|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of Transfer. |
|
5
|
|
|
* |
|
6
|
|
|
* For the full copyright and license information, please view the LICENSE file located |
|
7
|
|
|
* in the root directory. |
|
8
|
|
|
*/ |
|
9
|
|
|
|
|
10
|
|
|
namespace Transfer\Console\Command\Manifest; |
|
11
|
|
|
|
|
12
|
|
|
use Symfony\Component\Console\Input\InputArgument; |
|
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
|
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
16
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
|
17
|
|
|
use Transfer\Exception\ManifestNotFoundException; |
|
18
|
|
|
use Transfer\Manifest\InputDataAwareManifestInterface; |
|
19
|
|
|
use Transfer\Manifest\ManifestInterface; |
|
20
|
|
|
use Transfer\Manifest\ManifestRunner; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Command for running a manifest. |
|
24
|
|
|
*/ |
|
25
|
|
|
class RunCommand extends ManifestCommand |
|
26
|
|
|
{ |
|
27
|
|
|
/** |
|
28
|
|
|
* @var EventDispatcherInterface Custom event dispatcher |
|
29
|
|
|
*/ |
|
30
|
|
|
protected $dispatcher; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* {@inheritdoc} |
|
34
|
|
|
*/ |
|
35
|
4 |
|
protected function configure() |
|
36
|
|
|
{ |
|
37
|
4 |
|
parent::configure(); |
|
38
|
|
|
|
|
39
|
4 |
|
$this |
|
40
|
4 |
|
->setName('manifest:run') |
|
41
|
4 |
|
->setDescription('Run a specific manifest') |
|
42
|
4 |
|
->addArgument('name', InputArgument::OPTIONAL, 'Name of the manifest') |
|
43
|
4 |
|
->addOption('input', 'i', InputOption::VALUE_OPTIONAL, 'Input data'); |
|
44
|
4 |
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* Sets custom event dispatcher. |
|
48
|
|
|
* |
|
49
|
|
|
* @param EventDispatcherInterface $dispatcher Custom event dispatcher |
|
50
|
|
|
*/ |
|
51
|
2 |
|
public function setEventDispatcher($dispatcher) |
|
52
|
|
|
{ |
|
53
|
2 |
|
$this->dispatcher = $dispatcher; |
|
54
|
2 |
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* {@inheritdoc} |
|
58
|
|
|
*/ |
|
59
|
2 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
|
60
|
|
|
{ |
|
61
|
2 |
|
parent::execute($input, $output); |
|
62
|
|
|
|
|
63
|
1 |
|
$name = $input->getArgument('name'); |
|
64
|
|
|
|
|
65
|
1 |
|
$manifest = $this->chain->getManifest($name); |
|
|
|
|
|
|
66
|
|
|
|
|
67
|
1 |
|
if (!$manifest) { |
|
68
|
1 |
|
throw new ManifestNotFoundException($name); |
|
|
|
|
|
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
1 |
|
$this->applyInputData($manifest, $input->getOption('input')); |
|
72
|
|
|
|
|
73
|
1 |
|
$this->runManifest($manifest); |
|
74
|
1 |
|
} |
|
75
|
|
|
|
|
76
|
|
|
/** |
|
77
|
|
|
* Runs a manifest. |
|
78
|
|
|
* |
|
79
|
|
|
* @param ManifestInterface $manifest Manifest to run |
|
80
|
|
|
*/ |
|
81
|
1 |
|
private function runManifest(ManifestInterface $manifest) |
|
82
|
|
|
{ |
|
83
|
1 |
|
$runner = new ManifestRunner(); |
|
84
|
1 |
|
$runner->run($manifest); |
|
85
|
1 |
|
} |
|
86
|
|
|
|
|
87
|
|
|
/** |
|
88
|
|
|
* Applies input data. |
|
89
|
|
|
* |
|
90
|
|
|
* @param ManifestInterface $manifest Manifest |
|
91
|
|
|
* @param string $input Input data |
|
92
|
|
|
*/ |
|
93
|
1 |
|
private function applyInputData(ManifestInterface $manifest, $input) |
|
94
|
|
|
{ |
|
95
|
1 |
|
if ($manifest instanceof InputDataAwareManifestInterface) { |
|
96
|
1 |
|
$manifest->setInputData($input); |
|
97
|
1 |
|
} |
|
98
|
1 |
|
} |
|
99
|
|
|
} |
|
100
|
|
|
|
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.