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
|
|
|
protected function getPath(InputInterface $input) |
26
|
|
|
{ |
27
|
|
|
$path = $input->getArgument('path'); |
28
|
|
|
|
29
|
|
|
if (empty($path)) { |
30
|
|
|
$path = explode(PATH_SEPARATOR, getenv('PATH')); |
31
|
|
|
} |
32
|
|
|
|
33
|
|
|
return $path; |
34
|
|
|
} |
35
|
|
|
|
36
|
|
|
protected function getWebServer(InputInterface $input, OutputInterface $output) |
37
|
|
|
{ |
38
|
|
|
$webservername = $input->getArgument('webserver'); |
39
|
|
|
$version = 0; |
40
|
|
View Code Duplication |
if (preg_match(',([^:]+)(:([\.\d]+))$,', $webservername, $matches)) { |
|
|
|
|
41
|
|
|
$version = $matches[3]; |
42
|
|
|
$webservername = $matches[1]; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
$factory = new Factory(); |
46
|
|
|
|
47
|
|
|
$webserver = $factory->createWebServer($webservername, $version); |
48
|
|
|
if ($webserver instanceof NullWebServer) { |
49
|
|
|
$output->writeln('<error>Web Server "'.$webservername.'" unknown.</error>'); |
50
|
|
|
$output->writeln( |
51
|
|
|
'<comment>Known Web Servers are '. |
52
|
|
|
implode(' or ', $factory->getKnownWebServers()). |
53
|
|
|
'.</comment>' |
54
|
|
|
); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return $webserver; |
58
|
|
|
} |
59
|
|
|
} |
60
|
|
|
|
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.