1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* \AppserverIo\Server\Configuration\ServerJsonConfiguration |
5
|
|
|
* |
6
|
|
|
* NOTICE OF LICENSE |
7
|
|
|
* |
8
|
|
|
* This source file is subject to the Open Software License (OSL 3.0) |
9
|
|
|
* that is available through the world-wide-web at this URL: |
10
|
|
|
* http://opensource.org/licenses/osl-3.0.php |
11
|
|
|
* |
12
|
|
|
* PHP version 5 |
13
|
|
|
* |
14
|
|
|
* @author Johann Zelger <[email protected]> |
15
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
16
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
17
|
|
|
* @link https://github.com/appserver-io/server |
18
|
|
|
* @link http://www.appserver.io |
19
|
|
|
*/ |
20
|
|
|
|
21
|
|
|
namespace AppserverIo\Server\Configuration; |
22
|
|
|
|
23
|
|
|
use AppserverIo\Server\Interfaces\ServerConfigurationInterface; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Class ServerJsonConfiguration |
27
|
|
|
* |
28
|
|
|
* @author Johann Zelger <[email protected]> |
29
|
|
|
* @copyright 2015 TechDivision GmbH <[email protected]> |
30
|
|
|
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) |
31
|
|
|
* @link https://github.com/appserver-io/server |
32
|
|
|
* @link http://www.appserver.io |
33
|
|
|
*/ |
34
|
|
|
class ServerJsonConfiguration implements ServerConfigurationInterface |
35
|
|
|
{ |
36
|
|
|
/** |
37
|
|
|
* Holds raw data instance |
38
|
|
|
* |
39
|
|
|
* @var \stdClass |
40
|
|
|
*/ |
41
|
|
|
protected $data; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Holds the modules to be used |
45
|
|
|
* |
46
|
|
|
* @var array |
47
|
|
|
*/ |
48
|
|
|
protected $modules; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Holds the handlers array |
52
|
|
|
* |
53
|
|
|
* @var array |
54
|
|
|
*/ |
55
|
|
|
protected $handlers; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Holds the virtual hosts array |
59
|
|
|
* |
60
|
|
|
* @var array |
61
|
|
|
*/ |
62
|
|
|
protected $virtualHosts; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* Holds the authentications array |
66
|
|
|
* |
67
|
|
|
* @var array |
68
|
|
|
*/ |
69
|
|
|
protected $authentications; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Holds the rewrites array |
73
|
|
|
* |
74
|
|
|
* @var array |
75
|
|
|
*/ |
76
|
|
|
protected $rewrites; |
77
|
|
|
|
78
|
|
|
/** |
79
|
|
|
* Holds the environmentVariables array |
80
|
|
|
* |
81
|
|
|
* @var array |
82
|
|
|
*/ |
83
|
|
|
protected $environmentVariables; |
84
|
|
|
|
85
|
|
|
/** |
86
|
|
|
* Holds the connection handlers array |
87
|
|
|
* |
88
|
|
|
* @var array |
89
|
|
|
*/ |
90
|
|
|
protected $connectionHandlers; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Holds the accesses array |
94
|
|
|
* |
95
|
|
|
* @var array |
96
|
|
|
*/ |
97
|
|
|
protected $accesses; |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Holds the accesses array |
101
|
|
|
* |
102
|
|
|
* @var array |
103
|
|
|
*/ |
104
|
|
|
protected $analytics; |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* The configured locations. |
108
|
|
|
* |
109
|
|
|
* @var array |
110
|
|
|
*/ |
111
|
|
|
protected $locations; |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* The rewrite maps |
115
|
|
|
* |
116
|
|
|
* @var array |
117
|
|
|
*/ |
118
|
|
|
protected $rewriteMaps; |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* Constructs config |
122
|
|
|
* |
123
|
|
|
* @param \stdClass $data The data object use |
124
|
|
|
*/ |
125
|
|
|
public function __construct($data) |
126
|
|
|
{ |
127
|
|
|
$this->data = $data; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
/** |
131
|
|
|
* Returns name |
132
|
|
|
* |
133
|
|
|
* @return string |
134
|
|
|
*/ |
135
|
|
|
public function getName() |
136
|
|
|
{ |
137
|
|
|
return $this->data->name; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* Returns logger name |
142
|
|
|
* |
143
|
|
|
* @return string |
144
|
|
|
*/ |
145
|
|
|
public function getLoggerName() |
146
|
|
|
{ |
147
|
|
|
return $this->data->loggerName; |
148
|
|
|
} |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Returns type |
152
|
|
|
* |
153
|
|
|
* @return string |
154
|
|
|
*/ |
155
|
|
|
public function getType() |
156
|
|
|
{ |
157
|
|
|
return $this->data->type; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* Returns transport |
162
|
|
|
* |
163
|
|
|
* @return string |
164
|
|
|
*/ |
165
|
|
|
public function getTransport() |
166
|
|
|
{ |
167
|
|
|
return $this->data->transport; |
168
|
|
|
} |
169
|
|
|
|
170
|
|
|
/** |
171
|
|
|
* Returns address |
172
|
|
|
* |
173
|
|
|
* @return string |
174
|
|
|
*/ |
175
|
|
|
public function getAddress() |
176
|
|
|
{ |
177
|
|
|
return $this->data->address; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* Returns port |
182
|
|
|
* |
183
|
|
|
* @return int |
184
|
|
|
*/ |
185
|
|
|
public function getPort() |
186
|
|
|
{ |
187
|
|
|
return (int)$this->data->port; |
188
|
|
|
} |
189
|
|
|
|
190
|
|
|
/** |
191
|
|
|
* Returns flags |
192
|
|
|
* |
193
|
|
|
* @return string |
194
|
|
|
*/ |
195
|
|
|
public function getFlags() |
196
|
|
|
{ |
197
|
|
|
return $this->data->flags; |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* Returns software |
202
|
|
|
* |
203
|
|
|
* @return string |
204
|
|
|
*/ |
205
|
|
|
public function getSoftware() |
206
|
|
|
{ |
207
|
|
|
return $this->data->software; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
/** |
211
|
|
|
* Returns admin |
212
|
|
|
* |
213
|
|
|
* @return string |
214
|
|
|
*/ |
215
|
|
|
public function getAdmin() |
216
|
|
|
{ |
217
|
|
|
return $this->data->admin; |
218
|
|
|
} |
219
|
|
|
|
220
|
|
|
/** |
221
|
|
|
* Returns keep-alive max connection |
222
|
|
|
* |
223
|
|
|
* @return int |
224
|
|
|
*/ |
225
|
|
|
public function getKeepAliveMax() |
226
|
|
|
{ |
227
|
|
|
return (int)$this->data->keepAliveMax; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Returns keep-alive timeout |
232
|
|
|
* |
233
|
|
|
* @return int |
234
|
|
|
*/ |
235
|
|
|
public function getKeepAliveTimeout() |
236
|
|
|
{ |
237
|
|
|
return (int)$this->data->keepAliveTimeout; |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* Returns admin |
242
|
|
|
* |
243
|
|
|
* @return string |
244
|
|
|
*/ |
245
|
|
|
public function getErrorsPageTemplatePath() |
246
|
|
|
{ |
247
|
|
|
return $this->data->errorsPageTemplatePath; |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
/** |
251
|
|
|
* Returns template path for possible configured welcome page |
252
|
|
|
* |
253
|
|
|
* @return string |
254
|
|
|
*/ |
255
|
|
|
public function getWelcomePageTemplatePath() |
256
|
|
|
{ |
257
|
|
|
return $this->data->welcomePageTemplatePath; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
/** |
261
|
|
|
* Returns template path for possible configured auto index page |
262
|
|
|
* |
263
|
|
|
* @return string |
264
|
|
|
*/ |
265
|
|
|
public function getAutoIndexTemplatePath() |
266
|
|
|
{ |
267
|
|
|
return $this->data->autoIndexTemplatePath; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
/** |
271
|
|
|
* Returns worker number |
272
|
|
|
* |
273
|
|
|
* @return int |
274
|
|
|
*/ |
275
|
|
|
public function getWorkerNumber() |
276
|
|
|
{ |
277
|
|
|
return (int)$this->data->workerNumber; |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
/** |
281
|
|
|
* Returns worker's accept min count |
282
|
|
|
* |
283
|
|
|
* @return int |
284
|
|
|
*/ |
285
|
|
|
public function getWorkerAcceptMin() |
286
|
|
|
{ |
287
|
|
|
return (int)$this->data->workerAcceptMin; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Returns worker's accept min count |
292
|
|
|
* |
293
|
|
|
* @return int |
294
|
|
|
*/ |
295
|
|
|
public function getWorkerAcceptMax() |
296
|
|
|
{ |
297
|
|
|
return (int)$this->data->workerAcceptMax; |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
/** |
301
|
|
|
* Returns the auto index configuration |
302
|
|
|
* |
303
|
|
|
* @return boolean |
304
|
|
|
*/ |
305
|
|
|
public function getAutoIndex() |
306
|
|
|
{ |
307
|
|
|
return (boolean)$this->data->autoIndex; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
/** |
311
|
|
|
* Returns context type |
312
|
|
|
* |
313
|
|
|
* @return string |
314
|
|
|
*/ |
315
|
|
|
public function getServerContextType() |
316
|
|
|
{ |
317
|
|
|
return $this->data->serverContext; |
318
|
|
|
} |
319
|
|
|
|
320
|
|
|
/** |
321
|
|
|
* Returns stream context type |
322
|
|
|
* |
323
|
|
|
* @return string |
324
|
|
|
*/ |
325
|
|
|
public function getStreamContextType() |
326
|
|
|
{ |
327
|
|
|
return $this->data->streamContext; |
328
|
|
|
} |
329
|
|
|
|
330
|
|
|
/** |
331
|
|
|
* Returns request type |
332
|
|
|
* |
333
|
|
|
* @return string |
334
|
|
|
*/ |
335
|
|
|
public function getRequestContextType() |
336
|
|
|
{ |
337
|
|
|
return $this->data->requestContext; |
338
|
|
|
} |
339
|
|
|
|
340
|
|
|
/** |
341
|
|
|
* Returns socket type |
342
|
|
|
* |
343
|
|
|
* @return string |
344
|
|
|
*/ |
345
|
|
|
public function getSocketType() |
346
|
|
|
{ |
347
|
|
|
return $this->data->socket; |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Returns worker type |
352
|
|
|
* |
353
|
|
|
* @return string |
354
|
|
|
*/ |
355
|
|
|
public function getWorkerType() |
356
|
|
|
{ |
357
|
|
|
return $this->data->worker; |
358
|
|
|
} |
359
|
|
|
|
360
|
|
|
/** |
361
|
|
|
* Returns document root |
362
|
|
|
* |
363
|
|
|
* @return string |
364
|
|
|
*/ |
365
|
|
|
public function getDocumentRoot() |
366
|
|
|
{ |
367
|
|
|
return $this->data->documentRoot; |
368
|
|
|
} |
369
|
|
|
|
370
|
|
|
/** |
371
|
|
|
* Returns directory index definition |
372
|
|
|
* |
373
|
|
|
* @return string |
374
|
|
|
*/ |
375
|
|
|
public function getDirectoryIndex() |
376
|
|
|
{ |
377
|
|
|
return $this->data->directoryIndex; |
378
|
|
|
} |
379
|
|
|
|
380
|
|
|
/** |
381
|
|
|
* Returns connection handlers |
382
|
|
|
* |
383
|
|
|
* @return array |
384
|
|
|
*/ |
385
|
|
|
public function getConnectionHandlers() |
386
|
|
|
{ |
387
|
|
|
if (!$this->connectionHandlers) { |
|
|
|
|
388
|
|
|
$this->connectionHandlers = $this->prepareConnectionHandlers($this->data); |
389
|
|
|
} |
390
|
|
|
return $this->connectionHandlers; |
391
|
|
|
} |
392
|
|
|
|
393
|
|
|
/** |
394
|
|
|
* Returns the headers used by the server |
395
|
|
|
* |
396
|
|
|
* @return array |
397
|
|
|
*/ |
398
|
|
|
public function getHeaders() |
399
|
|
|
{ |
400
|
|
|
if (!$this->headers) { |
401
|
|
|
$this->headers = $this->prepareHeaders($this->data); |
|
|
|
|
402
|
|
|
} |
403
|
|
|
return $this->headers; |
404
|
|
|
} |
405
|
|
|
|
406
|
|
|
/** |
407
|
|
|
* Returns the certificates used by the server |
408
|
|
|
* |
409
|
|
|
* @return array |
410
|
|
|
*/ |
411
|
|
|
public function getCertificates() |
412
|
|
|
{ |
413
|
|
|
if (!$this->certificates) { |
414
|
|
|
$this->certificates = $this->prepareCertificates($this->data); |
|
|
|
|
415
|
|
|
} |
416
|
|
|
return $this->certificates; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* Returns the virtual hosts |
421
|
|
|
* |
422
|
|
|
* @return array |
423
|
|
|
*/ |
424
|
|
|
public function getVirtualHosts() |
425
|
|
|
{ |
426
|
|
|
if (!$this->virtualHosts) { |
|
|
|
|
427
|
|
|
$this->virtualHosts = $this->prepareVirtualHosts($this->data); |
428
|
|
|
} |
429
|
|
|
return $this->virtualHosts; |
430
|
|
|
} |
431
|
|
|
|
432
|
|
|
/** |
433
|
|
|
* Returns the authentications |
434
|
|
|
* |
435
|
|
|
* @return array |
436
|
|
|
*/ |
437
|
|
|
public function getAuthentications() |
438
|
|
|
{ |
439
|
|
|
if (!$this->authentications) { |
|
|
|
|
440
|
|
|
$this->authentications = $this->prepareAuthentications($this->data); |
441
|
|
|
} |
442
|
|
|
return $this->authentications; |
443
|
|
|
} |
444
|
|
|
|
445
|
|
|
/** |
446
|
|
|
* Returns modules |
447
|
|
|
* |
448
|
|
|
* @return array |
449
|
|
|
*/ |
450
|
|
|
public function getModules() |
451
|
|
|
{ |
452
|
|
|
if (!$this->modules) { |
|
|
|
|
453
|
|
|
$this->modules = $this->prepareModules($this->data); |
454
|
|
|
} |
455
|
|
|
return $this->modules; |
456
|
|
|
} |
457
|
|
|
|
458
|
|
|
/** |
459
|
|
|
* Returns handlers |
460
|
|
|
* |
461
|
|
|
* @return array |
462
|
|
|
*/ |
463
|
|
|
public function getHandlers() |
464
|
|
|
{ |
465
|
|
|
if (!$this->handlers) { |
|
|
|
|
466
|
|
|
$this->handlers = $this->prepareHandlers($this->data); |
467
|
|
|
} |
468
|
|
|
return $this->handlers; |
469
|
|
|
} |
470
|
|
|
|
471
|
|
|
/** |
472
|
|
|
* Returns cert path |
473
|
|
|
* |
474
|
|
|
* @return string |
475
|
|
|
*/ |
476
|
|
|
public function getCertPath() |
477
|
|
|
{ |
478
|
|
|
return $this->data->certPath; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* Returns passphrase |
483
|
|
|
* |
484
|
|
|
* @return string |
485
|
|
|
*/ |
486
|
|
|
public function getPassphrase() |
487
|
|
|
{ |
488
|
|
|
return $this->data->passphrase; |
489
|
|
|
} |
490
|
|
|
|
491
|
|
|
/** |
492
|
|
|
* Returns the rewrite configuration. |
493
|
|
|
* |
494
|
|
|
* @return array |
495
|
|
|
*/ |
496
|
|
|
public function getRewrites() |
497
|
|
|
{ |
498
|
|
|
// init rewrites |
499
|
|
|
if (!$this->rewrites) { |
|
|
|
|
500
|
|
|
$this->rewrites = $this->prepareRewrites($this->data); |
501
|
|
|
} |
502
|
|
|
// return the rewrites |
503
|
|
|
return $this->rewrites; |
504
|
|
|
} |
505
|
|
|
|
506
|
|
|
/** |
507
|
|
|
* Returns the environment variable configuration |
508
|
|
|
* |
509
|
|
|
* @return array |
510
|
|
|
*/ |
511
|
|
|
public function getEnvironmentVariables() |
512
|
|
|
{ |
513
|
|
|
// init EnvironmentVariables |
514
|
|
|
if (!$this->environmentVariables) { |
|
|
|
|
515
|
|
|
$this->environmentVariables = $this->prepareEnvironmentVariables($this->data); |
516
|
|
|
} |
517
|
|
|
// return the environmentVariables |
518
|
|
|
return $this->environmentVariables; |
519
|
|
|
} |
520
|
|
|
|
521
|
|
|
/** |
522
|
|
|
* Returns the accesses |
523
|
|
|
* |
524
|
|
|
* @return array |
525
|
|
|
*/ |
526
|
|
|
public function getAccesses() |
527
|
|
|
{ |
528
|
|
|
if (!$this->accesses) { |
|
|
|
|
529
|
|
|
$this->accesses = $this->prepareAccesses($this->data); |
530
|
|
|
} |
531
|
|
|
return $this->accesses; |
532
|
|
|
} |
533
|
|
|
|
534
|
|
|
/** |
535
|
|
|
* Returns the analytics |
536
|
|
|
* |
537
|
|
|
* @return array |
538
|
|
|
*/ |
539
|
|
|
public function getAnalytics() |
540
|
|
|
{ |
541
|
|
|
if (!$this->analytics) { |
|
|
|
|
542
|
|
|
$this->analytics = $this->prepareAnalytics($this->data); |
543
|
|
|
} |
544
|
|
|
return $this->analytics; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* Returns the locations. |
549
|
|
|
* |
550
|
|
|
* @return array |
551
|
|
|
*/ |
552
|
|
|
public function getLocations() |
553
|
|
|
{ |
554
|
|
|
if (!$this->locations) { |
|
|
|
|
555
|
|
|
$this->locations = $this->prepareLocations($this->data); |
556
|
|
|
} |
557
|
|
|
return $this->locations; |
558
|
|
|
} |
559
|
|
|
|
560
|
|
|
|
561
|
|
|
/** |
562
|
|
|
* Returns the rewrite maps. |
563
|
|
|
* |
564
|
|
|
* @return array |
565
|
|
|
*/ |
566
|
|
|
public function getRewriteMaps() |
567
|
|
|
{ |
568
|
|
|
if (!$this->rewriteMaps) { |
|
|
|
|
569
|
|
|
$this->rewriteMaps = $this->prepareRewriteMaps($this->data); |
570
|
|
|
} |
571
|
|
|
return $this->rewriteMaps; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* Prepares the modules array based on a data object |
576
|
|
|
* |
577
|
|
|
* @param \stdClass $data The data object |
578
|
|
|
* |
579
|
|
|
* @return array |
580
|
|
|
*/ |
581
|
|
|
public function prepareModules(\stdClass $data) |
582
|
|
|
{ |
583
|
|
|
|
584
|
|
|
$modules = array(); |
585
|
|
|
if (isset($data->modules)) { |
586
|
|
|
foreach ($data->modules as $module) { |
587
|
|
|
$modules[] = new ModuleJsonConfiguration($module); |
588
|
|
|
} |
589
|
|
|
} |
590
|
|
|
return $modules; |
591
|
|
|
} |
592
|
|
|
|
593
|
|
|
/** |
594
|
|
|
* Prepares the connectionHandlers array based on a data object |
595
|
|
|
* |
596
|
|
|
* @param \stdClass $data The data object |
597
|
|
|
* |
598
|
|
|
* @return array |
599
|
|
|
*/ |
600
|
|
|
public function prepareConnectionHandlers(\stdClass $data) |
601
|
|
|
{ |
602
|
|
|
$connectionHandlers = array(); |
603
|
|
|
if (isset($data->connectionHandlers)) { |
604
|
|
|
$connectionHandlers = $data->connectionHandlers; |
605
|
|
|
} |
606
|
|
|
return $connectionHandlers; |
607
|
|
|
} |
608
|
|
|
|
609
|
|
|
/** |
610
|
|
|
* Prepares the headers array based on a data object |
611
|
|
|
* |
612
|
|
|
* @param \stdClass $data The data object |
613
|
|
|
* |
614
|
|
|
* @return array |
615
|
|
|
*/ |
616
|
|
|
public function prepareHeaders(\stdClass $data) |
617
|
|
|
{ |
618
|
|
|
$headers = array(); |
619
|
|
|
if (isset($data->headers)) { |
620
|
|
|
$headers = $data->headers; |
621
|
|
|
} |
622
|
|
|
return $headers; |
623
|
|
|
} |
624
|
|
|
|
625
|
|
|
/** |
626
|
|
|
* Prepares the certificates array based on a data object |
627
|
|
|
* |
628
|
|
|
* @param \stdClass $data The data object |
629
|
|
|
* |
630
|
|
|
* @return array |
631
|
|
|
*/ |
632
|
|
|
public function prepareCertificates(\stdClass $data) |
633
|
|
|
{ |
634
|
|
|
$certificates = array(); |
635
|
|
|
if (isset($data->certificates)) { |
636
|
|
|
$certificates = $data->certificates; |
637
|
|
|
} |
638
|
|
|
return $certificates; |
639
|
|
|
} |
640
|
|
|
|
641
|
|
|
/** |
642
|
|
|
* Prepares the handlers array based on a data object |
643
|
|
|
* |
644
|
|
|
* @param \stdClass $data The data object |
645
|
|
|
* |
646
|
|
|
* @return array |
647
|
|
|
*/ |
648
|
|
|
public function prepareHandlers(\stdClass $data) |
649
|
|
|
{ |
650
|
|
|
$handlers = array(); |
651
|
|
|
if (isset($data->handlers)) { |
652
|
|
|
foreach ($data->handlers as $handler) { |
653
|
|
|
// get all params |
654
|
|
|
$params = array(); |
655
|
|
|
if (isset($handler->params)) { |
656
|
|
|
$params = (array)$handler->params; |
657
|
|
|
} |
658
|
|
|
// set the handler information |
659
|
|
|
$handlers[$handler->extension] = array( |
660
|
|
|
"name" => $handler->name, |
661
|
|
|
"params" => $params |
662
|
|
|
); |
663
|
|
|
} |
664
|
|
|
} |
665
|
|
|
return $handlers; |
666
|
|
|
} |
667
|
|
|
|
668
|
|
|
/** |
669
|
|
|
* Prepares the virtual hosts array based on a data object |
670
|
|
|
* |
671
|
|
|
* @param \stdClass $data The data object |
672
|
|
|
* |
673
|
|
|
* @return array |
674
|
|
|
*/ |
675
|
|
|
public function prepareVirtualHosts(\stdClass $data) |
676
|
|
|
{ |
677
|
|
|
$virtualHosts = array(); |
678
|
|
|
if (isset($data->virtualHosts)) { |
679
|
|
|
foreach ($data->virtualHosts as $virtualHost) { |
680
|
|
|
// explode virtuaHost names |
681
|
|
|
$virtualHostNames = explode(' ', $virtualHost->name); |
682
|
|
|
// get all params |
683
|
|
|
$params = get_object_vars($virtualHost); |
684
|
|
|
// remove name |
685
|
|
|
unset($params["name"]); |
686
|
|
|
// set all virtual host information's |
687
|
|
View Code Duplication |
foreach ($virtualHostNames as $virtualHostName) { |
|
|
|
|
688
|
|
|
// add all virtual hosts params per key for faster matching later on |
689
|
|
|
$virtualHosts[trim($virtualHostName)] = array( |
690
|
|
|
'params' => $params, |
691
|
|
|
'rewriteMaps' => $this->prepareRewriteMaps($virtualHost), |
692
|
|
|
'rewrites' => $this->prepareRewrites($virtualHost), |
693
|
|
|
'locations' => $this->prepareLocations($virtualHost), |
694
|
|
|
'environmentVariables' => $this->prepareEnvironmentVariables($virtualHost), |
695
|
|
|
'authentication' => $this->prepareAuthentications($virtualHost), |
696
|
|
|
'accesses' => $this->prepareAccesses($virtualHost), |
697
|
|
|
'analytics' => $this->prepareAnalytics($virtualHost) |
698
|
|
|
); |
699
|
|
|
} |
700
|
|
|
} |
701
|
|
|
} |
702
|
|
|
return $virtualHosts; |
703
|
|
|
} |
704
|
|
|
|
705
|
|
|
/** |
706
|
|
|
* Prepares the rewrites array based on a data object |
707
|
|
|
* |
708
|
|
|
* @param \stdClass $data The data object |
709
|
|
|
* |
710
|
|
|
* @return array |
711
|
|
|
*/ |
712
|
|
View Code Duplication |
public function prepareRewrites(\stdClass $data) |
|
|
|
|
713
|
|
|
{ |
714
|
|
|
$rewrites = array(); |
715
|
|
|
if (isset($data->rewrites)) { |
716
|
|
|
// prepare the array with the rewrite rules |
717
|
|
|
foreach ($data->rewrites as $rewrite) { |
718
|
|
|
// Build up the array entry |
719
|
|
|
$rewrites[] = array( |
720
|
|
|
'condition' => $rewrite->condition, |
721
|
|
|
'target' => $rewrite->target, |
722
|
|
|
'flag' => $rewrite->flag |
723
|
|
|
); |
724
|
|
|
} |
725
|
|
|
} |
726
|
|
|
return $rewrites; |
727
|
|
|
} |
728
|
|
|
|
729
|
|
|
/** |
730
|
|
|
* Prepares the environmentVariables array based on a data object |
731
|
|
|
* |
732
|
|
|
* @param \stdClass $data The data object |
733
|
|
|
* |
734
|
|
|
* @return array |
735
|
|
|
*/ |
736
|
|
View Code Duplication |
public function prepareEnvironmentVariables(\stdClass $data) |
|
|
|
|
737
|
|
|
{ |
738
|
|
|
$environmentVariables = array(); |
739
|
|
|
if (isset($data->environmentVariables)) { |
740
|
|
|
// prepare the array with the environment variables |
741
|
|
|
foreach ($data->environmentVariables as $environmentVariable) { |
742
|
|
|
// Build up the array entry |
743
|
|
|
$environmentVariables[] = array( |
744
|
|
|
'condition' => $environmentVariable->condition, |
745
|
|
|
'definition' => $environmentVariable->definition |
746
|
|
|
); |
747
|
|
|
} |
748
|
|
|
} |
749
|
|
|
return $environmentVariables; |
750
|
|
|
} |
751
|
|
|
|
752
|
|
|
/** |
753
|
|
|
* Prepares the authentications array based on a data object |
754
|
|
|
* |
755
|
|
|
* @param \stdClass $data The data object |
756
|
|
|
* |
757
|
|
|
* @return array |
758
|
|
|
*/ |
759
|
|
View Code Duplication |
public function prepareAuthentications(\stdClass $data) |
|
|
|
|
760
|
|
|
{ |
761
|
|
|
$authentications = array(); |
762
|
|
|
if (isset($data->authentications)) { |
763
|
|
|
foreach ($data->authentications as $authentication) { |
764
|
|
|
$authenticationType = $authentication->uri; |
765
|
|
|
// get all params |
766
|
|
|
$params = get_object_vars($authentication); |
767
|
|
|
// remove type |
768
|
|
|
unset($params["uri"]); |
769
|
|
|
// set all authentication information's |
770
|
|
|
$authentications[$authenticationType] = $params; |
771
|
|
|
} |
772
|
|
|
} |
773
|
|
|
return $authentications; |
774
|
|
|
} |
775
|
|
|
|
776
|
|
|
/** |
777
|
|
|
* Prepares the access array based on a data object |
778
|
|
|
* |
779
|
|
|
* @param \stdClass $data The data object |
780
|
|
|
* |
781
|
|
|
* @return array |
782
|
|
|
*/ |
783
|
|
View Code Duplication |
public function prepareAccesses(\stdClass $data) |
|
|
|
|
784
|
|
|
{ |
785
|
|
|
$accesses = array(); |
786
|
|
|
if (isset($data->accesses)) { |
787
|
|
|
foreach ($data->accesses as $access) { |
788
|
|
|
$accessType = $access->type; |
789
|
|
|
// get all params |
790
|
|
|
$params = get_object_vars($access); |
791
|
|
|
// remove type |
792
|
|
|
unset($params["type"]); |
793
|
|
|
// set all accesses information's |
794
|
|
|
$accesses[$accessType][] = $params; |
795
|
|
|
} |
796
|
|
|
} |
797
|
|
|
return $accesses; |
798
|
|
|
} |
799
|
|
|
|
800
|
|
|
/** |
801
|
|
|
* Prepares the analytics array based on a data object |
802
|
|
|
* |
803
|
|
|
* @param \stdClass $data The data object |
804
|
|
|
* |
805
|
|
|
* @return array |
806
|
|
|
*/ |
807
|
|
|
public function prepareAnalytics(\stdClass $data) |
808
|
|
|
{ |
809
|
|
|
$analytics = array(); |
810
|
|
|
if (isset($data->analytics)) { |
811
|
|
|
foreach ($data->analytics as $analytic) { |
812
|
|
|
$connectors = array(); |
813
|
|
|
foreach ($analytic->connectors as $connector) { |
814
|
|
|
// get all params |
815
|
|
|
$params = get_object_vars($connector->params); |
816
|
|
|
// build up the connectors entry |
817
|
|
|
$connectors[] = array( |
818
|
|
|
'name' => $connector->name, |
819
|
|
|
'type' => $connector->type, |
820
|
|
|
'params' => $params |
821
|
|
|
); |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
// build up the analytics entry |
825
|
|
|
$analytics[] = array( |
826
|
|
|
'uri' => $analytic->uri, |
827
|
|
|
'connectors' => $connectors |
828
|
|
|
); |
829
|
|
|
} |
830
|
|
|
} |
831
|
|
|
return $analytics; |
832
|
|
|
} |
833
|
|
|
|
834
|
|
|
/** |
835
|
|
|
* Prepares the locations array based on a data object |
836
|
|
|
* |
837
|
|
|
* @param \stdClass $data The data object |
838
|
|
|
* |
839
|
|
|
* @return array |
840
|
|
|
*/ |
841
|
|
View Code Duplication |
public function prepareLocations(\stdClass $data) |
|
|
|
|
842
|
|
|
{ |
843
|
|
|
$locations = array(); |
844
|
|
|
if (isset($data->locations)) { |
845
|
|
|
// prepare the array with the location variables |
846
|
|
|
foreach ($data->locations as $location) { |
847
|
|
|
// Build up the array entry |
848
|
|
|
$locations[] = array( |
849
|
|
|
'condition' => $location->condition, |
850
|
|
|
'handlers' => $this->prepareHandlers($location) |
851
|
|
|
); |
852
|
|
|
} |
853
|
|
|
} |
854
|
|
|
return $locations; |
855
|
|
|
} |
856
|
|
|
|
857
|
|
|
/** |
858
|
|
|
* Prepares the rewrite maps array based on a data object |
859
|
|
|
* |
860
|
|
|
* @param \stdClass $data The data object |
861
|
|
|
* |
862
|
|
|
* @return array |
863
|
|
|
*/ |
864
|
|
|
public function prepareRewriteMaps(\stdClass $data) |
865
|
|
|
{ |
866
|
|
|
$rewriteMaps = array(); |
867
|
|
|
if (isset($data->rewriteMaps)) { |
868
|
|
|
// prepare the array with the rewrite maps variables |
869
|
|
|
foreach ($data->rewriteMaps as $rewriteMap) { |
870
|
|
|
// Build up the array entry |
871
|
|
|
$rewriteMaps[$rewriteMap->type] = array( |
872
|
|
|
'params' => (array)$rewriteMap->params |
873
|
|
|
); |
874
|
|
|
} |
875
|
|
|
} |
876
|
|
|
return $rewriteMaps; |
877
|
|
|
} |
878
|
|
|
} |
879
|
|
|
|
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.