1 | <?php |
||
24 | class Compiler |
||
25 | { |
||
26 | /** |
||
27 | * The parser instance. |
||
28 | * |
||
29 | * @var Parser |
||
30 | */ |
||
31 | private $parser; |
||
32 | |||
33 | /** |
||
34 | * The string to match as a starting multi-line directive. |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | private $startMultiLine; |
||
39 | |||
40 | /** |
||
41 | * The string to match as an ending multi-line directive. |
||
42 | * |
||
43 | * @var string |
||
44 | */ |
||
45 | private $endMultiLine; |
||
46 | |||
47 | /** |
||
48 | * The string to match a simple Directive. |
||
49 | * |
||
50 | * @var string |
||
51 | */ |
||
52 | private $simpleDirective; |
||
53 | |||
54 | /** |
||
55 | * The string to match an inclusion Directive. |
||
56 | * |
||
57 | * @var string |
||
58 | */ |
||
59 | private $inclusionDirective; |
||
60 | |||
61 | /** |
||
62 | * Constructor. |
||
63 | * |
||
64 | * @param string $startMultiLine match as a starting multi-line directive |
||
65 | * @param string $endMultiLine match as an ending multi-line directive |
||
66 | * @param string $simpleDirective match a simple directive |
||
67 | * @param string $inclusionDirective match an inclusion directive |
||
68 | */ |
||
69 | 7 | public function __construct($startMultiLine, $endMultiLine, $simpleDirective, $inclusionDirective) |
|
76 | |||
77 | /** |
||
78 | * Sets the parser instance. |
||
79 | * |
||
80 | * @param Parser $parser the parser instance |
||
81 | */ |
||
82 | 7 | public function setParser(Parser $parser) |
|
88 | |||
89 | /** |
||
90 | * Does a nested array of lines depending on container Directives. |
||
91 | * |
||
92 | * @param array $activeConfig a clean config array of lines |
||
93 | * @param string $context the context name |
||
94 | * @param string $value an optional context value |
||
95 | * |
||
96 | * @return Directive\BlockDirective a full context of directives |
||
97 | */ |
||
98 | 10 | public function doCompile($activeConfig, $context = 'main', $value = '') |
|
109 | |||
110 | /** |
||
111 | * Looks for a container directive. |
||
112 | * |
||
113 | * @param array $activeConfig a clean config array of directives |
||
114 | * @param string $lineConfig a line |
||
115 | * |
||
116 | * @return Directive\DirectiveInterface a directive or a container of directives |
||
117 | * |
||
118 | * @throws Exception\InvalidConfigException if a simple directive has invalid syntax |
||
119 | */ |
||
120 | 10 | private function subCompile(&$activeConfig, $lineConfig) |
|
132 | |||
133 | /** |
||
134 | * Finds the end of a container directive. |
||
135 | * |
||
136 | * @param string $context a container's name |
||
137 | * @param string $contextValue a container's value |
||
138 | * @param array $activeConfig a clean config array of lines |
||
139 | * |
||
140 | * @return Directive\BlockDirective a container of directives |
||
141 | * |
||
142 | * @throws Exception\InvalidConfigException if a container does not end correctly |
||
143 | */ |
||
144 | 9 | private function findEndingKey($context, $contextValue, &$activeConfig) |
|
161 | |||
162 | /** |
||
163 | * Builds a BlockDirective. |
||
164 | * |
||
165 | * @param string $context a container's name |
||
166 | * @param string $contextValue a container's value |
||
167 | * @param array $lines an array of directives |
||
168 | * |
||
169 | * @return Directive\BlockDirective the BlockDirective |
||
170 | */ |
||
171 | 8 | private function buildBlockDirective($context, $contextValue, $lines) |
|
180 | |||
181 | /** |
||
182 | * Build a SimpleDirective or an InclusionDirective. |
||
183 | * |
||
184 | * Remember that inclusion are parsed as simple directives but are block directives |
||
185 | * |
||
186 | * @see Directive\InclusionDirective Inclusion Doc |
||
187 | * |
||
188 | * @param string $key a directive's name |
||
189 | * @param string $value a directive's value |
||
190 | * |
||
191 | * @return Directive\SimpleDirective|Directive\InclusionDirective the Directive |
||
192 | */ |
||
193 | 9 | private function buildSimpleDirective($key, $value) |
|
201 | } |
||
202 |