|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of CaptainHook. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Sebastian Feldmann <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
*/ |
|
10
|
|
|
namespace sebastianfeldmann\CaptainHook\Console\Command; |
|
11
|
|
|
|
|
12
|
|
|
use sebastianfeldmann\CaptainHook\Config; |
|
13
|
|
|
use sebastianfeldmann\CaptainHook\Console\IO; |
|
14
|
|
|
use Symfony\Component\Console\Command\Command; |
|
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
|
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* Class Base |
|
20
|
|
|
* |
|
21
|
|
|
* @package CaptainHook |
|
22
|
|
|
* @author Sebastian Feldmann <[email protected]> |
|
23
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
|
24
|
|
|
* @since Class available since Release 0.9.0 |
|
25
|
|
|
*/ |
|
26
|
|
|
class Base extends Command |
|
27
|
|
|
{ |
|
28
|
|
|
/** |
|
29
|
|
|
* Input output handler. |
|
30
|
|
|
* |
|
31
|
|
|
* @var \sebastianfeldmann\CaptainHook\Console\IO |
|
32
|
|
|
*/ |
|
33
|
|
|
private $io; |
|
34
|
|
|
|
|
35
|
|
|
/** |
|
36
|
|
|
* CaptainHook configuration |
|
37
|
|
|
* |
|
38
|
|
|
* @var \sebastianfeldmann\CaptainHook\Config |
|
39
|
|
|
*/ |
|
40
|
|
|
private $config; |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* IO setter. |
|
44
|
|
|
* |
|
45
|
|
|
* @param \sebastianfeldmann\CaptainHook\Console\IO $io |
|
46
|
|
|
*/ |
|
47
|
9 |
|
public function setIO(IO $io) |
|
48
|
|
|
{ |
|
49
|
9 |
|
$this->io = $io; |
|
50
|
9 |
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* IO interface getter. |
|
54
|
|
|
* |
|
55
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
|
56
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
|
57
|
|
|
* @return \sebastianfeldmann\CaptainHook\Console\IO |
|
58
|
|
|
*/ |
|
59
|
11 |
|
public function getIO(InputInterface $input, OutputInterface $output) |
|
60
|
|
|
{ |
|
61
|
11 |
|
if (null === $this->io) { |
|
62
|
2 |
|
$this->io = new IO\DefaultIO($input, $output, $this->getHelperSet()); |
|
63
|
|
|
} |
|
64
|
11 |
|
return $this->io; |
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
/** |
|
68
|
|
|
* CaptainHook config getter. |
|
69
|
|
|
* |
|
70
|
|
|
* @param string $path |
|
71
|
|
|
* @param bool $failIfNotFound |
|
72
|
|
|
* @return \sebastianfeldmann\CaptainHook\Config |
|
73
|
|
|
*/ |
|
74
|
11 |
|
protected function getConfig($path = null, $failIfNotFound = false) |
|
75
|
|
|
{ |
|
76
|
11 |
|
$this->config = Config\Factory::create($path); |
|
77
|
|
|
|
|
78
|
10 |
|
if ($failIfNotFound && !$this->config->isLoadedFromFile()) { |
|
79
|
1 |
|
throw new \RuntimeException( |
|
80
|
1 |
|
'Please create a captainhook configuration first' . PHP_EOL . |
|
81
|
1 |
|
'Run \'captainhook configure\'' . PHP_EOL . |
|
82
|
1 |
|
'If you have a configuration located elsewhere use the --configuration option' |
|
83
|
|
|
); |
|
84
|
|
|
} |
|
85
|
9 |
|
return $this->config; |
|
86
|
|
|
} |
|
87
|
|
|
} |
|
88
|
|
|
|