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 CaptainHook\App\Console\Command; |
11
|
|
|
|
12
|
|
|
use CaptainHook\App\Config; |
13
|
|
|
use CaptainHook\App\Hook\Util; |
14
|
|
|
use SebastianFeldmann\Git\Repository; |
15
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
16
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* Class Hook |
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
|
|
|
abstract class Hook extends Base |
27
|
|
|
{ |
28
|
|
|
/** |
29
|
|
|
* Hook to execute |
30
|
|
|
* |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $hookName; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Path to the configuration file to use |
37
|
|
|
* |
38
|
|
|
* @var string |
39
|
|
|
*/ |
40
|
|
|
protected $configFile; |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Path to the git repository to use. |
44
|
|
|
* |
45
|
|
|
* @var string |
46
|
|
|
*/ |
47
|
|
|
protected $repositoryPath; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Hook constructor |
51
|
|
|
* |
52
|
|
|
* @param string $configFile |
53
|
|
|
* @param string $repositoryPath |
54
|
|
|
*/ |
55
|
5 |
|
public function __construct(string $configFile, string $repositoryPath) |
56
|
|
|
{ |
57
|
5 |
|
$this->configFile = $configFile; |
58
|
5 |
|
$this->repositoryPath = $repositoryPath; |
59
|
5 |
|
parent::__construct(); |
60
|
5 |
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* Configure the command |
64
|
|
|
*/ |
65
|
5 |
|
protected function configure() |
66
|
|
|
{ |
67
|
5 |
|
$this->setName($this->hookName) |
68
|
5 |
|
->setDescription('Run git ' . $this->hookName . ' hook.') |
69
|
5 |
|
->setHelp('This command executes the ' . $this->hookName . ' hook.'); |
70
|
5 |
|
} |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Execute the command |
74
|
|
|
* |
75
|
|
|
* @param \Symfony\Component\Console\Input\InputInterface $input |
76
|
|
|
* @param \Symfony\Component\Console\Output\OutputInterface $output |
77
|
|
|
* @return void |
78
|
|
|
* @throws \Exception |
79
|
|
|
*/ |
80
|
5 |
|
protected function execute(InputInterface $input, OutputInterface $output) |
81
|
|
|
{ |
82
|
5 |
|
$io = $this->getIO($input, $output); |
83
|
5 |
|
$config = $this->getConfig($this->configFile, true); |
84
|
5 |
|
$repository = new Repository($this->repositoryPath); |
85
|
|
|
$arguments = new Config\Options($input->getArguments()); |
86
|
|
|
|
87
|
|
|
/** @var \CaptainHook\App\Runner\Hook $hook */ |
88
|
4 |
|
$class = '\\CaptainHook\\App\\Runner\\Hook\\' . Util::getHookCommand($this->hookName); |
89
|
|
|
$hook = new $class($io, $config, $repository, $arguments); |
90
|
|
|
$hook->run(); |
91
|
4 |
|
} |
92
|
|
|
} |
93
|
|
|
|