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\Command; |
13
|
|
|
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
use JamesRezo\WebHelper\Factory; |
18
|
|
|
use JamesRezo\WebHelper\WebServer\NullWebServer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Base WebHelper command. |
22
|
|
|
*/ |
23
|
|
|
class BaseCommand extends Command |
24
|
|
|
{ |
25
|
4 |
|
protected function getPath(InputInterface $input) |
26
|
|
|
{ |
27
|
4 |
|
$path = $input->getArgument('path'); |
28
|
|
|
|
29
|
4 |
|
if (empty($path)) { |
30
|
1 |
|
$path = explode(PATH_SEPARATOR, getenv('PATH')); |
31
|
1 |
|
} |
32
|
|
|
|
33
|
4 |
|
return $path; |
34
|
|
|
} |
35
|
|
|
|
36
|
7 |
|
protected function getWebServer(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
7 |
|
$webservername = $input->getArgument('webserver'); |
39
|
7 |
|
$version = 0; |
40
|
7 |
|
if (preg_match(',([^:]+)(:([\.\d]+))$,', $webservername, $matches)) { |
41
|
3 |
|
$version = $matches[3]; |
42
|
3 |
|
$webservername = $matches[1]; |
43
|
3 |
|
} |
44
|
|
|
|
45
|
7 |
|
$factory = new Factory(); |
46
|
|
|
|
47
|
7 |
|
$webserver = $factory->createWebServer($webservername, $version); |
48
|
7 |
|
if ($webserver instanceof NullWebServer) { |
49
|
2 |
|
$output->writeln('<error>Web Server "'.$webservername.'" unknown.</error>'); |
50
|
2 |
|
$output->writeln( |
51
|
|
|
'<comment>Known Web Servers are '. |
52
|
2 |
|
implode(' or ', $factory->getKnownWebServers()). |
53
|
|
|
'.</comment>' |
54
|
2 |
|
); |
55
|
2 |
|
} |
56
|
|
|
|
57
|
7 |
|
return $webserver; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|