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\Input\InputInterface; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
17
|
|
|
use JamesRezo\WebHelper\WebHelper; |
18
|
|
|
use JamesRezo\WebHelper\WebServer\NullWebServer; |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* Generates Configuration Statements given a webserver and known directives. |
22
|
|
|
*/ |
23
|
|
|
class GenerateCommand extends BaseCommand |
24
|
|
|
{ |
25
|
|
|
/** |
26
|
|
|
* {@inheritdoc} |
27
|
|
|
*/ |
28
|
4 |
|
protected function configure() |
29
|
|
|
{ |
30
|
4 |
|
$this |
31
|
4 |
|
->setName('generate') |
32
|
4 |
|
->setDescription('Output statements for a webserver') |
33
|
4 |
|
->setHelp('The <info>generate</info> command creates one or many statements for the specified webserver.') |
34
|
4 |
|
->addArgument('webserver', InputArgument::REQUIRED, 'a webserver name.') |
35
|
4 |
|
->addArgument('directives', InputArgument::IS_ARRAY, 'List of directives to generate.') |
36
|
|
|
; |
37
|
4 |
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Execute the command. |
41
|
|
|
* |
42
|
|
|
* {@inheritdoc} |
43
|
|
|
* |
44
|
|
|
* @param InputInterface $input the input interface |
45
|
|
|
* @param OutputInterface $output the output interface |
46
|
|
|
*/ |
47
|
3 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
48
|
|
|
{ |
49
|
3 |
|
$webserver = $this->getWebServer($input, $output); |
50
|
3 |
|
if ($webserver instanceof NullWebServer) { |
51
|
1 |
|
return 1; |
52
|
|
|
} |
53
|
|
|
|
54
|
2 |
|
$webservername = $webserver->getName(); |
55
|
2 |
|
$version = $webserver->getVersion(); |
56
|
|
|
|
57
|
2 |
|
$directives = $input->getArgument('directives'); |
58
|
|
|
|
59
|
2 |
|
$webhelper = new WebHelper(); |
60
|
2 |
|
$webhelper->setRepository(__DIR__.'/../../res'); |
61
|
2 |
|
$webhelper->setProject('webhelper', '0.2'); |
62
|
2 |
|
$webhelper->setServer($webservername, $version); |
63
|
|
|
|
64
|
2 |
|
if ($webhelper->getRepository()->okGo()) { |
65
|
2 |
|
foreach ($directives as $directive) { |
66
|
2 |
|
$twigFile = $webhelper->find($directive); |
67
|
2 |
|
$output->write($webhelper->render($twigFile, $webhelper->getProject()->getParameters())); |
68
|
2 |
|
} |
69
|
2 |
|
} |
70
|
2 |
|
} |
71
|
|
|
} |
72
|
|
|
|