| [ Index ] |
PHP Cross Reference of Limb3 |
[Summary view] [Print] [Text view]
1 <?php 2 /* 3 * Limb PHP Framework 4 * 5 * @link http://limb-project.com 6 * @copyright Copyright © 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/lmbMacroTokenizerListener.interface.php'); 11 lmb_require('limb/macro/src/lmbMacroBaseParsingState.class.php'); 12 13 /** 14 * class lmbMacroTagParsingState. 15 * 16 * @package macro 17 * @version $Id$ 18 */ 19 class lmbMacroTagParsingState extends lmbMacroBaseParsingState implements lmbMacroTokenizerListener 20 { 21 protected $tag_dictionary; 22 23 function __construct($parser, $tree_builder, $tag_dictionary) 24 { 25 parent :: __construct($parser, $tree_builder); 26 $this->tag_dictionary = $tag_dictionary; 27 } 28 29 function startElement($tag, $attrs) 30 { 31 $location = $this->locator->getCurrentLocation(); 32 33 $lower_attributes = $this->normalizeAttributes($attrs, $location); 34 35 $tag_info = $this->tag_dictionary->findTagInfo($tag); 36 37 if($tag_info->isEndTagForbidden()) 38 { 39 $tag_node = $this->buildTagNode($tag_info, $tag, $attrs, $self_closed_tag = true); 40 $tag_node->setHasClosingTag(false); 41 $this->tree_builder->pushNode($tag_node); // for cases like <%include%> we do pushNode() and popNode() here. 42 $this->tree_builder->popNode(); 43 } 44 else 45 { 46 $this->tree_builder->pushExpectedTag($tag, $location); 47 $tag_node = $this->buildTagNode($tag_info, $tag, $attrs, $self_closed_tag = false); 48 $result = $this->tree_builder->pushNode($tag_node); 49 } 50 } 51 52 function endElement($tag) 53 { 54 $tag_info = $this->tag_dictionary->getTagInfo($tag); 55 $location = $this->locator->getCurrentLocation(); 56 57 if($tag_info->isEndTagForbidden()) 58 { 59 throw new lmbMacroException('Closing tag forbidden', 60 array('tag' => $tag_info->getTag(), 61 'file' => $location->getFile(), 62 'line' => $location->getLine())); 63 } 64 65 $this->tree_builder->popExpectedTag($tag, $location); 66 $this->tree_builder->popNode(); 67 } 68 69 function emptyElement($tag, $attrs) 70 { 71 $location = $this->locator->getCurrentLocation(); 72 $lower_attributes = $this->normalizeAttributes($attrs, $location); 73 74 $tag_info = $this->tag_dictionary->findTagInfo($tag); 75 $tag_info->load(); 76 77 $tag_node = $this->buildTagNode($tag_info, $tag, $attrs, $self_closed_tag = true); 78 $tag_node->setHasClosingTag(false); 79 $this->tree_builder->pushNode($tag_node); // for cases like <%include%> we do pushNode() and popNode() here. 80 $this->tree_builder->popNode(); 81 } 82 83 /** 84 * Builds a component, adding attributes 85 * @param lmbMacroTagInfo 86 * @param string XML tag name of component 87 * @param array attributes for tag 88 * @param boolean whether the tag has contents 89 * @return lmbMacroNode 90 */ 91 function buildTagNode($tag_info, $tag, $attrs, $isEmpty) 92 { 93 $tag_node = $this->_createTagNode($tag_info, $tag); 94 $tag_node->emptyClosedTag = $isEmpty; 95 $this->_addAttributesToTagNode($tag_node, $attrs); 96 return $tag_node; 97 } 98 99 protected function _addAttributesToTagNode($tag_node, $attrs) 100 { 101 foreach($attrs as $name => $value) 102 { 103 if($value === null) 104 { 105 $location = $this->locator->getCurrentLocation(); 106 throw new lmbMacroException('Attribute should have a value', 107 array('file' => $location->getFile(), 108 'line' => $location->getLine(), 109 'tag' => $tag_node->getTag(), 110 'attribute' => $name)); 111 } 112 $tag_node->set($name, $value); 113 } 114 } 115 116 protected function _createTagNode($tag_info, $tag) 117 { 118 $class = $tag_info->getClass(); 119 $tag_node = new $class($this->locator->getCurrentLocation(), $tag, $tag_info); 120 return $tag_node; 121 } 122 123 function normalizeAttributes($attrs) 124 { 125 return array_change_key_case($attrs, CASE_LOWER); 126 } 127 128 function characters($text) 129 { 130 $this->tree_builder->addTextNode($text); 131 } 132 133 function unexpectedEOF($text) 134 { 135 $this->tree_builder->addTextNode($text); 136 } 137 138 function invalidEntitySyntax($text) 139 { 140 $this->tree_builder->addTextNode($text); 141 } 142 } 143 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Oct 12 04:41:30 2008 | Cross-referenced by PHPXref 0.7 |