1 | <?php |
||
23 | abstract class Parser implements ParserInterface |
||
24 | { |
||
25 | /** @var Server\ServerInterface a server instance */ |
||
26 | private $server; |
||
27 | |||
28 | /** @var string configuration file */ |
||
29 | private $configFile = ''; |
||
30 | |||
31 | /** @var array active directives in an array */ |
||
32 | protected $activeConfig = []; |
||
33 | |||
34 | /** |
||
35 | * Setter for the server instance. |
||
36 | * |
||
37 | * @see Server\ServerInterface Server Documentation |
||
38 | * |
||
39 | * @param Server\ServerInterface $server the server instance |
||
40 | */ |
||
41 | 8 | public function setServer(ServerInterface $server) |
|
47 | |||
48 | /** |
||
49 | * Setter for the config file to parse. |
||
50 | * |
||
51 | * @param string $configFile configuration file |
||
52 | * |
||
53 | * @throws Exception\ParserException if configuration file is not readable |
||
54 | * @throws Exception\InvalidConfigException if active configuration is empty |
||
55 | */ |
||
56 | 12 | public function setConfigFile($configFile = '') |
|
71 | |||
72 | /** |
||
73 | * Getter for the server instance. |
||
74 | * |
||
75 | * @see Server\ServerInterface Server Documentation |
||
76 | * |
||
77 | * @param Server\ServerInterface the server instance |
||
78 | */ |
||
79 | 1 | public function getServer() |
|
83 | |||
84 | /** |
||
85 | * Getter for the active config main context. |
||
86 | * |
||
87 | * @return Directive\DirectiveInterface the active config |
||
88 | */ |
||
89 | abstract public function getActiveConfig(); |
||
90 | |||
91 | /** |
||
92 | * Getter for the content of the configuration file. |
||
93 | * |
||
94 | * @return string content of the configuration file |
||
95 | */ |
||
96 | 11 | public function getOriginalConfig() |
|
100 | |||
101 | /** |
||
102 | * Does some extra parsing before the active config turns into an array. |
||
103 | * |
||
104 | * @param string $config a config file content |
||
105 | * |
||
106 | * @return string a config file content |
||
107 | */ |
||
108 | 11 | protected function beforeExplode($config) |
|
114 | |||
115 | /** |
||
116 | * Does some extra parsing after the active config has turned into an array. |
||
117 | * |
||
118 | * @param array $activeConfig an active config |
||
119 | * |
||
120 | * @return array an active config |
||
121 | */ |
||
122 | 11 | protected function afterExplode(array $activeConfig) |
|
128 | |||
129 | /** |
||
130 | * Comon parsing to both apache and nginx. |
||
131 | * |
||
132 | * @return bool true if active lines were found |
||
133 | */ |
||
134 | 11 | private function parseConfigFile() |
|
146 | |||
147 | /** |
||
148 | * Deletes commented lines and end line comments. |
||
149 | * |
||
150 | * @param string $config a file content |
||
151 | * |
||
152 | * @return string a file content without comments |
||
153 | */ |
||
154 | 11 | private function deleteComments($config = '') |
|
161 | |||
162 | /** |
||
163 | * Trim all blank lines. |
||
164 | * |
||
165 | * @param array $activeConfig config file exploded in an array of lines |
||
166 | * |
||
167 | * @return array an array cleaned of blank lines |
||
168 | */ |
||
169 | 11 | private function deleteBlankLines(array $activeConfig = array()) |
|
181 | } |
||
182 |