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\Runner; |
11
|
|
|
|
12
|
|
|
use SebastianFeldmann\CaptainHook\Config; |
13
|
|
|
use SebastianFeldmann\CaptainHook\Console\IO; |
14
|
|
|
use SebastianFeldmann\CaptainHook\Exception; |
15
|
|
|
use SebastianFeldmann\CaptainHook\Hook\Util as HookUtil; |
16
|
|
|
use SebastianFeldmann\CaptainHook\Runner; |
17
|
|
|
use SebastianFeldmann\Git\Repository; |
18
|
|
|
|
19
|
|
|
/** |
20
|
|
|
* Class HookHandler |
21
|
|
|
* |
22
|
|
|
* @package CaptainHook |
23
|
|
|
* @author Sebastian Feldmann <[email protected]> |
24
|
|
|
* @link https://github.com/sebastianfeldmann/captainhook |
25
|
|
|
* @since Class available since Release 0.9.0 |
26
|
|
|
*/ |
27
|
|
|
abstract class HookHandler extends Runner |
28
|
|
|
{ |
29
|
|
|
/** |
30
|
|
|
* Git repository. |
31
|
|
|
* |
32
|
|
|
* @var \SebastianFeldmann\Git\Repository |
33
|
|
|
*/ |
34
|
|
|
protected $repository; |
35
|
|
|
|
36
|
|
|
/** |
37
|
|
|
* Hook that should be handled. |
38
|
|
|
* |
39
|
|
|
* @var string |
40
|
|
|
*/ |
41
|
|
|
protected $hookToHandle; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* HookHandler constructor. |
45
|
|
|
* |
46
|
|
|
* @param \SebastianFeldmann\CaptainHook\Console\IO $io |
47
|
|
|
* @param \SebastianFeldmann\CaptainHook\Config $config |
48
|
|
|
* @param \SebastianFeldmann\Git\Repository $repository |
49
|
|
|
*/ |
50
|
15 |
|
public function __construct(IO $io, Config $config, Repository $repository) |
51
|
|
|
{ |
52
|
15 |
|
parent::__construct($io, $config); |
53
|
15 |
|
$this->repository = $repository; |
54
|
15 |
|
} |
55
|
|
|
/** |
56
|
|
|
* Hook setter. |
57
|
|
|
* |
58
|
|
|
* @param string $hook |
59
|
|
|
* @return \SebastianFeldmann\CaptainHook\Runner\HookHandler |
60
|
|
|
* @throws \SebastianFeldmann\CaptainHook\Exception\InvalidHookName |
61
|
|
|
*/ |
62
|
11 |
|
public function setHook(string $hook) : HookHandler |
63
|
|
|
{ |
64
|
11 |
|
if (!empty($hook) && !HookUtil::isValid($hook)) { |
65
|
2 |
|
throw new Exception\InvalidHookName('Invalid hook name \'' . $hook . '\''); |
66
|
|
|
} |
67
|
9 |
|
$this->hookToHandle = $hook; |
68
|
9 |
|
return $this; |
69
|
|
|
} |
70
|
|
|
} |
71
|
|
|
|