1 | <?php |
||
9 | class Compiler |
||
10 | { |
||
11 | /** |
||
12 | * |
||
13 | * @var array |
||
14 | */ |
||
15 | protected $lexerOptions; |
||
16 | |||
17 | /** |
||
18 | * |
||
19 | * @var \DOMDocument |
||
20 | */ |
||
21 | protected $document; |
||
22 | |||
23 | /** |
||
24 | * |
||
25 | * @var Twital |
||
26 | */ |
||
27 | protected $twital; |
||
28 | |||
29 | 486 | public function __construct(Twital $twital, array $lexerOptions = array()) |
|
44 | |||
45 | /** |
||
46 | * |
||
47 | * @return \DOMDocument |
||
48 | */ |
||
49 | public function getDocument() |
||
53 | |||
54 | /** |
||
55 | * |
||
56 | * @param string $content |
||
57 | * @return \DOMCDATASection |
||
58 | */ |
||
59 | 7 | public function createPrintNode($content) |
|
65 | |||
66 | /** |
||
67 | * |
||
68 | * @param string $content |
||
69 | * @return \DOMCDATASection |
||
70 | */ |
||
71 | 111 | public function createControlNode($content) |
|
77 | |||
78 | /** |
||
79 | * @param \DOMDocument $doc |
||
80 | * @return void |
||
81 | */ |
||
82 | 486 | public function compile(\DOMDocument $doc) |
|
83 | { |
||
84 | 486 | $this->document = $doc; |
|
85 | 486 | $this->compileChilds($doc); |
|
86 | 484 | } |
|
87 | |||
88 | 483 | public function compileElement(\DOMElement $node) |
|
89 | { |
||
90 | 483 | $nodes = $this->twital->getNodes(); |
|
91 | 483 | if (isset($nodes[$node->namespaceURI][$node->localName])) { |
|
92 | 81 | $nodes[$node->namespaceURI][$node->localName]->visit($node, $this); |
|
93 | 483 | } elseif (isset($nodes[$node->namespaceURI]['__base__'])) { |
|
94 | $nodes[$node->namespaceURI]['__base__']->visit($node, $this); |
||
95 | } else { |
||
96 | 426 | if ($node->namespaceURI === Twital::NS) { |
|
97 | throw new Exception("Can't handle the {$node->namespaceURI}#{$node->localName} node at line " . $node->getLineNo()); |
||
98 | } |
||
99 | 426 | if ($this->compileAttributes($node)) { |
|
100 | 421 | $this->compileChilds($node); |
|
101 | 421 | } |
|
102 | } |
||
103 | 481 | } |
|
104 | |||
105 | 450 | public function compileAttributes(\DOMNode $node) |
|
133 | |||
134 | 486 | public function compileChilds(\DOMNode $node) |
|
135 | { |
||
142 | |||
143 | 118 | private function getLexerOption($name) |
|
147 | } |
||
148 |