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 | /** @var bool */ |
||
61 | private $isHttps; |
||
62 | |||
63 | /** |
||
64 | * ModuleManager constructor. |
||
65 | * |
||
66 | * @param ConfigInterface $config |
||
67 | * @param array $getData |
||
68 | * @param array $postData |
||
69 | * @param array $serverData |
||
70 | * @param array $cookieData |
||
71 | * @param array $filesData |
||
72 | */ |
||
73 | 9 | public function __construct( |
|
106 | |||
107 | /** |
||
108 | * Gets the application domain. |
||
109 | * |
||
110 | * @return string |
||
111 | */ |
||
112 | public function getApplicationDomain() |
||
116 | |||
117 | /** |
||
118 | * Gets the application SSL status. |
||
119 | * |
||
120 | * @return bool |
||
121 | */ |
||
122 | public function isSecuredApplication() |
||
126 | |||
127 | /** |
||
128 | * Gets the selected application. |
||
129 | * |
||
130 | * @return string |
||
131 | */ |
||
132 | 4 | public function getSelectedApplication() |
|
136 | |||
137 | /** |
||
138 | * Get the URI path for the selected application. Required for the RouterAdapter to work with directory-based |
||
139 | * applications correctly. |
||
140 | * |
||
141 | * @return string |
||
142 | */ |
||
143 | 8 | public function getSelectedApplicationUri() |
|
147 | |||
148 | /** |
||
149 | * Gets the selected module. |
||
150 | * |
||
151 | * @return string |
||
152 | */ |
||
153 | 6 | public function getSelectedModule() |
|
157 | |||
158 | /** |
||
159 | * Gets the selected theme. |
||
160 | * |
||
161 | * @return string |
||
162 | */ |
||
163 | 5 | public function getSelectedTheme() |
|
167 | |||
168 | /** |
||
169 | * Gets the resource path for the selected theme. |
||
170 | * |
||
171 | * @return string |
||
172 | */ |
||
173 | 6 | public function getResourcePath() |
|
177 | |||
178 | /** |
||
179 | * Gets environment data. |
||
180 | * |
||
181 | * @param string $key |
||
182 | * |
||
183 | * @return array |
||
184 | */ |
||
185 | 5 | public function getEnvironmentData($key) |
|
193 | |||
194 | /** |
||
195 | * Gets the template settings for a specific theme. |
||
196 | * |
||
197 | * @param string $theme |
||
198 | * |
||
199 | * @codeCoverageIgnore - @see \WebHemiTest\Config\ConfigTest |
||
200 | * |
||
201 | * @return ConfigInterface |
||
202 | */ |
||
203 | public function getApplicationTemplateSettings($theme = self::DEFAULT_THEME) |
||
207 | |||
208 | /** |
||
209 | * Gets the routing settings for the selected module. |
||
210 | * |
||
211 | * @codeCoverageIgnore - @see \WebHemiTest\Config\ConfigTest |
||
212 | * |
||
213 | * @return ConfigInterface |
||
214 | */ |
||
215 | public function getModuleRouteSettings() |
||
219 | |||
220 | /** |
||
221 | * Parses server data and tries to set domain information. |
||
222 | * |
||
223 | * @return $this |
||
224 | */ |
||
225 | 9 | private function setDomain() |
|
265 | |||
266 | /** |
||
267 | * From the parsed domain data, selects the application, module and theme. |
||
268 | * |
||
269 | * @return $this |
||
270 | */ |
||
271 | 9 | private function selectModuleApplicationAndTheme() |
|
308 | |||
309 | /** |
||
310 | * Checks from type, path it the current URI segment is valid. |
||
311 | * |
||
312 | * @param string $applicationName |
||
313 | * @param array $applicationData |
||
314 | * @param string $subDirectory |
||
315 | * |
||
316 | * @return bool |
||
317 | */ |
||
318 | 9 | private function checkDirectoryIsValid($applicationName, $applicationData, $subDirectory) |
|
326 | |||
327 | /** |
||
328 | * Checks from type and path if the domain is valid. If so, it sets the $subDirectory to the default. |
||
329 | * |
||
330 | * @param string $applicationName |
||
331 | * @param array $applicationData |
||
332 | * @param string $subDirectory |
||
333 | * |
||
334 | * @return bool |
||
335 | */ |
||
336 | 9 | private function checkDomainIsValid($applicationName, $applicationData, &$subDirectory) |
|
353 | } |
||
354 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.