File indexing completed on 2024-05-12 06:02:46

0001 <?php
0002 /**
0003  * Zend Framework
0004  *
0005  * LICENSE
0006  *
0007  * This source file is subject to the new BSD license that is bundled
0008  * with this package in the file LICENSE.txt.
0009  * It is also available through the world-wide-web at this URL:
0010  * http://framework.zend.com/license/new-bsd
0011  * If you did not receive a copy of the license and are unable to
0012  * obtain it through the world-wide-web, please send an email
0013  * to license@zend.com so we can send you a copy immediately.
0014  *
0015  * @category   Zend
0016  * @package    Zend_Markup
0017  * @subpackage Parser
0018  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0019  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0020  * @version    $Id$
0021  */
0022 
0023 /**
0024  * @see Zend_Markup_TokenList
0025  */
0026 // require_once 'Zend/Markup/TokenList.php';
0027 
0028 /**
0029  * @category   Zend
0030  * @package    Zend_Markup
0031  * @copyright  Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
0032  * @license    http://framework.zend.com/license/new-bsd     New BSD License
0033  */
0034 class Zend_Markup_Token
0035 {
0036     const TYPE_NONE    = 'none';
0037     const TYPE_TAG     = 'tag';
0038 
0039     /**
0040      * Children of this token
0041      *
0042      * @var Zend_Markup_TokenList
0043      */
0044     protected $_children;
0045 
0046     /**
0047      * The complete tag
0048      *
0049      * @var string
0050      */
0051     protected $_tag;
0052 
0053     /**
0054      * The tag's type
0055      *
0056      * @var string
0057      */
0058     protected $_type;
0059 
0060     /**
0061      * Tag name
0062      *
0063      * @var string
0064      */
0065     protected $_name = '';
0066 
0067     /**
0068      * Tag attributes
0069      *
0070      * @var array
0071      */
0072     protected $_attributes = array();
0073 
0074     /**
0075      * The used tag stopper (empty when none is found)
0076      *
0077      * @var string
0078      */
0079     protected $_stopper = '';
0080 
0081     /**
0082      * The parent token
0083      *
0084      * @var Zend_Markup_Token
0085      */
0086     protected $_parent;
0087 
0088 
0089     /**
0090      * Construct the token
0091      *
0092      * @param  string $tag
0093      * @param  string $type
0094      * @param  string $name
0095      * @param  array $attributes
0096      * @param  Zend_Markup_Token $parent
0097      * @return void
0098      */
0099     public function __construct(
0100         $tag,
0101         $type,
0102         $name = '',
0103         array $attributes = array(),
0104         Zend_Markup_Token $parent = null
0105     ) {
0106         $this->_tag        = $tag;
0107         $this->_type       = $type;
0108         $this->_name       = $name;
0109         $this->_attributes = $attributes;
0110         $this->_parent     = $parent;
0111     }
0112 
0113     // accessors
0114 
0115     /**
0116      * Set the stopper
0117      *
0118      * @param string $stopper
0119      * @return Zend_Markup_Token
0120      */
0121     public function setStopper($stopper)
0122     {
0123         $this->_stopper = $stopper;
0124 
0125         return $this;
0126     }
0127 
0128     /**
0129      * Get the stopper
0130      *
0131      * @return string
0132      */
0133     public function getStopper()
0134     {
0135         return $this->_stopper;
0136     }
0137 
0138     /**
0139      * Get the token's name
0140      *
0141      * @return string
0142      */
0143     public function getName()
0144     {
0145         return $this->_name;
0146     }
0147 
0148     /**
0149      * Get the token's type
0150      *
0151      * @return string
0152      */
0153     public function getType()
0154     {
0155         return $this->_type;
0156     }
0157 
0158     /**
0159      * Get the complete tag
0160      *
0161      * @return string
0162      */
0163     public function getTag()
0164     {
0165         return $this->_tag;
0166     }
0167 
0168     /**
0169      * Get an attribute
0170      *
0171      * @param string $name
0172      *
0173      * @return string
0174      */
0175     public function getAttribute($name)
0176     {
0177         return isset($this->_attributes[$name]) ? $this->_attributes[$name] : null;
0178     }
0179 
0180     /**
0181      * Check if the token has an attribute
0182      *
0183      * @param string $name
0184      *
0185      * @return bool
0186      */
0187     public function hasAttribute($name)
0188     {
0189         return isset($this->_attributes[$name]);
0190     }
0191 
0192     /**
0193      * Get all the attributes
0194      *
0195      * @return array
0196      */
0197     public function getAttributes()
0198     {
0199         return $this->_attributes;
0200     }
0201 
0202     /**
0203      * Add an attribute
0204      *
0205      * @return Zend_Markup_Token
0206      */
0207     public function addAttribute($name, $value)
0208     {
0209         $this->_attributes[$name] = $value;
0210 
0211         return $this;
0212     }
0213 
0214     /**
0215      * Check if an attribute is empty
0216      *
0217      * @param string $name
0218      *
0219      * @return bool
0220      */
0221     public function attributeIsEmpty($name)
0222     {
0223         return empty($this->_attributes[$name]);
0224     }
0225 
0226     // functions for child/parent tokens
0227 
0228     /**
0229      * Add a child token
0230      *
0231      * @return void
0232      */
0233     public function addChild(Zend_Markup_Token $child)
0234     {
0235         $this->getChildren()->addChild($child);
0236     }
0237 
0238     /**
0239      * Set the children token list
0240      *
0241      * @param  Zend_Markup_TokenList $children
0242      * @return Zend_Markup_Token
0243      */
0244     public function setChildren(Zend_Markup_TokenList $children)
0245     {
0246         $this->_children = $children;
0247         return $this;
0248     }
0249 
0250     /**
0251      * Get the children for this token
0252      *
0253      * @return Zend_Markup_TokenList
0254      */
0255     public function getChildren()
0256     {
0257         if (null === $this->_children) {
0258             $this->setChildren(new Zend_Markup_TokenList());
0259         }
0260         return $this->_children;
0261     }
0262 
0263     /**
0264      * Does this token have any children
0265      *
0266      * @return bool
0267      */
0268     public function hasChildren()
0269     {
0270         return !empty($this->_children);
0271     }
0272 
0273     /**
0274      * Get the parent token (if any)
0275      *
0276      * @return Zend_Markup_Token
0277      */
0278     public function getParent()
0279     {
0280         return $this->_parent;
0281     }
0282 
0283     /**
0284      * Set a parent token
0285      *
0286      * @param  Zend_Markup_Token $parent
0287      * @return Zend_Markup_Token
0288      */
0289     public function setParent(Zend_Markup_Token $parent)
0290     {
0291         $this->_parent = $parent;
0292         return $this;
0293     }
0294 
0295     /**
0296      * Magic clone function
0297      *
0298      * @return void
0299      */
0300     public function __clone()
0301     {
0302         $this->_parent   = null;
0303         $this->_children = null;
0304         $this->_tag      = '';
0305     }
0306 }