[ Index ]

PHP Cross Reference of Limb3

title

Body

[close]

/wact/src/compiler/parser/ -> WactComponentParsingState.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  require_once('limb/wact/src/compiler/parser/WactHTMLParserListener.interface.php');
  11  require_once('limb/wact/src/compiler/parser/WactBaseParsingState.class.php');
  12  
  13  define ('WACT_PARSER_FORBID_PARSING', 10);
  14  
  15  /**

  16   * class WactComponentParsingState.

  17   *

  18   * @package wact

  19   * @version $Id: WactComponentParsingState.class.php 5945 2007-06-06 08:31:43Z pachanga $

  20   */
  21  class WactComponentParsingState extends WactBaseParsingState implements WactHTMLParserListener
  22  {
  23    protected $tag_dictionary;
  24  
  25    protected $node_builder;
  26  
  27    function __construct($parser, $tree_builder, $tag_dictionary)
  28    {
  29      parent :: __construct($parser, $tree_builder);
  30  
  31      $this->tag_dictionary = $tag_dictionary;
  32    }
  33  
  34    function startTag($tag, $attrs, $location)
  35    {
  36      $lower_attributes = $this->checkAttributes($attrs, $location);
  37  
  38      $runtime_tag_info = $this->tag_dictionary->findTagInfo($tag, $lower_attributes, FALSE, $this->tree_builder->getCursor());
  39  
  40      if (is_object($runtime_tag_info))
  41      {
  42        $runtime_tag_info->load();
  43  
  44        if($runtime_tag_info->isEndTagForbidden())
  45        {
  46          $tag_node = $this->tree_builder->buildTagNode($runtime_tag_info, $tag, $location, $attrs, $self_closed_tag = FALSE, $has_closing_tag = false);
  47          // for cases like <core:include> or <core:wrap> we have to pushNode() and popNode() here.

  48          $this->tree_builder->pushNode($tag_node);
  49          $this->tree_builder->popNode();
  50        }
  51        else
  52        {
  53          $this->tree_builder->pushExpectedWactTag($tag, $location);
  54          $tag_node = $this->tree_builder->buildTagNode($runtime_tag_info, $tag, $location, $attrs);
  55          $result = $this->tree_builder->pushNode($tag_node);
  56  
  57          if (($result == WACT_PARSER_FORBID_PARSING) || $runtime_tag_info->isParsingForbidden())
  58            $this->parser->changeToLiteralParsingState($tag);
  59        }
  60      }
  61      else
  62      {
  63        $this->tree_builder->pushExpectedPlainTag($tag, $location);
  64        $this->tree_builder->addContent('<' . $tag . $this->getAttributeString($attrs) . '>', $location);
  65      }
  66    }
  67  
  68    function endTag($tag, $location)
  69    {
  70      $tag_info = $this->tag_dictionary->getWactTagInfo($tag);
  71  
  72      if (is_object($tag_info))
  73      {
  74        if ($tag_info->isEndTagForbidden())
  75        {
  76          throw new WactException('Closing tag forbidden',
  77                                  array('tag' => $tag_info->Tag,
  78                                        'file' => $location->getFile(),
  79                                        'line' => $location->getLine()));
  80        }
  81      }
  82  
  83      if($tag_info && ($tag_info->getRunat() == LOCATION_SERVER))
  84        $result = $this->tree_builder->popExpectedWactTag($tag, $location);
  85      else
  86        $result = $this->tree_builder->popExpectedPlainTag($tag, $location);
  87  
  88      if ($result == WACT_EXPECTED_WACT_TAG)
  89        $this->tree_builder->popNode();
  90      else
  91        $this->tree_builder->addWactTextNode('</' . $tag .'>');
  92    }
  93  
  94    function emptyTag($tag, $attrs, $location)
  95    {
  96      $lower_attributes = $this->checkAttributes($attrs, $location);
  97  
  98      $runtime_tag_info = $this->tag_dictionary->findTagInfo($tag, $lower_attributes, TRUE, $this->tree_builder->getCursor());
  99      if (is_object($runtime_tag_info))
 100      {
 101        $runtime_tag_info->load();
 102  
 103        $tag_node = $this->tree_builder->buildTagNode($runtime_tag_info, $tag, $location, $attrs, $self_closed_tag = TRUE, $has_closing_tag = false);
 104        // for cases like <core:include> or <core:wrap> we have to pushNode() and popNode() here.

 105        $this->tree_builder->pushNode($tag_node);
 106        $this->tree_builder->popNode();
 107      }
 108      else
 109        $this->tree_builder->addContent('<' . $tag . $this->getAttributeString($attrs) . ' />', $location);
 110    }
 111  
 112    /**

 113    * Transforms attributes so keys are lowercase, and checks for

 114    * illegal DBEs

 115    */
 116    function checkAttributes($attrs, $location)
 117    {
 118      $lower_attributes = array_change_key_case($attrs, CASE_LOWER);
 119      if ( isset($lower_attributes['runat']) &&
 120              strpos($lower_attributes['runat'], '{$') !== FALSE)
 121      {
 122          throw new WactException('Illegal use of variable reference for attribute',
 123                                  array('expression' => $lower_attributes['runat'],
 124                                        'file' => $location->getFile(),
 125                                        'line' => $location->getLine()));
 126      }
 127      return $lower_attributes;
 128    }
 129  
 130    function characters($text, $location)
 131    {
 132      $this->tree_builder->addContent($text, $location);
 133    }
 134  
 135    function instruction($target, $instruction, $location)
 136    {
 137      $this->tree_builder->addProcessingInstruction($target, $instruction, $location);
 138    }
 139  }
 140  ?>


Generated: Mon Sep 8 04:35:41 2008 Cross-referenced by PHPXref 0.7