/
PipelineCommand.php
58 lines (45 loc) · 1.66 KB
/
PipelineCommand.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php
namespace App\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\ArrayInput;
class PipelineCommand extends \App\Command{
protected $configHistory;
protected function configure()
{
$this->setName('pipeline')
->setDescription('Execute a pipeline')
;
}
protected function doExecute(InputInterface $input) {
$app = $this->getApplication();
$pipes = $app->getPipeLine();
foreach($pipes as $pipeName => $config) {
preg_match('/^([\w:]+)(.*)/', $pipeName, $match);
list($match, $commandName, $description) = $match;
$config = $this->processConfig($config);
$this->info(sprintf('Running pipe \'%s\' ...', $pipeName));
$app->appendConfig($config);
$this->runSubCommand($commandName);
$this->configHistory[$pipeName] = $app->getConfig();
}
$this->info('Pipeline completed');
}
protected function processConfig(array $config) {
foreach($config as $key => $value) {
if(preg_match('/^@/', $key)) {
switch($key) {
case '@from':
$config = $this->getConfigFrom($value, $config);
break;
default:
throw new \InvalidArgumentException(sprintf('Unexpected %s parameter', $key));
}
unset($config[$key]);
}
}
return $config;
}
protected function getConfigFrom($pipeName, $topConfig) {
return array_merge($this->configHistory[$pipeName], $topConfig);
}
}