1 | <?php |
||
21 | class Compiler |
||
22 | { |
||
23 | /** |
||
24 | * The parser instance. |
||
25 | * |
||
26 | * @var Parser |
||
27 | */ |
||
28 | private $parser; |
||
29 | |||
30 | /** |
||
31 | * The string to match as a starting multi-line directive. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | private $startMultiLine; |
||
36 | |||
37 | /** |
||
38 | * The string to match as an ending multi-line directive. |
||
39 | * |
||
40 | * @var string |
||
41 | */ |
||
42 | private $endMultiLine; |
||
43 | |||
44 | /** |
||
45 | * The string to match a simple Directive. |
||
46 | * |
||
47 | * @var string |
||
48 | */ |
||
49 | private $simpleDirective; |
||
50 | |||
51 | /** |
||
52 | * Constructor. |
||
53 | * |
||
54 | * @param string $startMultiLine match as a starting multi-line directive |
||
55 | * @param string $endMultiLine match as an ending multi-line directive |
||
56 | * @param string $simpleDirective match a simple directive |
||
57 | */ |
||
58 | 7 | public function __construct($startMultiLine, $endMultiLine, $simpleDirective) |
|
64 | |||
65 | /** |
||
66 | * Sets the parser instance. |
||
67 | * |
||
68 | * @param Parser $parser the parser instance |
||
69 | */ |
||
70 | 7 | public function setParser(Parser $parser) |
|
76 | |||
77 | /** |
||
78 | * Does a nested array of lines depending on container Directives. |
||
79 | * |
||
80 | * @param array $activeConfig a clean config array of lines |
||
81 | * @param string $context the context name |
||
82 | * @param string $value an optional context value |
||
83 | * |
||
84 | * @return Directive\BlockDirective a full context of directives |
||
85 | */ |
||
86 | 10 | public function doCompile($activeConfig, $context = 'main', $value = '') |
|
97 | |||
98 | /** |
||
99 | * Looks for a container directive. |
||
100 | * |
||
101 | * @param array $activeConfig a clean config array of directives |
||
102 | * @param string $lineConfig a line |
||
103 | * |
||
104 | * @throws Exception\InvalidConfigException if a simple directive has invalid syntax |
||
105 | * |
||
106 | * @return Directive\DirectiveInterface a directive or a container of directives |
||
107 | */ |
||
108 | 10 | private function subCompile(&$activeConfig, $lineConfig) |
|
120 | |||
121 | /** |
||
122 | * Finds the end of a container directive. |
||
123 | * |
||
124 | * @param string $context a container's name |
||
125 | * @param string $contextValue a container's value |
||
126 | * @param array $activeConfig a clean config array of lines |
||
127 | * |
||
128 | * @throws Exception\InvalidConfigException if a container does not end correctly |
||
129 | * |
||
130 | * @return Directive\BlockDirective a container of directives |
||
131 | */ |
||
132 | 9 | private function findEndingKey($context, $contextValue, &$activeConfig) |
|
149 | |||
150 | /** |
||
151 | * Builds a BlockDirective. |
||
152 | * |
||
153 | * @param string $context a container's name |
||
154 | * @param string $contextValue a container's value |
||
155 | * @param array $lines an array of directives |
||
156 | * |
||
157 | * @return Directive\BlockDirective the BlockDirective |
||
158 | */ |
||
159 | 8 | private function buildBlockDirective($context, $contextValue, $lines) |
|
175 | |||
176 | /** |
||
177 | * Build a SimpleDirective or an InclusionDirective. |
||
178 | * |
||
179 | * Remember that inclusion are parsed as simple directives but are block directives |
||
180 | * |
||
181 | * @see Directive\InclusionDirective Inclusion Doc |
||
182 | * |
||
183 | * @param string $key a directive's name |
||
184 | * @param string $value a directive's value |
||
185 | * |
||
186 | * @return Directive\SimpleDirective|Directive\InclusionDirective the Directive |
||
187 | */ |
||
188 | 9 | private function buildSimpleDirective($key, $value) |
|
200 | } |
||
201 |