[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/macro/src/ -> lmbMacroTag.class.php (source)

   1  <?php
   2  /*
   3   * Limb PHP Framework
   4   *
   5   * @link http://limb-project.com 
   6   * @copyright  Copyright &copy; 2004-2007 BIT(http://bit-creative.com)
   7   * @license    LGPL http://www.gnu.org/copyleft/lesser.html 
   8   */
   9  
  10  lmb_require('limb/macro/src/lmbMacroNode.class.php');
  11  
  12  /**

  13   * class lmbMacroTag.

  14   *

  15   * @package macro

  16   * @version $Id$

  17   */
  18  class lmbMacroTag extends lmbMacroNode
  19  {
  20    protected $tag;
  21    protected $has_closing_tag = true;
  22    protected $empty_closed_tag = false;  
  23    protected $tag_info;
  24    protected $attributes = array();
  25    
  26    function __construct($location, $tag, $tag_info)
  27    {
  28      $this->tag = $tag;
  29      $this->tag_info = $tag_info;
  30      
  31      parent :: __construct($location);
  32    }
  33  
  34    function getTag()
  35    {
  36      return $this->tag;
  37    }
  38    
  39    function getHasClosingTag()
  40    {
  41      return $this->has_closing_tag;
  42    }
  43    
  44    function setHasClosingTag($flag)
  45    {
  46      return $this->has_closing_tag = $flag;
  47    }  
  48    
  49    function getId()
  50    {
  51      if($this->id)
  52        return $this->id;
  53          
  54      if($id = $this->get('id'))
  55        $this->id = $id;
  56      else
  57        $this->id = self :: generateNewId();
  58  
  59      return $this->id;
  60    }  
  61    
  62    function get($name)
  63    {
  64      if(array_key_exists(strtolower($name), $this->attributes))
  65        return $this->attributes[strtolower($name)];
  66    }  
  67    
  68    function set($name, $value)
  69    {
  70      $this->attributes[strtolower($name)] = $value;
  71    }
  72  
  73    function has($name)
  74    {
  75      return array_key_exists(strtolower($name), $this->attributes);
  76    }
  77  
  78    /**

  79    * Return the value of a boolean attribute as a boolean.

  80    * ATTRIBUTE=ANYTHING  (true)

  81    * ATTRIBUTE=(false|N|NA|NO|NONE|0) (false)

  82    * ATTRIBUTE (true)

  83    * (attribute unspecified) (default)

  84    */
  85    function getBool($attrib, $default = false)
  86    {
  87      if(!isset($this->attributes[strtolower($attrib)]))
  88        return $default;
  89  
  90      return self :: getBooleanValue($this->attributes[strtolower($attrib)]);
  91    }
  92  
  93    static function getBooleanValue($value)
  94    {
  95      switch(strtoupper($value))
  96      {
  97        case 'FALSE':
  98        case 'N':
  99        case 'NO':
 100        case 'NONE':
 101        case 'NA':
 102        case '0':
 103          return false;
 104        default:
 105          return true;
 106      }
 107    }
 108  
 109    function remove($attrib)
 110    {
 111      unset($this->attributes[strtolower($attrib)]);
 112    }  
 113      
 114    function raise($error, $vars = array())
 115    {
 116      $vars['tag'] = $this->tag;
 117      parent :: raise($error, $vars);
 118    }  
 119  
 120    function raiseRequiredAttribute($attribute_name)
 121    {
 122      $this->raise('Missing required attribute', array('attribute' => $attribute_name));
 123    }
 124    
 125    function preParse()
 126    {
 127      foreach($this->tag_info->getRequiredAttributes() as $attr_name)
 128      {
 129        if(!$this->has($attr_name))
 130          $this->raiseRequiredAttribute($attr_name);
 131      }
 132  
 133      if($this->tag_info->isRestrictSelfNesting() && $parent = $this->findParentByClass(get_class($this)))
 134        $this->raise('Tag cannot be nested within the same tag',
 135                                  array('same_tag_file' => $parent->getTemplateFile(),
 136                                        'same_tag_line' => $parent->getTemplateLine()));
 137  
 138      if(($parent_class = $this->tag_info->getParentClass()) &&
 139         !$parent = $this->findParentByClass($parent_class))
 140      {
 141        $this->raise('Tag must be enclosed by a proper parent tag',
 142                                  array('required_parent_tag_class' => $parent_class));
 143  
 144      }
 145    }  
 146  }
 147  ?>


Generated: Thu Aug 21 04:38:04 2008 Cross-referenced by PHPXref 0.7