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; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Yaml\Yaml; |
15
|
|
|
use JamesRezo\WebHelper\WebServer\NullWebServer; |
16
|
|
|
use JamesRezo\WebHelper\WebProject\NullWebProject; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* WebHelper Factory Class. |
20
|
|
|
* |
21
|
|
|
* @author James <[email protected]> |
22
|
|
|
*/ |
23
|
|
|
class Factory |
24
|
|
|
{ |
25
|
|
|
private $webservers = []; |
26
|
|
|
|
27
|
33 |
|
public function __construct() |
28
|
|
|
{ |
29
|
33 |
|
$file = ''; |
30
|
|
|
foreach ([ |
31
|
33 |
|
getenv('HOME').'/.config/webhelper/parameters.yml', |
32
|
33 |
|
__DIR__.'/../app/config/parameters.yml', |
33
|
33 |
|
] as $file) { |
34
|
33 |
|
if (is_readable($file)) { |
35
|
33 |
|
break; |
36
|
|
|
} |
37
|
33 |
|
} |
38
|
|
|
|
39
|
33 |
|
if ($file) { |
40
|
33 |
|
$yaml = new Yaml(); |
41
|
33 |
|
$config = $yaml->parse(file_get_contents($file)); |
42
|
33 |
|
$this->webservers = $config['webservers']; |
43
|
33 |
|
} |
44
|
33 |
|
} |
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* Create a WebServerInterface Object. |
48
|
|
|
* |
49
|
|
|
* @param string $name a web server software name |
50
|
|
|
* @param string $version a web server software version |
51
|
|
|
* |
52
|
|
|
* @return WebServer\WebServerInterface a WebServer Object |
53
|
|
|
*/ |
54
|
31 |
|
public function createWebServer($name, $version = '') |
55
|
|
|
{ |
56
|
31 |
|
if (in_array($name, $this->getKnownWebServers())) { |
57
|
21 |
|
$webserver = new $this->webservers[$name][0]($version); |
58
|
|
|
$webserver |
59
|
21 |
|
->setBinaries($this->webservers[$name][1]) |
60
|
21 |
|
->setDetectionParameter($this->webservers[$name][2]); |
61
|
|
|
|
62
|
21 |
|
return $webserver; |
63
|
|
|
} |
64
|
|
|
|
65
|
10 |
|
return new NullWebServer($version); |
66
|
|
|
} |
67
|
|
|
|
68
|
31 |
|
public function getKnownWebServers() |
69
|
|
|
{ |
70
|
31 |
|
return array_keys($this->webservers); |
71
|
|
|
} |
72
|
|
|
|
73
|
2 |
|
public function createWebProject($name, $version = '') |
|
|
|
|
74
|
|
|
{ |
75
|
2 |
|
$name = ''; |
|
|
|
|
76
|
|
|
|
77
|
2 |
|
return new NullWebProject($version); |
78
|
|
|
} |
79
|
|
|
} |
80
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.