1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* This file is, guess what, part of WebHelper. |
5
|
|
|
* |
6
|
|
|
* (c) James <[email protected]> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace JamesRezo\WebHelper\WebServer; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* ApacheWebServer is the webserver class for apache httpd webserver. |
16
|
|
|
*/ |
17
|
|
|
class ApacheWebServer extends WebServer |
18
|
|
|
{ |
19
|
|
|
/** |
20
|
|
|
* Constructor. |
21
|
|
|
* |
22
|
|
|
* @param string $version the semver-like version of the apache webserver |
23
|
|
|
*/ |
24
|
15 |
|
public function __construct($version = '') |
25
|
|
|
{ |
26
|
15 |
|
parent::__construct('apache', $version); |
27
|
15 |
|
} |
28
|
|
|
|
29
|
3 |
|
public function extractVersion($settings = '') |
30
|
|
|
{ |
31
|
3 |
|
return $this->match('/^Server version: Apache\/([0-9\.]+) .*/', $settings); |
32
|
|
|
} |
33
|
|
|
|
34
|
3 |
|
public function extractRootConfigurationFile($settings = '') |
35
|
|
|
{ |
36
|
3 |
|
return $this->match('/ -D SERVER_CONFIG_FILE="([^"]+)"/', $settings); |
37
|
|
|
} |
38
|
|
|
|
39
|
1 |
|
public function parseActiveConfig(array $activeConfig = array()) |
40
|
|
|
{ |
41
|
1 |
|
$parsedActiveConfig = []; |
42
|
|
|
|
43
|
1 |
|
foreach ($activeConfig as $line => $directive) { |
44
|
1 |
View Code Duplication |
if (preg_match('/^<If(Module|Define)\s+(\w+)>/i', trim($directive), $matches)) { |
|
|
|
|
45
|
|
|
$parsedActiveConfig[$line] = ['module section', $matches[2]]; |
46
|
|
|
} |
47
|
1 |
View Code Duplication |
if (preg_match('/^<(((Directory|Files|Location)(Match)?)|VirtualHost)/i', trim($directive), $matches)) { |
|
|
|
|
48
|
|
|
$parsedActiveConfig[$line] = ['scope section', $matches[2]]; |
49
|
|
|
} |
50
|
|
|
/*if (preg_match('/^Include(Optional)?\s+(.+)/i', trim($directive), $matches)) { |
|
|
|
|
51
|
|
|
$parsedActiveConfig[$line] = ['include directive', $matches[2]]; |
52
|
|
|
}*/ |
53
|
1 |
View Code Duplication |
if (preg_match('/^(\w+)\s+(.+)/i', trim($directive), $matches)) { |
|
|
|
|
54
|
|
|
$parsedActiveConfig[$line] = ['directive', [$matches[1], $matches[2]]]; |
55
|
|
|
} |
56
|
1 |
|
} |
57
|
|
|
|
58
|
1 |
|
return $parsedActiveConfig; |
59
|
|
|
} |
60
|
|
|
} |
61
|
|
|
|
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.