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\Command\Command; |
13
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
14
|
|
|
use Symfony\Component\Console\Input\InputOption; |
15
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
16
|
|
|
use Transfer\Exception\MissingManifestChainException; |
17
|
|
|
use Transfer\Manifest\ManifestChain; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Base for manifest commands. |
21
|
|
|
*/ |
22
|
|
|
abstract class ManifestCommand extends Command |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* @var ManifestChain Manifest chain |
26
|
|
|
*/ |
27
|
|
|
protected $chain; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
12 |
|
protected function configure() |
33
|
|
|
{ |
34
|
12 |
|
$this->addOption('chain', 'c', InputOption::VALUE_REQUIRED, 'Manifest chain'); |
35
|
12 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* Sets manifest chain. |
39
|
|
|
* |
40
|
|
|
* @param ManifestChain $chain Manifest chain |
41
|
|
|
*/ |
42
|
3 |
|
public function setChain(ManifestChain $chain) |
43
|
|
|
{ |
44
|
3 |
|
$this->chain = $chain; |
45
|
3 |
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* {@inheritdoc} |
49
|
|
|
*/ |
50
|
8 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
51
|
|
|
{ |
52
|
8 |
|
$file = $input->getOption('chain'); |
53
|
|
|
|
54
|
8 |
|
if ($file !== null) { |
55
|
2 |
|
if (!file_exists($file)) { |
56
|
1 |
|
throw new \InvalidArgumentException(sprintf('File "%s" could not be located.', $file)); |
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
/* @var ManifestChain $input */ |
60
|
1 |
|
$this->chain = require $file; |
61
|
1 |
|
} |
62
|
|
|
|
63
|
7 |
|
if ($this->chain === null) { |
64
|
3 |
|
throw new MissingManifestChainException(); |
65
|
|
|
} |
66
|
4 |
|
} |
67
|
|
|
} |
68
|
|
|
|