1 | <?php |
||
20 | class EnvironmentManager |
||
21 | { |
||
22 | const APPLICATION_TYPE_DIRECTORY = 'directory'; |
||
23 | const APPLICATION_TYPE_DOMAIN = 'domain'; |
||
24 | |||
25 | const COOKIE_AUTO_LOGIN_PREFIX = 'atln'; |
||
26 | const COOKIE_SESSION_PREFIX = 'atsn'; |
||
27 | |||
28 | const DEFAULT_APPLICATION = 'website'; |
||
29 | const DEFAULT_APPLICATION_URI = '/'; |
||
30 | const DEFAULT_MODULE = 'Website'; |
||
31 | const DEFAULT_THEME = 'default'; |
||
32 | const DEFAULT_THEME_RESOURCE_PATH = '/resources/default_theme'; |
||
33 | |||
34 | const SESSION_SALT = 'WebHemi'; |
||
35 | |||
36 | /** @var ConfigInterface */ |
||
37 | private $config; |
||
38 | /** @var string */ |
||
39 | private $url; |
||
40 | /** @var string */ |
||
41 | private $subDomain; |
||
42 | /** @var string */ |
||
43 | private $mainDomain; |
||
44 | /** @var string */ |
||
45 | private $applicationDomain; |
||
46 | /** @var string */ |
||
47 | private $documentRoot; |
||
48 | /** @var string */ |
||
49 | private $selectedModule; |
||
50 | /** @var string */ |
||
51 | private $selectedApplication; |
||
52 | /** @var string */ |
||
53 | private $selectedApplicationUri; |
||
54 | /** @var string */ |
||
55 | private $selectedTheme; |
||
56 | /** @var string */ |
||
57 | private $selectedThemeResourcePath; |
||
58 | /** @var array */ |
||
59 | private $environmentData; |
||
60 | |||
61 | /** |
||
62 | * ModuleManager constructor. |
||
63 | * |
||
64 | * @param ConfigInterface $config |
||
65 | * @param array $getData |
||
66 | * @param array $postData |
||
67 | * @param array $serverData |
||
68 | * @param array $cookieData |
||
69 | * @param array $filesData |
||
70 | */ |
||
71 | 4 | public function __construct( |
|
106 | |||
107 | /** |
||
108 | * Gets the selected application. |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | 4 | public function getSelectedApplication() |
|
116 | |||
117 | /** |
||
118 | * Get the URI path for the selected application. Required for the RouterAdapter to work with directory-based |
||
119 | * applications correctly. |
||
120 | * |
||
121 | * @return string |
||
122 | */ |
||
123 | 4 | public function getSelectedApplicationUri() |
|
127 | |||
128 | /** |
||
129 | * Gets the selected module. |
||
130 | * |
||
131 | * @return string |
||
132 | */ |
||
133 | 1 | public function getSelectedModule() |
|
137 | |||
138 | /** |
||
139 | * Gets the selected theme. |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | 1 | public function getSelectedTheme() |
|
147 | |||
148 | /** |
||
149 | * Gets the resource path for the selected theme. |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | 2 | public function getResourcePath() |
|
157 | |||
158 | /** |
||
159 | * Gets environment data. |
||
160 | * |
||
161 | * @param string $key |
||
162 | * |
||
163 | * @return array |
||
164 | */ |
||
165 | 1 | public function getEnvironmentData($key) |
|
173 | |||
174 | /** |
||
175 | * Gets the template settings for a specific theme. |
||
176 | * |
||
177 | * @param string $theme |
||
178 | * |
||
179 | * @codeCoverageIgnore - @see \WebHemiTest\Config\ConfigTest |
||
180 | * |
||
181 | * @return ConfigInterface |
||
182 | */ |
||
183 | public function getApplicationTemplateSettings($theme = self::DEFAULT_THEME) |
||
187 | |||
188 | /** |
||
189 | * Gets the routing settings for the selected module. |
||
190 | * |
||
191 | * @codeCoverageIgnore - @see \WebHemiTest\Config\ConfigTest |
||
192 | * |
||
193 | * @return ConfigInterface |
||
194 | */ |
||
195 | public function getModuleRouteSettings() |
||
199 | |||
200 | /** |
||
201 | * Overwrite PHP settings to be more secure |
||
202 | * |
||
203 | * @codeCoverageIgnore - Core functions. |
||
204 | * |
||
205 | * @return $this |
||
206 | */ |
||
207 | private function secureSession() |
||
224 | |||
225 | /** |
||
226 | * Parses server data and tries to set domain information. |
||
227 | * |
||
228 | * @return $this |
||
229 | */ |
||
230 | 4 | private function setDomain() |
|
260 | |||
261 | /** |
||
262 | * From the parsed domain data, selects the application, module and theme. |
||
263 | * |
||
264 | * @return $this |
||
265 | */ |
||
266 | 4 | private function selectModuleApplicationAndTheme() |
|
303 | |||
304 | /** |
||
305 | * Checks from type, path it the current URI segment is valid. |
||
306 | * |
||
307 | * @param string $type |
||
308 | * @param string $path |
||
309 | * @param string $subDirectory |
||
310 | * |
||
311 | * @return bool |
||
312 | */ |
||
313 | 4 | private function checkDirectoryIsValid($type, $path, $subDirectory) |
|
320 | |||
321 | /** |
||
322 | * Checks from type and path if the domain is valid. If so, it sets the $subDirectory to the default. |
||
323 | * |
||
324 | * @param string $type |
||
325 | * @param string $path |
||
326 | * @param string $subDirectory |
||
327 | * |
||
328 | * @return bool |
||
329 | */ |
||
330 | 4 | private function checkDomainIsValid($type, $path, &$subDirectory) |
|
344 | } |
||
345 |