PageRenderTime 40ms CodeModel.GetById 12ms RepoModel.GetById 0ms app.codeStats 0ms

/src/application/libraries/Zend/Markup/Token.php

https://bitbucket.org/masnug/grc276-blog-laravel
PHP | 306 lines | 104 code | 32 blank | 170 comment | 1 complexity | 47fa4b122b723a93a55774a406a8352e MD5 | raw file
  1. <?php
  2. /**
  3. * Zend Framework
  4. *
  5. * LICENSE
  6. *
  7. * This source file is subject to the new BSD license that is bundled
  8. * with this package in the file LICENSE.txt.
  9. * It is also available through the world-wide-web at this URL:
  10. * http://framework.zend.com/license/new-bsd
  11. * If you did not receive a copy of the license and are unable to
  12. * obtain it through the world-wide-web, please send an email
  13. * to license@zend.com so we can send you a copy immediately.
  14. *
  15. * @category Zend
  16. * @package Zend_Markup
  17. * @subpackage Parser
  18. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  19. * @license http://framework.zend.com/license/new-bsd New BSD License
  20. * @version $Id: Token.php 23775 2011-03-01 17:25:24Z ralph $
  21. */
  22. /**
  23. * @see Zend_Markup_TokenList
  24. */
  25. require_once 'Zend/Markup/TokenList.php';
  26. /**
  27. * @category Zend
  28. * @package Zend_Markup
  29. * @copyright Copyright (c) 2005-2011 Zend Technologies USA Inc. (http://www.zend.com)
  30. * @license http://framework.zend.com/license/new-bsd New BSD License
  31. */
  32. class Zend_Markup_Token
  33. {
  34. const TYPE_NONE = 'none';
  35. const TYPE_TAG = 'tag';
  36. /**
  37. * Children of this token
  38. *
  39. * @var Zend_Markup_TokenList
  40. */
  41. protected $_children;
  42. /**
  43. * The complete tag
  44. *
  45. * @var string
  46. */
  47. protected $_tag;
  48. /**
  49. * The tag's type
  50. *
  51. * @var string
  52. */
  53. protected $_type;
  54. /**
  55. * Tag name
  56. *
  57. * @var string
  58. */
  59. protected $_name = '';
  60. /**
  61. * Tag attributes
  62. *
  63. * @var array
  64. */
  65. protected $_attributes = array();
  66. /**
  67. * The used tag stopper (empty when none is found)
  68. *
  69. * @var string
  70. */
  71. protected $_stopper = '';
  72. /**
  73. * The parent token
  74. *
  75. * @var Zend_Markup_Token
  76. */
  77. protected $_parent;
  78. /**
  79. * Construct the token
  80. *
  81. * @param string $tag
  82. * @param string $type
  83. * @param string $name
  84. * @param array $attributes
  85. * @param Zend_Markup_Token $parent
  86. * @return void
  87. */
  88. public function __construct(
  89. $tag,
  90. $type,
  91. $name = '',
  92. array $attributes = array(),
  93. Zend_Markup_Token $parent = null
  94. ) {
  95. $this->_tag = $tag;
  96. $this->_type = $type;
  97. $this->_name = $name;
  98. $this->_attributes = $attributes;
  99. $this->_parent = $parent;
  100. }
  101. // accessors
  102. /**
  103. * Set the stopper
  104. *
  105. * @param string $stopper
  106. * @return Zend_Markup_Token
  107. */
  108. public function setStopper($stopper)
  109. {
  110. $this->_stopper = $stopper;
  111. return $this;
  112. }
  113. /**
  114. * Get the stopper
  115. *
  116. * @return string
  117. */
  118. public function getStopper()
  119. {
  120. return $this->_stopper;
  121. }
  122. /**
  123. * Get the token's name
  124. *
  125. * @return string
  126. */
  127. public function getName()
  128. {
  129. return $this->_name;
  130. }
  131. /**
  132. * Get the token's type
  133. *
  134. * @return string
  135. */
  136. public function getType()
  137. {
  138. return $this->_type;
  139. }
  140. /**
  141. * Get the complete tag
  142. *
  143. * @return string
  144. */
  145. public function getTag()
  146. {
  147. return $this->_tag;
  148. }
  149. /**
  150. * Get an attribute
  151. *
  152. * @param string $name
  153. *
  154. * @return string
  155. */
  156. public function getAttribute($name)
  157. {
  158. return isset($this->_attributes[$name]) ? $this->_attributes[$name] : null;
  159. }
  160. /**
  161. * Check if the token has an attribute
  162. *
  163. * @param string $name
  164. *
  165. * @return bool
  166. */
  167. public function hasAttribute($name)
  168. {
  169. return isset($this->_attributes[$name]);
  170. }
  171. /**
  172. * Get all the attributes
  173. *
  174. * @return array
  175. */
  176. public function getAttributes()
  177. {
  178. return $this->_attributes;
  179. }
  180. /**
  181. * Add an attribute
  182. *
  183. * @return Zend_Markup_Token
  184. */
  185. public function addAttribute($name, $value)
  186. {
  187. $this->_attributes[$name] = $value;
  188. return $this;
  189. }
  190. /**
  191. * Check if an attribute is empty
  192. *
  193. * @param string $name
  194. *
  195. * @return bool
  196. */
  197. public function attributeIsEmpty($name)
  198. {
  199. return empty($this->_attributes[$name]);
  200. }
  201. // functions for child/parent tokens
  202. /**
  203. * Add a child token
  204. *
  205. * @return void
  206. */
  207. public function addChild(Zend_Markup_Token $child)
  208. {
  209. $this->getChildren()->addChild($child);
  210. }
  211. /**
  212. * Set the children token list
  213. *
  214. * @param Zend_Markup_TokenList $children
  215. * @return Zend_Markup_Token
  216. */
  217. public function setChildren(Zend_Markup_TokenList $children)
  218. {
  219. $this->_children = $children;
  220. return $this;
  221. }
  222. /**
  223. * Get the children for this token
  224. *
  225. * @return Zend_Markup_TokenList
  226. */
  227. public function getChildren()
  228. {
  229. if (null === $this->_children) {
  230. $this->setChildren(new Zend_Markup_TokenList());
  231. }
  232. return $this->_children;
  233. }
  234. /**
  235. * Does this token have any children
  236. *
  237. * @return bool
  238. */
  239. public function hasChildren()
  240. {
  241. return !empty($this->_children);
  242. }
  243. /**
  244. * Get the parent token (if any)
  245. *
  246. * @return Zend_Markup_Token
  247. */
  248. public function getParent()
  249. {
  250. return $this->_parent;
  251. }
  252. /**
  253. * Set a parent token
  254. *
  255. * @param Zend_Markup_Token $parent
  256. * @return Zend_Markup_Token
  257. */
  258. public function setParent(Zend_Markup_Token $parent)
  259. {
  260. $this->_parent = $parent;
  261. return $this;
  262. }
  263. /**
  264. * Magic clone function
  265. *
  266. * @return void
  267. */
  268. public function __clone()
  269. {
  270. $this->_parent = null;
  271. $this->_children = null;
  272. $this->_tag = '';
  273. }
  274. }