ServerXmlConfiguration   F
last analyzed

Complexity

Total Complexity 109

Size/Duplication

Total Lines 1258
Duplicated Lines 7.63 %

Coupling/Cohesion

Components 8
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 109
lcom 8
cbo 2
dl 96
loc 1258
ccs 0
cts 470
cp 0
rs 0.5217
c 0
b 0
f 0

67 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 50 3
C prepareHeaders() 0 29 7
A prepareModules() 0 10 3
A prepareConnectionHandlers() 0 11 3
B prepareHandlers() 14 21 5
B prepareVirtualHosts() 14 30 5
A prepareRewriteMaps() 17 17 4
A prepareRewrites() 0 12 3
A prepareCertificates() 0 15 3
A prepareLocations() 0 16 3
A prepareEnvironmentVariables() 0 12 3
A prepareAuthentications() 16 16 4
A prepareAccesses() 17 17 4
B prepareAnalytics() 18 34 6
A getName() 0 4 1
A getType() 0 4 1
A getLoggerName() 0 4 1
A getTransport() 0 4 1
A getRewrites() 0 4 1
A getAddress() 0 4 1
A getPort() 0 4 1
A getFlags() 0 4 1
A getSoftware() 0 4 1
A getAdmin() 0 4 1
A getAnalytics() 0 4 1
A getKeepAliveMax() 0 4 1
A getKeepAliveTimeout() 0 4 1
A getErrorsPageTemplatePath() 0 4 1
A getWelcomePageTemplatePath() 0 4 1
A getAutoIndexTemplatePath() 0 4 1
A getWorkerNumber() 0 4 1
A getWorkerAcceptMin() 0 4 1
A getWorkerAcceptMax() 0 4 1
A getAutoIndex() 0 4 1
A getServerContextType() 0 4 1
A getStreamContextType() 0 4 1
A getRequestContextType() 0 4 1
A getSocketType() 0 4 1
A getWorkerType() 0 4 1
A getDocumentRoot() 0 4 1
A getDirectoryIndex() 0 4 1
A getConnectionHandlers() 0 4 1
A getHeaders() 0 4 1
A getCertificates() 0 4 1
A getVirtualHosts() 0 4 1
A getAuthentications() 0 4 1
A getModules() 0 4 1
A getHandlers() 0 4 1
A getCertPath() 0 4 1
A getPassphrase() 0 4 1
A getEnvironmentVariables() 0 4 1
A getAccesses() 0 4 1
A getLocations() 0 4 1
A getRewriteMaps() 0 4 1
A getDhParamPath() 0 4 1
A getPrivateKeyPath() 0 4 1
A getCryptoMethod() 0 4 1
A getPeerName() 0 4 1
A getVerifyPeer() 0 4 1
A getVerifyPeerName() 0 4 1
A getDisableCompression() 0 4 1
A getAllowSelfSigned() 0 4 1
A getHonorCipherOrder() 0 4 1
A getEcdhCurve() 0 4 1
A getSingleEcdhUse() 0 4 1
A getSingleDhUse() 0 4 1
A getCiphers() 0 4 1

How to fix   Duplicated Code    Complexity   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

Complex Class

 Tip:   Before tackling complexity, make sure that you eliminate any duplication first. This often can reduce the size of classes significantly.

Complex classes like ServerXmlConfiguration often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use ServerXmlConfiguration, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
/**
4
 * \AppserverIo\Server\Configuration\ServerXmlConfiguration
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\Utils\ServerUtil;
24
use AppserverIo\Server\Interfaces\ServerConfigurationInterface;
25
26
/**
27
 * Server configuration that handles XML files.
28
 *
29
 * @author    Johann Zelger <[email protected]>
30
 * @copyright 2015 TechDivision GmbH <[email protected]>
31
 * @license   http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
32
 * @link      https://github.com/appserver-io/server
33
 * @link      http://www.appserver.io
34
 */
35
class ServerXmlConfiguration implements ServerConfigurationInterface
36
{
37
38
    /**
39
     * The configured rewrite rules
40
     *
41
     * @var array
42
     */
43
    protected $rewrites = array();
44
45
    /**
46
     * The configured locations.
47
     *
48
     * @var array
49
     */
50
    protected $locations = array();
51
52
    /**
53
     * The configured headers
54
     *
55
     * @var array
56
     */
57
    protected $headers = array();
58
59
    /**
60
     * Holds the environmentVariables array
61
     *
62
     * @var array
63
     */
64
    protected $environmentVariables = array();
65
66
    /**
67
     * The server name for internal purposes.
68
     *
69
     * @var string
70
     */
71
    protected $name = 'httpsServer';
72
73
    /**
74
     * The server class name.
75
     *
76
     * @var string
77
     */
78
    protected $type = '\\AppserverIo\\Server\\Servers\\MultiThreadedServer';
79
80
    /**
81
     * The worker class name.
82
     *
83
     * @var string
84
     */
85
    protected $workerType = '\\AppserverIo\\Server\\Workers\\ThreadWorker';
86
87
    /**
88
     * The socket class name.
89
     *
90
     * @var string
91
     */
92
    protected $socketType = '\\AppserverIo\\Server\\Sockets\\StreamSocket';
93
94
    /**
95
     * The stream context class name.
96
     *
97
     * @var string
98
     */
99
    protected $streamContextType = '\\AppserverIo\\Server\\Contexts\\StreamContext';
100
101
    /**
102
     * The server context class name.
103
     *
104
     * @var string
105
     */
106
    protected $serverContextType = '\\AppserverIo\\Server\\Contexts\\ServerContext';
107
108
    /**
109
     * The request context class name.
110
     *
111
     * @var string
112
     */
113
    protected $requestContextType = '\\AppserverIo\\Server\\Contexts\\RequestContext';
114
115
    /**
116
     * The logger name for internal purposes.
117
     *
118
     * @var string
119
     */
120
    protected $loggerName = 'System';
121
122
    /**
123
     * The server admin's email addres.
124
     *
125
     * @var string
126
     */
127
    protected $admin = '[email protected]';
128
129
    /**
130
     * The server software name.
131
     *
132
     * @var string
133
     */
134
    protected $software = 'phpWebServer/7.0.0';
135
136
    /**
137
     * The number of workers to start.
138
     *
139
     * @var integer
140
     */
141
    protected $workerNumber = 64;
142
143
    /**
144
     * The minimum number of requests a worker handles.
145
     *
146
     * @var integer
147
     */
148
    protected $workerAcceptMin = 16;
149
150
    /**
151
     * The maximum number of requests a worker handles.
152
     *
153
     * @var integer
154
     */
155
    protected $workerAcceptMax = 64;
156
157
    /**
158
     * The transport protocol to use.
159
     *
160
     * @var string
161
     */
162
    protected $transport = 'tcp';
163
164
    /**
165
     * The IP address to use.
166
     *
167
     * @var string
168
     */
169
    protected $address = '0.0.0.0';
170
171
    /**
172
     * The port to use.
173
     *
174
     * @var string
175
     */
176
    protected $port = 9080;
177
178
    /**
179
     * Socket flags used for socket initialization.
180
     *
181
     * @var string
182
     */
183
    protected $flags = null;
184
185
    /**
186
     * The server's document root.
187
     *
188
     * @var string
189
     */
190
    protected $documentRoot = 'var/www';
191
192
    /**
193
     * Directory index files to be used.
194
     *
195
     * @var string
196
     */
197
    protected $directoryIndex = 'index.php index.html index.htm';
198
199
    /**
200
     * The maximum requests to be handled for a keep alive connection.
201
     *
202
     * @var integer
203
     */
204
    protected $keepAliveMax = 64;
205
206
    /**
207
     * The timeout for the keep alive connection.
208
     *
209
     * @var integer
210
     */
211
    protected $keepAliveTimeout = 5;
212
213
    /**
214
     * Flag to enable/disable auto index functionality.
215
     *
216
     * @var boolean
217
     */
218
    protected $autoIndex = false;
219
220
    /**
221
     * The path to the error page template.
222
     *
223
     * @var string
224
     */
225
    protected $errorsPageTemplatePath = 'resources/templates/www/error.phtml';
226
227
    /**
228
     * The path to the welcome page template.
229
     *
230
     * @var string
231
     */
232
    protected $welcomePageTemplatePath = 'resources/templates/www/welcome.phtml';
233
234
    /**
235
     * The path to the auto index template.
236
     *
237
     * @var string
238
     */
239
    protected $autoIndexTemplatePath = 'resources/templates/www/auto_index.phtml';
240
241
    /**
242
     * The file handlers.
243
     *
244
     * @var array
245
     */
246
    protected $handlers = array();
247
248
    /**
249
     * The rewrite maps.
250
     *
251
     * @var array
252
     */
253
    protected $rewriteMaps = array();
254
255
    /**
256
     * The path to the SSL certificate.
257
     *
258
     * @var string
259
     */
260
    protected $certPath = 'etc/webserver.pem';
261
262
    /**
263
     * The path to the SSL certificate's private key file.
264
     *
265
     * @var string
266
     */
267
    protected $privateKeyPath = null;
268
269
    /**
270
     * The path to the Diffie Hellmann param file.
271
     *
272
     * @var string
273
     */
274
    protected $dhParamPath = null;
275
276
    /**
277
     * The SSL certificate's passphrase.
278
     *
279
     * @var string
280
     */
281
    protected $passphrase = null;
282
283
    /**
284
     * The crypto method(s) to use.
285
     *
286
     * @var string
287
     */
288
    protected $cryptoMethod = 'STREAM_CRYPTO_METHOD_TLS_SERVER';
289
290
    /**
291
     * The peer name.
292
     *
293
     * @var string
294
     */
295
    protected $peerName = null;
296
297
    /**
298
     * Flag to enable/disable peer verification.
299
     *
300
     * @var boolean
301
     */
302
    protected $verifyPeer = false;
303
304
    /**
305
     * The flag to enable/disable peer name verification.
306
     *
307
     * @var boolean
308
     */
309
    protected $verifyPeerName = false;
310
311
    /**
312
     * Flag to allow/disallow self signed SSL certificates.
313
     *
314
     * @var boolean
315
     */
316
    protected $allowSelfSigned = true;
317
318
    /**
319
     * The flag to disable TLS compression. This can help mitigate the CRIME attack vector.
320
     *
321
     * @var boolean
322
     */
323
    protected $disableCompression = true;
324
325
    /**
326
     * The flag to control cipher ordering preferences during negotiation has to be allowed.
327
     *
328
     * @var boolean
329
     */
330
    protected $honorCipherOrder = true;
331
332
    /**
333
     * The curve to use with ECDH ciphers, if not specified prime256v1 will be used.
334
     *
335
     * @var string
336
     */
337
    protected $ecdhCurve = 'prime256v1';
338
339
    /**
340
     * The flag to enable/disable new key pair has to be created in scenarios where ECDH cipher suites are negotiated (instead of the preferred ECDHE ciphers).
341
     * @var boolean
342
     */
343
    protected $singleEcdhUse = true;
344
345
    /**
346
     * The flag to enable/disable new key pair creation when using DH parameters (improves forward secrecy).
347
     *
348
     * @var boolean
349
     */
350
    protected $singleDhUse = true;
351
352
    /**
353
     * The list of available ciphers.
354
     *
355
     * @var string
356
     * @link http://php.net/manual/en/context.ssl.php#context.ssl.ciphers
357
     * @link https://www.openssl.org/docs/manmaster/apps/ciphers.html#CIPHER_LIST_FORMAT
358
     */
359
    protected $ciphers = 'ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-AES256-GCM-SHA384:DHE-RSA-AES128-GCM-SHA256:DHE-DSS-AES128-GCM-SHA256:kEDH+AESGCM:ECDHE-RSA-AES128-SHA256:ECDHE-ECDSA-AES128-SHA256:ECDHE-RSA-AES128-SHA:ECDHE-ECDSA-AES128-SHA:ECDHE-RSA-AES256-SHA384:ECDHE-ECDSA-AES256-SHA384:ECDHE-RSA-AES256-SHA:ECDHE-ECDSA-AES256-SHA:DHE-RSA-AES128-SHA256:DHE-RSA-AES128-SHA:DHE-DSS-AES128-SHA256:DHE-RSA-AES256-SHA256:DHE-DSS-AES256-SHA:DHE-RSA-AES256-SHA:AES128-GCM-SHA256:AES256-GCM-SHA384:ECDHE-RSA-RC4-SHA:ECDHE-ECDSA-RC4-SHA:AES128:AES256:RC4-SHA:HIGH:!aNULL:!eNULL:!EXPORT:!DES:!3DES:!MD5:!PSK';
360
361
    /**
362
     * Constructs config
363
     *
364
     * @param \SimpleXMLElement $node The simple xml element used to build config
365
     */
366
    public function __construct($node)
367
    {
368
369
        // load the object properties
370
        $properties = get_object_vars($this);
371
372
        // prepare properties
373
        $this->name = (string) $node->attributes()->name;
374
        $this->type = (string) $node->attributes()->type;
375
        $this->workerType = (string) $node->attributes()->worker;
376
        $this->socketType = (string) $node->attributes()->socket;
377
        $this->streamContextType = (string) $node->attributes()->streamContext;
378
        $this->serverContextType = (string) $node->attributes()->serverContext;
379
        $this->requestContextType = (string) $node->attributes()->requestContext;
380
        $this->loggerName = (string) $node->attributes()->loggerName;
381
382
        // extract the properties from the params
383
        foreach ($node->xpath('./params/param') as $param) {
384
            if (array_key_exists($propertyName = (string) $param->attributes()->name, $properties)) {
385
                $this->{$propertyName} = ServerUtil::singleton()->castToType($param->attributes()->type, (string) $param);
386
            }
387
        }
388
389
        // prepare analytics
390
        $this->analytics = $this->prepareAnalytics($node);
0 ignored issues
show
Bug introduced by
The property analytics does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
391
        // prepare modules
392
        $this->headers = $this->prepareHeaders($node);
393
        // prepare modules
394
        $this->modules = $this->prepareModules($node);
0 ignored issues
show
Bug introduced by
The property modules does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
395
        // prepare connection handlers
396
        $this->connectionHandlers = $this->prepareConnectionHandlers($node);
0 ignored issues
show
Bug introduced by
The property connectionHandlers does not seem to exist. Did you mean handlers?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
397
        // prepare handlers
398
        $this->handlers = $this->prepareHandlers($node);
399
        // prepare virutalHosts
400
        $this->virtualHosts = $this->prepareVirtualHosts($node);
0 ignored issues
show
Bug introduced by
The property virtualHosts does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
401
        // prepare rewrites
402
        $this->rewrites = $this->prepareRewrites($node);
403
        // prepare environmentVariables
404
        $this->environmentVariables = $this->prepareEnvironmentVariables($node);
405
        // prepare authentications
406
        $this->authentications = $this->prepareAuthentications($node);
0 ignored issues
show
Bug introduced by
The property authentications does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
407
        // prepare accesses
408
        $this->accesses = $this->prepareAccesses($node);
0 ignored issues
show
Bug introduced by
The property accesses does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
409
        // prepare locations
410
        $this->locations = $this->prepareLocations($node);
411
        // prepare rewrite maps
412
        $this->rewriteMaps = $this->prepareRewriteMaps($node);
413
        // prepare certificates
414
        $this->certificates = $this->prepareCertificates($node);
0 ignored issues
show
Bug introduced by
The property certificates does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
415
    }
416
417
    /**
418
     * Prepares the headers array based on a simple xml element node
419
     *
420
     * @param \SimpleXMLElement $node The xml node
421
     *
422
     * @return array
423
     */
424
    public function prepareHeaders(\SimpleXMLElement $node)
425
    {
426
        $headers = array();
427
        if ($node->headers) {
428
            foreach ($node->headers->header as $headerNode) {
429
                // Cut of the SimpleXML attributes wrapper and attach it to our headers
430
                $override = false;
431
                $overrideAttribute = strtolower((string)$headerNode->attributes()->override);
432
                if ($overrideAttribute && $overrideAttribute === 'true') {
433
                    $override = true;
434
                }
435
                $append = false;
436
                $appendAttribute = strtolower((string)$headerNode->attributes()->append);
437
                if ($appendAttribute && $appendAttribute === 'true') {
438
                    $append = true;
439
                }
440
                $header = array(
441
                    'type' => (string) $headerNode->attributes()->type,
442
                    'name' => (string) $headerNode->attributes()->name,
443
                    'value' => (string) $headerNode->attributes()->value,
444
                    'uri' => (string) $headerNode->attributes()->uri,
445
                    'override' => $override,
446
                    'append' => $append
447
                );
448
                $headers[(string) $headerNode->attributes()->type][] = $header;
449
            }
450
        }
451
        return $headers;
452
    }
453
454
    /**
455
     * Prepares the modules array based on a simple xml element node
456
     *
457
     * @param \SimpleXMLElement $node The xml node
458
     *
459
     * @return array
460
     */
461
    public function prepareModules(\SimpleXMLElement $node)
462
    {
463
        $modules = array();
464
        if ($node->modules) {
465
            foreach ($node->modules->module as $moduleNode) {
466
                $modules[] = new ModuleXmlConfiguration($moduleNode);
467
            }
468
        }
469
        return $modules;
470
    }
471
472
    /**
473
     * Prepares the connectionHandlers array based on a simple xml element node
474
     *
475
     * @param \SimpleXMLElement $node The xml node
476
     *
477
     * @return array
478
     */
479
    public function prepareConnectionHandlers(\SimpleXMLElement $node)
480
    {
481
        $connectionHandlers = array();
482
        if ($node->connectionHandlers) {
483
            foreach ($node->connectionHandlers->connectionHandler as $connectionHandlerNode) {
484
                $connectionHandlerType = (string) $connectionHandlerNode->attributes()->type;
485
                $connectionHandlers[] = $connectionHandlerType;
486
            }
487
        }
488
        return $connectionHandlers;
489
    }
490
491
    /**
492
     * Prepares the handlers array based on a simple xml element node
493
     *
494
     * @param \SimpleXMLElement $node The xml node
495
     *
496
     * @return array
497
     */
498
    public function prepareHandlers(\SimpleXMLElement $node)
499
    {
500
        $handlers = array();
501
        if ($node->handlers) {
502 View Code Duplication
            foreach ($node->handlers->handler as $handlerNode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
503
                $params = array();
504
                if ($handlerNode->params->param) {
505
                    foreach ($handlerNode->params->param as $paramNode) {
506
                        $paramName = (string)$paramNode->attributes()->name;
507
                        $paramNodes = $handlerNode->xpath(".//param[@name='$paramName']");
508
                        $params[$paramName] = (string) array_shift($paramNodes);
509
                    }
510
                }
511
                $handlers[(string)$handlerNode->attributes()->extension] = array(
512
                    'name' => (string) $handlerNode->attributes()->name,
513
                    'params' => $params
514
                );
515
            }
516
        }
517
        return $handlers;
518
    }
519
520
    /**
521
     * Prepares the virtual hosts array based on a simple xml element node
522
     *
523
     * @param \SimpleXMLElement $node The xml node
524
     *
525
     * @return array
526
     */
527
    public function prepareVirtualHosts(\SimpleXMLElement $node)
528
    {
529
        $virutalHosts = array();
530
        if ($node->virtualHosts) {
531
            foreach ($node->virtualHosts->virtualHost as $virtualHostNode) {
532
                $virtualHostNames = explode(' ', (string)$virtualHostNode->attributes()->name);
533
                $params = array();
534
                foreach ($virtualHostNode->params->param as $paramNode) {
535
                    $paramName = (string) $paramNode->attributes()->name;
536
                    $paramNodes = $virtualHostNode->xpath(".//param[@name='$paramName']");
537
                    $params[$paramName] = (string) array_shift($paramNodes);
538
                }
539 View Code Duplication
                foreach ($virtualHostNames as $virtualHostName) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
540
                    // set all virtual hosts params per key for faster matching later on
541
                    $virutalHosts[trim($virtualHostName)] = array(
542
                        'params' => $params,
543
                        'headers' => $this->prepareHeaders($virtualHostNode),
544
                        'rewriteMaps' => $this->prepareRewriteMaps($virtualHostNode),
545
                        'rewrites' => $this->prepareRewrites($virtualHostNode),
546
                        'locations' => $this->prepareLocations($virtualHostNode),
547
                        'environmentVariables' => $this->prepareEnvironmentVariables($virtualHostNode),
548
                        'authentications' => $this->prepareAuthentications($virtualHostNode),
549
                        'accesses' => $this->prepareAccesses($virtualHostNode),
550
                        'analytics' => $this->prepareAnalytics($virtualHostNode)
551
                    );
552
                }
553
            }
554
        }
555
        return $virutalHosts;
556
    }
557
558
    /**
559
     * Prepares the rewrite maps based on a simple xml element node
560
     *
561
     * @param \SimpleXMLElement $node The xml node
562
     *
563
     * @return array
564
     */
565 View Code Duplication
    public function prepareRewriteMaps(\SimpleXMLElement $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
566
    {
567
        $rewriteMaps = array();
568
        if ($node->rewriteMaps) {
569
            foreach ($node->rewriteMaps->rewriteMap as $rewriteMapNode) {
570
                $rewriteMapType = (string)$rewriteMapNode->attributes()->type;
571
                $params = array();
572
                foreach ($rewriteMapNode->params->param as $paramNode) {
573
                    $paramName = (string) $paramNode->attributes()->name;
574
                    $paramNodes = $rewriteMapNode->xpath(".//param[@name='$paramName']");
575
                    $params[$paramName] = (string) array_shift($paramNodes);
576
                }
577
                $rewriteMaps[$rewriteMapType] = $params;
578
            }
579
        }
580
        return $rewriteMaps;
581
    }
582
583
    /**
584
     * Prepares the rewrites array based on a simple xml element node
585
     *
586
     * @param \SimpleXMLElement $node The xml node
587
     *
588
     * @return array
589
     */
590
    public function prepareRewrites(\SimpleXMLElement $node)
591
    {
592
        $rewrites = array();
593
        if ($node->rewrites) {
594
            foreach ($node->rewrites->rewrite as $rewriteNode) {
595
                // cut of the SimpleXML attributes wrapper and attach it to our rewrites
596
                $rewrite = (array)$rewriteNode;
597
                $rewrites[] = array_shift($rewrite);
598
            }
599
        }
600
        return $rewrites;
601
    }
602
603
    /**
604
     * Prepares the certificates array based on a simple xml element node
605
     *
606
     * @param \SimpleXMLElement $node The xml node
607
     *
608
     * @return array
609
     */
610
    public function prepareCertificates(\SimpleXMLElement $node)
611
    {
612
        $certificates = array();
613
        if ($node->certificates) {
614
            foreach ($node->certificates->certificate as $certificateNode) {
615
                // Cut of the SimpleXML attributes wrapper and attach it to our locations
616
                $certificate = array(
617
                    'domain' => (string) $certificateNode->attributes()->domain,
618
                    'certPath' => (string) $certificateNode->attributes()->certPath
619
                );
620
                $certificates[] = $certificate;
621
            }
622
        }
623
        return $certificates;
624
    }
625
626
    /**
627
     * Prepares the locations array based on a simple xml element node
628
     *
629
     * @param \SimpleXMLElement $node The xml node
630
     *
631
     * @return array
632
     */
633
    public function prepareLocations(\SimpleXMLElement $node)
634
    {
635
        $locations = array();
636
        if ($node->locations) {
637
            foreach ($node->locations->location as $locationNode) {
638
                // Cut of the SimpleXML attributes wrapper and attach it to our locations
639
                $location = array(
640
                    'condition' => (string) $locationNode->attributes()->condition,
641
                    'handlers' => $this->prepareHandlers($locationNode),
642
                    'headers' => $this->prepareHeaders($locationNode),
643
                );
644
                $locations[] = $location;
645
            }
646
        }
647
        return $locations;
648
    }
649
650
    /**
651
     * Prepares the environmentVariables array based on a simple xml element node
652
     *
653
     * @param \SimpleXMLElement $node The xml node
654
     *
655
     * @return array
656
     */
657
    public function prepareEnvironmentVariables(\SimpleXMLElement $node)
658
    {
659
        $environmentVariables = array();
660
        if ($node->environmentVariables) {
661
            foreach ($node->environmentVariables->environmentVariable as $environmentVariableNode) {
662
                // cut of the SimpleXML attributes wrapper and attach it to our environment variable
663
                $environmentVariable = (array) $environmentVariableNode;
664
                $environmentVariables[] = array_shift($environmentVariable);
665
            }
666
        }
667
        return $environmentVariables;
668
    }
669
670
    /**
671
     * Prepares the authentications array based on a simple xml element node
672
     *
673
     * @param \SimpleXMLElement $node The xml node
674
     *
675
     * @return array
676
     */
677 View Code Duplication
    public function prepareAuthentications(\SimpleXMLElement $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
678
    {
679
        $authentications = array();
680
        if ($node->authentications) {
681
            foreach ($node->authentications->authentication as $authenticationNode) {
682
                $params = array();
683
                foreach ($authenticationNode->params->param as $paramNode) {
684
                    $paramName = (string) $paramNode->attributes()->name;
685
                    $paramNodes = $authenticationNode->xpath(".//param[@name='$paramName']");
686
                    $params[$paramName] = (string) array_shift($paramNodes);
687
                }
688
                $authentications[(string)$authenticationNode->attributes()->uri] = $params;
689
            }
690
        }
691
        return $authentications;
692
    }
693
694
    /**
695
     * Prepares the access array based on a simple xml element node
696
     *
697
     * @param \SimpleXMLElement $node The xml node
698
     *
699
     * @return array
700
     */
701 View Code Duplication
    public function prepareAccesses(\SimpleXMLElement $node)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
702
    {
703
        // init accesses
704
        $accesses = array();
705
        if ($node->accesses) {
706
            foreach ($node->accesses->access as $accessNode) {
707
                $params = array();
708
                foreach ($accessNode->params->param as $paramNode) {
709
                    $paramName = (string)$paramNode->attributes()->name;
710
                    $paramNodes = $accessNode->xpath(".//param[@name='$paramName']");
711
                    $params[$paramName] = (string) array_shift($paramNodes);
712
                }
713
                $accesses[(string) $accessNode->attributes()->type][] = $params;
714
            }
715
        }
716
        return $accesses;
717
    }
718
719
    /**
720
     * Prepares the analytics array based on a simple XML element node
721
     *
722
     * @param \SimpleXMLElement $node The XML node
723
     *
724
     * @return array
725
     */
726
    public function prepareAnalytics(\SimpleXMLElement $node)
727
    {
728
        $analytics = array();
729
        if ($node->analytics) {
730
            foreach ($node->analytics->analytic as $analyticNode) {
731
                $connectors = array();
732 View Code Duplication
                foreach ($analyticNode->connectors->connector as $connectorNode) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
733
                    // connectors might have params
734
                    $params = array();
735
                    if ($connectorNode->params) {
736
                        foreach ($connectorNode->params->param as $paramNode) {
737
                            $paramName = (string) $paramNode->attributes()->name;
738
                            $paramNodes = $connectorNode->xpath(".//param[@name='$paramName']");
739
                            $params[$paramName] = (string) array_shift($paramNodes);
740
                        }
741
                    }
742
743
                    // build up the connectors entry
744
                    $connectors[] = array(
745
                        'name' => (string)$connectorNode->attributes()->name,
746
                        'type' => (string)$connectorNode->attributes()->type,
747
                        'params' => $params
748
                    );
749
                }
750
751
                // build up the analytics entry
752
                $analytics[] = array(
753
                    'uri' => (string)$analyticNode->attributes()->uri,
754
                    'connectors' => $connectors
755
                );
756
            }
757
        }
758
        return $analytics;
759
    }
760
761
    /**
762
     * Return's name
763
     *
764
     * @return string
765
     */
766
    public function getName()
767
    {
768
        return $this->name;
769
    }
770
771
    /**
772
     * Return's type
773
     *
774
     * @return string
775
     */
776
    public function getType()
777
    {
778
        return $this->type;
779
    }
780
781
    /**
782
     * Return's logger name
783
     *
784
     * @return string
785
     */
786
    public function getLoggerName()
787
    {
788
        return $this->loggerName;
789
    }
790
791
    /**
792
     * Return's transport
793
     *
794
     * @return string
795
     */
796
    public function getTransport()
797
    {
798
        return $this->transport;
799
    }
800
801
    /**
802
     * Returns rewrites
803
     *
804
     * @return array
805
     */
806
    public function getRewrites()
807
    {
808
        return $this->rewrites;
809
    }
810
811
    /**
812
     * Return's address
813
     *
814
     * @return string
815
     */
816
    public function getAddress()
817
    {
818
        return $this->address;
819
    }
820
821
    /**
822
     * Return's port
823
     *
824
     * @return int
825
     */
826
    public function getPort()
827
    {
828
        return (int)$this->port;
829
    }
830
831
    /**
832
     * Return's flags
833
     *
834
     * @return string
835
     */
836
    public function getFlags()
837
    {
838
        return $this->flags;
839
    }
840
841
    /**
842
     * Return's software
843
     *
844
     * @return string
845
     */
846
    public function getSoftware()
847
    {
848
        return $this->software;
849
    }
850
851
    /**
852
     * Return's admin
853
     *
854
     * @return string
855
     */
856
    public function getAdmin()
857
    {
858
        return $this->admin;
859
    }
860
861
    /**
862
     * Return's analytics
863
     *
864
     * @return string
865
     */
866
    public function getAnalytics()
867
    {
868
        return $this->analytics;
869
    }
870
871
    /**
872
     * Return's keep-alive max connection
873
     *
874
     * @return int
875
     */
876
    public function getKeepAliveMax()
877
    {
878
        return (int)$this->keepAliveMax;
879
    }
880
881
    /**
882
     * Return's keep-alive timeout
883
     *
884
     * @return int
885
     */
886
    public function getKeepAliveTimeout()
887
    {
888
        return (int)$this->keepAliveTimeout;
889
    }
890
891
    /**
892
     * Return's template path for errors page
893
     *
894
     * @return string
895
     */
896
    public function getErrorsPageTemplatePath()
897
    {
898
        return $this->errorsPageTemplatePath;
899
    }
900
901
    /**
902
     * Returns template path for possible configured welcome page
903
     *
904
     * @return string
905
     */
906
    public function getWelcomePageTemplatePath()
907
    {
908
        return $this->welcomePageTemplatePath;
909
    }
910
911
    /**
912
     * Returns template path for possible configured auto index page
913
     *
914
     * @return string
915
     */
916
    public function getAutoIndexTemplatePath()
917
    {
918
        return $this->autoIndexTemplatePath;
919
    }
920
921
    /**
922
     * Return's worker number
923
     *
924
     * @return int
925
     */
926
    public function getWorkerNumber()
927
    {
928
        return (int)$this->workerNumber;
929
    }
930
931
    /**
932
     * Return's worker's accept min count
933
     *
934
     * @return int
935
     */
936
    public function getWorkerAcceptMin()
937
    {
938
        return (int)$this->workerAcceptMin;
939
    }
940
941
    /**
942
     * Return's worker's accept max count
943
     *
944
     * @return int
945
     */
946
    public function getWorkerAcceptMax()
947
    {
948
        return (int)$this->workerAcceptMax;
949
    }
950
951
    /**
952
     * Return's the auto index configuration
953
     *
954
     * @return boolean
955
     */
956
    public function getAutoIndex()
957
    {
958
        return (boolean)$this->autoIndex;
959
    }
960
961
    /**
962
     * Return's server context type
963
     *
964
     * @return string
965
     */
966
    public function getServerContextType()
967
    {
968
        return $this->serverContextType;
969
    }
970
971
    /**
972
     * Returns stream context type
973
     *
974
     * @return string
975
     */
976
    public function getStreamContextType()
977
    {
978
        return $this->streamContextType;
979
    }
980
981
    /**
982
     * Return's server context type
983
     *
984
     * @return string
985
     */
986
    public function getRequestContextType()
987
    {
988
        return $this->requestContextType;
989
    }
990
991
    /**
992
     * Return's socket type
993
     *
994
     * @return string
995
     */
996
    public function getSocketType()
997
    {
998
        return $this->socketType;
999
    }
1000
1001
    /**
1002
     * Return's worker type
1003
     *
1004
     * @return string
1005
     */
1006
    public function getWorkerType()
1007
    {
1008
        return $this->workerType;
1009
    }
1010
1011
    /**
1012
     * Return's document root
1013
     *
1014
     * @return string
1015
     */
1016
    public function getDocumentRoot()
1017
    {
1018
        return $this->documentRoot;
1019
    }
1020
1021
    /**
1022
     * Return's directory index definition
1023
     *
1024
     * @return string
1025
     */
1026
    public function getDirectoryIndex()
1027
    {
1028
        return $this->directoryIndex;
1029
    }
1030
1031
    /**
1032
     * Return's the connection handlers
1033
     *
1034
     * @return array
1035
     */
1036
    public function getConnectionHandlers()
1037
    {
1038
        return $this->connectionHandlers;
0 ignored issues
show
Bug introduced by
The property connectionHandlers does not seem to exist. Did you mean handlers?

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
1039
    }
1040
1041
    /**
1042
     * Returns the headers used by the server
1043
     *
1044
     * @return array
1045
     */
1046
    public function getHeaders()
1047
    {
1048
        return $this->headers;
1049
    }
1050
1051
    /**
1052
     * Returns the certificates used by the server
1053
     *
1054
     * @return array
1055
     */
1056
    public function getCertificates()
1057
    {
1058
        return $this->certificates;
1059
    }
1060
1061
    /**
1062
     * Return's the virtual hosts
1063
     *
1064
     * @return array
1065
     */
1066
    public function getVirtualHosts()
1067
    {
1068
        return $this->virtualHosts;
1069
    }
1070
1071
    /**
1072
     * Return's the authentication information's
1073
     *
1074
     * @return array
1075
     */
1076
    public function getAuthentications()
1077
    {
1078
        return $this->authentications;
1079
    }
1080
1081
    /**
1082
     * Return's modules
1083
     *
1084
     * @return array
1085
     */
1086
    public function getModules()
1087
    {
1088
        return $this->modules;
1089
    }
1090
1091
    /**
1092
     * Return's array
1093
     *
1094
     * @return array
1095
     */
1096
    public function getHandlers()
1097
    {
1098
        return $this->handlers;
1099
    }
1100
1101
    /**
1102
     * Return's cert path
1103
     *
1104
     * @return string
1105
     */
1106
    public function getCertPath()
1107
    {
1108
        return $this->certPath;
1109
    }
1110
1111
    /**
1112
     * Return's passphrase
1113
     *
1114
     * @return string
1115
     */
1116
    public function getPassphrase()
1117
    {
1118
        return $this->passphrase;
1119
    }
1120
1121
    /**
1122
     * Returns the environment variable configuration
1123
     *
1124
     * @return array
1125
     */
1126
    public function getEnvironmentVariables()
1127
    {
1128
        return $this->environmentVariables;
1129
    }
1130
1131
    /**
1132
     * Returns the access configuration.
1133
     *
1134
     * @return array
1135
     */
1136
    public function getAccesses()
1137
    {
1138
        return $this->accesses;
1139
    }
1140
1141
    /**
1142
     * Returns the locations.
1143
     *
1144
     * @return array
1145
     */
1146
    public function getLocations()
1147
    {
1148
        return $this->locations;
1149
    }
1150
1151
    /**
1152
     * Returns the rewrite maps.
1153
     *
1154
     * @return array
1155
     */
1156
    public function getRewriteMaps()
1157
    {
1158
        return $this->rewriteMaps;
1159
    }
1160
1161
    /**
1162
     * Return's DH param path
1163
     *
1164
     * @return string
1165
     */
1166
    public function getDhParamPath()
1167
    {
1168
        return $this->dhParamPath;
1169
    }
1170
1171
    /**
1172
     * Return's private key path
1173
     *
1174
     * @return string
1175
     */
1176
    public function getPrivateKeyPath()
1177
    {
1178
        return $this->privateKeyPath;
1179
    }
1180
1181
    /**
1182
     * Return's the crypto method to use
1183
     *
1184
     * @return string
1185
     */
1186
    public function getCryptoMethod()
1187
    {
1188
        return $this->cryptoMethod;
1189
    }
1190
1191
    /**
1192
     * Return's the peer name to be used, if this value is not set, then the name is guessed based on the hostname used when opening the stream
1193
     *
1194
     * @return string
1195
     */
1196
    public function getPeerName()
1197
    {
1198
        return $this->peerName;
1199
    }
1200
1201
    /**
1202
     * Return's TRUE it the verification of use SSL certificate has to be required
1203
     *
1204
     * @return boolean
1205
     */
1206
    public function getVerifyPeer()
1207
    {
1208
        return $this->verifyPeer;
1209
    }
1210
1211
    /**
1212
     * Return's TRUE it the peer name has to be verified
1213
     *
1214
     * @return boolean
1215
     */
1216
    public function getVerifyPeerName()
1217
    {
1218
        return $this->verifyPeerName;
1219
    }
1220
1221
    /**
1222
     * Return's TRUE to disable TLS compression. This can help mitigate the CRIME attack vector
1223
     *
1224
     * @return boolean
1225
     */
1226
    public function getDisableCompression()
1227
    {
1228
        return $this->disableCompression;
1229
    }
1230
1231
    /**
1232
     * Return's TRUE if self-signed certificates has to be allowed, but requires verify_peer to be FALSE
1233
     *
1234
     * @return boolean
1235
     */
1236
    public function getAllowSelfSigned()
1237
    {
1238
        return $this->allowSelfSigned;
1239
    }
1240
1241
    /**
1242
     * Return's TRUE if control cipher ordering preferences during negotiation has to be allowed
1243
     *
1244
     * @return boolean
1245
     */
1246
    public function getHonorCipherOrder()
1247
    {
1248
        return $this->honorCipherOrder;
1249
    }
1250
1251
    /**
1252
     * Return's the curve to use with ECDH ciphers, if not specified prime256v1 will be used
1253
     *
1254
     * @return string
1255
     */
1256
    public function getEcdhCurve()
1257
    {
1258
        return $this->ecdhCurve;
1259
    }
1260
1261
    /**
1262
     * Return's TRUE if a new key pair has to be created in scenarios where ECDH cipher suites are negotiated (instead of the preferred ECDHE ciphers)
1263
     *
1264
     * @return boolean
1265
     */
1266
    public function getSingleEcdhUse()
1267
    {
1268
        return $this->singleEcdhUse;
1269
    }
1270
1271
    /**
1272
     * Return's TRUE if new key pair has to be created when using DH parameters (improves forward secrecy)
1273
     *
1274
     * @return boolean
1275
     */
1276
    public function getSingleDhUse()
1277
    {
1278
        return $this->singleDhUse;
1279
    }
1280
1281
    /**
1282
     * Return's the list of available ciphers.
1283
     *
1284
     * @return string
1285
     * @link http://php.net/manual/en/context.ssl.php#context.ssl.ciphers
1286
     * @link https://www.openssl.org/docs/manmaster/apps/ciphers.html#CIPHER_LIST_FORMAT
1287
     */
1288
    public function getCiphers()
1289
    {
1290
        return $this->ciphers;
1291
    }
1292
}
1293