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 | 461 | 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 | 1 | public function createPrintNode($content) |
|
65 | |||
66 | /** |
||
67 | * |
||
68 | * @param string $content |
||
69 | * @return \DOMCDATASection |
||
70 | */ |
||
71 | 101 | public function createControlNode($content) |
|
77 | |||
78 | 102 | private function getLexerOption($name) |
|
82 | |||
83 | /** |
||
84 | * @param \DOMDocument $doc |
||
85 | * @return void |
||
86 | */ |
||
87 | 461 | public function compile(\DOMDocument $doc) |
|
92 | |||
93 | 461 | public function compileElement(\DOMElement $node) |
|
109 | |||
110 | 428 | public function compileAttributes(\DOMNode $node) |
|
111 | { |
||
112 | 428 | $attributes = $this->twital->getAttributes(); |
|
113 | 428 | $continueNode = true; |
|
114 | 428 | foreach (iterator_to_array($node->attributes) as $attr) { |
|
115 | 337 | if (!$attr->ownerElement) { |
|
116 | 6 | continue; |
|
117 | 337 | } elseif (isset($attributes[$attr->namespaceURI][$attr->localName])) { |
|
118 | 50 | $attPlugin = $attributes[$attr->namespaceURI][$attr->localName]; |
|
119 | 337 | } elseif (isset($attributes[$attr->namespaceURI]['__base__'])) { |
|
120 | 3 | $attPlugin = $attributes[$attr->namespaceURI]['__base__']; |
|
121 | 294 | } elseif ($attr->namespaceURI === Twital::NS) { |
|
122 | throw new Exception("Can't handle the {$attr->namespaceURI}#{$attr->localName} attribute on {$node->namespaceURI}#{$node->localName} node at line " . $attr->getLineNo()); |
||
123 | } else { |
||
124 | 291 | continue; |
|
125 | } |
||
126 | |||
127 | 50 | $return = $attPlugin->visit($attr, $this); |
|
128 | 48 | if ($return !== null) { |
|
129 | 5 | $continueNode = $continueNode && !($return & Attribute::STOP_NODE); |
|
130 | 5 | if ($return & Attribute::STOP_ATTRIBUTE) { |
|
131 | 5 | break; |
|
132 | } |
||
133 | } |
||
134 | 426 | } |
|
135 | |||
136 | 426 | return $continueNode; |
|
137 | } |
||
138 | |||
139 | 461 | public function compileChilds(\DOMNode $node) |
|
147 | } |
||
148 |