web/Zend/Markup/TokenList.php
changeset 0 4eba9c11703f
equal deleted inserted replaced
-1:000000000000 0:4eba9c11703f
       
     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  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    18  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    19  * @version    $Id: TokenList.php 20277 2010-01-14 14:17:12Z kokx $
       
    20  */
       
    21 
       
    22 /**
       
    23  * @see Zend_Markup_Token
       
    24  */
       
    25 require_once 'Zend/Markup/Token.php';
       
    26 
       
    27 /**
       
    28  * @category   Zend
       
    29  * @package    Zend_Markup
       
    30  * @copyright  Copyright (c) 2005-2010 Zend Technologies USA Inc. (http://www.zend.com)
       
    31  * @license    http://framework.zend.com/license/new-bsd     New BSD License
       
    32  */
       
    33 class Zend_Markup_TokenList implements RecursiveIterator
       
    34 {
       
    35 
       
    36     /**
       
    37      * Array of tokens
       
    38      *
       
    39      * @var array
       
    40      */
       
    41     protected $_tokens = array();
       
    42 
       
    43     /**
       
    44      * Get the current token
       
    45      *
       
    46      * @return Zend_Markup_Token
       
    47      */
       
    48     public function current()
       
    49     {
       
    50         return current($this->_tokens);
       
    51     }
       
    52 
       
    53     /**
       
    54      * Get the children of the current token
       
    55      *
       
    56      * @return Zend_Markup_TokenList
       
    57      */
       
    58     public function getChildren()
       
    59     {
       
    60         return current($this->_tokens)->getChildren();
       
    61     }
       
    62 
       
    63     /**
       
    64      * Add a new child token
       
    65      *
       
    66      * @param Zend_Markup_Token $child
       
    67      *
       
    68      * @return void
       
    69      */
       
    70     public function addChild(Zend_Markup_Token $child)
       
    71     {
       
    72         $this->_tokens[] = $child;
       
    73     }
       
    74 
       
    75     /**
       
    76      * Check if the current token has children
       
    77      *
       
    78      * @return bool
       
    79      */
       
    80     public function hasChildren()
       
    81     {
       
    82         return current($this->_tokens)->hasChildren();
       
    83     }
       
    84 
       
    85     /**
       
    86      * Get the key of the current token
       
    87      *
       
    88      * @return int
       
    89      */
       
    90     public function key()
       
    91     {
       
    92         return key($this->_tokens);
       
    93     }
       
    94 
       
    95     /**
       
    96      * Go to the next token
       
    97      *
       
    98      * @return Zend_Markup_Token
       
    99      */
       
   100     public function next()
       
   101     {
       
   102         return next($this->_tokens);
       
   103     }
       
   104 
       
   105     /**
       
   106      * Rewind the iterator
       
   107      *
       
   108      * @return void
       
   109      */
       
   110     public function rewind()
       
   111     {
       
   112         reset($this->_tokens);
       
   113     }
       
   114 
       
   115     /**
       
   116      * Check if the element is valid
       
   117      *
       
   118      * @return void
       
   119      */
       
   120     public function valid()
       
   121     {
       
   122         return $this->current() !== false;
       
   123     }
       
   124 }