| [ 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 /** 11 * class lmbMacroParser. 12 * 13 * @package macro 14 * @version $Id$ 15 */ 16 class lmbMacroParser implements lmbMacroTokenizerListener 17 { 18 protected $active_parsing_state; 19 protected $component_parsing_state; 20 protected $literal_parsing_state; 21 22 /** 23 * @var lmbMacroConfig 24 */ 25 protected $config; 26 27 /** 28 * @var lmbMacrotree_builder 29 */ 30 protected $tree_builder; 31 32 /** 33 * @var lmbMacroTemplateLocator 34 */ 35 protected $template_locator; 36 37 function __construct($tree_builder, $config, $template_locator, $tag_dictionary) 38 { 39 $this->tree_builder = $tree_builder; 40 41 $this->config = $config; 42 $this->template_locator = $template_locator; 43 44 $this->component_parsing_state = $this->_createComponentParsingState($tag_dictionary); 45 $this->literal_parsing_state = $this->_createLiteralParsingState(); 46 47 $this->changeToComponentParsingState(); 48 } 49 50 // for testing purposes 51 protected function _createComponentParsingState($tag_dictionary) 52 { 53 return new lmbMacroTagParsingState($this, $this->tree_builder, $tag_dictionary); 54 } 55 56 // for testing purposes 57 protected function _createLiteralParsingState() 58 { 59 return new lmbMacroLiteralParsingState($this, $this->tree_builder); 60 } 61 62 /** 63 * Used to parse the source template. 64 * Initially invoked by the CompileTemplate function, 65 * the first component argument being a root node. 66 */ 67 function parse($file_name, $root_node) 68 { 69 $source_file_path = $this->template_locator->locateSourceTemplate($file_name); 70 71 if(empty($source_file_path)) 72 throw new lmbMacroException('Template source file not found', array('file_name' => $file_name)); 73 74 $tags_before_parse = $this->tree_builder->getExpectedTagCount(); 75 76 $this->tree_builder->setCursor($root_node); 77 78 $this->changeToComponentParsingState(); 79 80 $tokenizer = new lmbMacroTokenizer($this); 81 82 $this->setTemplateLocator($parser); 83 84 $content = $this->template_locator->readTemplateFile($source_file_path); 85 86 $tokenizer->parse($content, $source_file_path); 87 88 if($tags_before_parse != $this->tree_builder->getExpectedTagCount()) 89 { 90 $location = $this->tree_builder->getExpectedTagLocation(); 91 throw new lmbMacroException('Missing close tag', 92 array('tag' => $this->tree_builder->getExpectedTag(), 93 'file' => $location->getFile(), 94 'line' => $location->getLine())); 95 } 96 } 97 98 function getActiveParsingState() 99 { 100 return $this->active_parsing_state; 101 } 102 103 function changeToComponentParsingState() 104 { 105 $this->active_parsing_state = $this->component_parsing_state; 106 } 107 108 function changeToLiteralParsingState($tag) 109 { 110 $this->active_parsing_state = $this->literal_parsing_state; 111 $this->active_parsing_state->setLiteralTag($tag); 112 } 113 114 function setTemplateLocator($template_locator) 115 { 116 $this->literal_parsing_state->setTemplateLocator($template_locator); 117 $this->component_parsing_state->setTemplateLocator($template_locator); 118 } 119 120 function startElement($tag, $attrs) 121 { 122 $this->active_parsing_state->startElement($tag, $attrs); 123 } 124 125 function endElement($tag) 126 { 127 $this->active_parsing_state->endElement($tag); 128 } 129 130 function emptyElement($tag, $attrs) 131 { 132 $this->active_parsing_state->emptyElement($tag, $attrs); 133 } 134 135 function characters($text) 136 { 137 $this->active_parsing_state->characters($text); 138 } 139 140 function unexpectedEOF($text) 141 { 142 $this->active_parsing_state->unexpectedEOF($text); 143 } 144 145 function invalidEntitySyntax($text) 146 { 147 $this->active_parsing_state->invalidEntitySyntax($text); 148 } 149 150 function invalidAttributeSyntax() 151 { 152 $this->active_parsing_state->invalidAttributeSyntax(); 153 } 154 } 155 156 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Tue Oct 7 05:02:03 2008 | Cross-referenced by PHPXref 0.7 |