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\Runner; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* Hook |
14
|
|
|
* |
15
|
|
|
* @package CaptainHook |
16
|
|
|
* @author Sebastian Feldmann <[email protected]> |
17
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
18
|
|
|
* @since Class available since Release 0.9.0 |
19
|
|
|
*/ |
20
|
|
|
class Hook extends HookHandler |
21
|
|
|
{ |
22
|
|
|
/** |
23
|
|
|
* Hook config |
24
|
|
|
* |
25
|
|
|
* @var \CaptainHook\Config\Hook |
26
|
|
|
*/ |
27
|
|
|
private $hookConfig; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Execute installation. |
31
|
|
|
*/ |
32
|
7 |
|
public function run() |
33
|
|
|
{ |
34
|
|
|
/** @var \CaptainHook\Config\Hook $hookConfig */ |
35
|
7 |
|
$this->hookConfig = $this->config->getHookConfig($this->hookToHandle); |
36
|
|
|
|
37
|
|
|
// execute hooks only if hook is enabled in captainhook.json |
38
|
7 |
|
if ($this->hookConfig->isEnabled()) { |
39
|
6 |
|
$this->io->write('EXECUTE: ' . $this->hookToHandle); |
40
|
6 |
|
foreach ($this->getActionsToRun() as $action) { |
41
|
1 |
|
$this->io->write(PHP_EOL . str_repeat('#', 80) . PHP_EOL); |
42
|
1 |
|
$runner = $this->getActionRunner($action->getType()); |
43
|
6 |
|
$runner->execute($this->config, $this->io, $this->repository, $action); |
44
|
|
|
} |
45
|
|
|
} else { |
46
|
1 |
|
$this->io->write('SKIP: ' . $this->hookToHandle . ' is disabled.'); |
47
|
|
|
} |
48
|
7 |
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Return list of actions to run. |
52
|
|
|
* |
53
|
|
|
* @return \CaptainHook\Config\Action[] |
54
|
|
|
*/ |
55
|
6 |
|
protected function getActionsToRun() |
56
|
|
|
{ |
57
|
6 |
|
return $this->hookConfig->getActions(); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Return matching action runner. |
62
|
|
|
* |
63
|
|
|
* @param string $type |
64
|
|
|
* @return \CaptainHook\Hook\Action |
65
|
|
|
* @throws \RuntimeException |
66
|
|
|
*/ |
67
|
3 |
|
public function getActionRunner($type) |
68
|
|
|
{ |
69
|
|
|
switch ($type) { |
70
|
3 |
|
case 'php': |
71
|
1 |
|
return new Action\PHP(); |
72
|
3 |
|
case 'cli': |
73
|
2 |
|
return new Action\Cli(); |
74
|
|
|
default: |
75
|
1 |
|
throw new \RuntimeException('Unknown action type: ' . $type); |
76
|
|
|
} |
77
|
|
|
} |
78
|
|
|
} |
79
|
|
|
|