| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306 |
- <?php
- /**
- * Zend Framework
- *
- * LICENSE
- *
- * This source file is subject to the new BSD license that is bundled
- * with this package in the file LICENSE.txt.
- * It is also available through the world-wide-web at this URL:
- * http://framework.zend.com/license/new-bsd
- * If you did not receive a copy of the license and are unable to
- * obtain it through the world-wide-web, please send an email
- * to license@zend.com so we can send you a copy immediately.
- *
- * @category Zend
- * @package Zend_Markup
- * @subpackage Parser
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- * @version $Id$
- */
- /**
- * @see Zend_Markup_TokenList
- */
- require_once 'Zend/Markup/TokenList.php';
- /**
- * @category Zend
- * @package Zend_Markup
- * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
- * @license http://framework.zend.com/license/new-bsd New BSD License
- */
- class Zend_Markup_Token
- {
- const TYPE_NONE = 'none';
- const TYPE_TAG = 'tag';
- /**
- * Children of this token
- *
- * @var Zend_Markup_TokenList
- */
- protected $_children;
- /**
- * The complete tag
- *
- * @var string
- */
- protected $_tag;
- /**
- * The tag's type
- *
- * @var string
- */
- protected $_type;
- /**
- * Tag name
- *
- * @var string
- */
- protected $_name = '';
- /**
- * Tag attributes
- *
- * @var array
- */
- protected $_attributes = array();
- /**
- * The used tag stopper (empty when none is found)
- *
- * @var string
- */
- protected $_stopper = '';
- /**
- * The parent token
- *
- * @var Zend_Markup_Token
- */
- protected $_parent;
- /**
- * Construct the token
- *
- * @param string $tag
- * @param string $type
- * @param string $name
- * @param array $attributes
- * @param Zend_Markup_Token $parent
- * @return void
- */
- public function __construct(
- $tag,
- $type,
- $name = '',
- array $attributes = array(),
- Zend_Markup_Token $parent = null
- ) {
- $this->_tag = $tag;
- $this->_type = $type;
- $this->_name = $name;
- $this->_attributes = $attributes;
- $this->_parent = $parent;
- }
- // accessors
- /**
- * Set the stopper
- *
- * @param string $stopper
- * @return Zend_Markup_Token
- */
- public function setStopper($stopper)
- {
- $this->_stopper = $stopper;
- return $this;
- }
- /**
- * Get the stopper
- *
- * @return string
- */
- public function getStopper()
- {
- return $this->_stopper;
- }
- /**
- * Get the token's name
- *
- * @return string
- */
- public function getName()
- {
- return $this->_name;
- }
- /**
- * Get the token's type
- *
- * @return string
- */
- public function getType()
- {
- return $this->_type;
- }
- /**
- * Get the complete tag
- *
- * @return string
- */
- public function getTag()
- {
- return $this->_tag;
- }
- /**
- * Get an attribute
- *
- * @param string $name
- *
- * @return string
- */
- public function getAttribute($name)
- {
- return isset($this->_attributes[$name]) ? $this->_attributes[$name] : null;
- }
- /**
- * Check if the token has an attribute
- *
- * @param string $name
- *
- * @return bool
- */
- public function hasAttribute($name)
- {
- return isset($this->_attributes[$name]);
- }
- /**
- * Get all the attributes
- *
- * @return array
- */
- public function getAttributes()
- {
- return $this->_attributes;
- }
- /**
- * Add an attribute
- *
- * @return Zend_Markup_Token
- */
- public function addAttribute($name, $value)
- {
- $this->_attributes[$name] = $value;
- return $this;
- }
- /**
- * Check if an attribute is empty
- *
- * @param string $name
- *
- * @return bool
- */
- public function attributeIsEmpty($name)
- {
- return empty($this->_attributes[$name]);
- }
- // functions for child/parent tokens
- /**
- * Add a child token
- *
- * @return void
- */
- public function addChild(Zend_Markup_Token $child)
- {
- $this->getChildren()->addChild($child);
- }
- /**
- * Set the children token list
- *
- * @param Zend_Markup_TokenList $children
- * @return Zend_Markup_Token
- */
- public function setChildren(Zend_Markup_TokenList $children)
- {
- $this->_children = $children;
- return $this;
- }
- /**
- * Get the children for this token
- *
- * @return Zend_Markup_TokenList
- */
- public function getChildren()
- {
- if (null === $this->_children) {
- $this->setChildren(new Zend_Markup_TokenList());
- }
- return $this->_children;
- }
- /**
- * Does this token have any children
- *
- * @return bool
- */
- public function hasChildren()
- {
- return !empty($this->_children);
- }
- /**
- * Get the parent token (if any)
- *
- * @return Zend_Markup_Token
- */
- public function getParent()
- {
- return $this->_parent;
- }
- /**
- * Set a parent token
- *
- * @param Zend_Markup_Token $parent
- * @return Zend_Markup_Token
- */
- public function setParent(Zend_Markup_Token $parent)
- {
- $this->_parent = $parent;
- return $this;
- }
- /**
- * Magic clone function
- *
- * @return void
- */
- public function __clone()
- {
- $this->_parent = null;
- $this->_children = null;
- $this->_tag = '';
- }
- }
|