|
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\Config; |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* Class Action |
|
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 Action |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* Action type |
|
24
|
|
|
* |
|
25
|
|
|
* @var string |
|
26
|
|
|
*/ |
|
27
|
|
|
private $type; |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Action phpc lass or cli script |
|
31
|
|
|
* |
|
32
|
|
|
* @var string |
|
33
|
|
|
*/ |
|
34
|
|
|
private $action; |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Map of options name => value |
|
38
|
|
|
* |
|
39
|
|
|
* @var \SebastianFeldmann\CaptainHook\Config\Options |
|
40
|
|
|
*/ |
|
41
|
|
|
private $options; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* List of valid action types |
|
45
|
|
|
* |
|
46
|
|
|
* @var array |
|
47
|
|
|
*/ |
|
48
|
|
|
protected static $validTypes = ['php' => true, 'cli' => true]; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* Action constructor. |
|
52
|
|
|
* |
|
53
|
|
|
* @param string $type |
|
54
|
|
|
* @param string $action |
|
55
|
|
|
* @param array $options |
|
56
|
|
|
* @throws \Exception |
|
57
|
|
|
*/ |
|
58
|
33 |
|
public function __construct(string $type, string $action, array $options = []) |
|
59
|
|
|
{ |
|
60
|
33 |
|
if (!isset(self::$validTypes[$type])) { |
|
61
|
1 |
|
throw new \Exception(sprintf('Invalid action type: %s', $type)); |
|
62
|
|
|
} |
|
63
|
32 |
|
$this->type = $type; |
|
64
|
32 |
|
$this->action = $action; |
|
65
|
32 |
|
$this->options = new Options($options); |
|
66
|
32 |
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Type getter. |
|
70
|
|
|
* |
|
71
|
|
|
* @return string |
|
72
|
|
|
*/ |
|
73
|
1 |
|
public function getType() : string |
|
74
|
|
|
{ |
|
75
|
1 |
|
return $this->type; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* Action getter. |
|
80
|
|
|
* |
|
81
|
|
|
* @return string |
|
82
|
|
|
*/ |
|
83
|
1 |
|
public function getAction() : string |
|
84
|
|
|
{ |
|
85
|
1 |
|
return $this->action; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Return option map. |
|
90
|
|
|
* |
|
91
|
|
|
* @return \SebastianFeldmann\CaptainHook\Config\Options |
|
92
|
|
|
*/ |
|
93
|
16 |
|
public function getOptions() : Options |
|
94
|
|
|
{ |
|
95
|
16 |
|
return $this->options; |
|
96
|
|
|
} |
|
97
|
|
|
|
|
98
|
|
|
/** |
|
99
|
|
|
* Return config data. |
|
100
|
|
|
* |
|
101
|
|
|
* @return array |
|
102
|
|
|
*/ |
|
103
|
2 |
|
public function getJsonData() : array |
|
104
|
|
|
{ |
|
105
|
|
|
return [ |
|
106
|
2 |
|
'action' => $this->action, |
|
107
|
2 |
|
'options' => $this->options->getAll(), |
|
108
|
|
|
]; |
|
109
|
|
|
} |
|
110
|
|
|
} |
|
111
|
|
|
|