1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace ParserHooks\Internal; |
4
|
|
|
|
5
|
|
|
use ParamProcessor\Processor; |
6
|
|
|
use Parser; |
7
|
|
|
use ParserHooks\HookDefinition; |
8
|
|
|
use ParserHooks\HookHandler; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* @since 1.1 |
12
|
|
|
* @licence GNU GPL v2+ |
13
|
|
|
* @author Jeroen De Dauw < [email protected] > |
14
|
|
|
*/ |
15
|
|
|
abstract class Runner { |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @since 1.1 |
19
|
|
|
* |
20
|
|
|
* @var HookDefinition |
21
|
|
|
*/ |
22
|
|
|
protected $definition; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @since 1.1 |
26
|
|
|
* |
27
|
|
|
* @var HookHandler |
28
|
|
|
*/ |
29
|
|
|
protected $handler; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @since 1.1 |
33
|
|
|
* |
34
|
|
|
* @var array |
35
|
|
|
*/ |
36
|
|
|
private $options; |
37
|
|
|
|
38
|
|
|
/** |
39
|
|
|
* @since 1.1 |
40
|
|
|
* |
41
|
|
|
* @var Processor |
42
|
|
|
*/ |
43
|
|
|
protected $paramProcessor; |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @since 1.1 |
47
|
|
|
* |
48
|
|
|
* @param HookDefinition $definition |
49
|
|
|
* @param HookHandler $handler |
50
|
|
|
* @param array $options |
51
|
|
|
* @param Processor|null $paramProcessor |
52
|
|
|
*/ |
53
|
7 |
|
public function __construct( HookDefinition $definition, HookHandler $handler, array $options = [], Processor $paramProcessor = null ) { |
54
|
7 |
|
$this->definition = $definition; |
55
|
7 |
|
$this->handler = $handler; |
56
|
|
|
|
57
|
7 |
|
$this->setParamProcessor( $paramProcessor ); |
58
|
7 |
|
$this->setOptions( $options ); |
59
|
7 |
|
} |
60
|
|
|
|
61
|
7 |
|
private function setParamProcessor( $paramProcessor ) { |
62
|
7 |
|
if ( $paramProcessor === null ) { |
63
|
1 |
|
$paramProcessor = Processor::newDefault(); |
64
|
|
|
} |
65
|
|
|
|
66
|
7 |
|
$this->paramProcessor = $paramProcessor; |
67
|
7 |
|
} |
68
|
|
|
|
69
|
7 |
|
private function setOptions( array $options ) { |
70
|
7 |
|
$this->options = array_merge( |
71
|
7 |
|
$this->getDefaultOptions(), |
72
|
|
|
$options |
73
|
|
|
); |
74
|
7 |
|
} |
75
|
|
|
|
76
|
|
|
/** |
77
|
|
|
* @since 1.1 |
78
|
|
|
* |
79
|
|
|
* @param string $name |
80
|
|
|
* |
81
|
|
|
* @return mixed |
82
|
|
|
*/ |
83
|
7 |
|
protected function getOption( $name ) { |
84
|
7 |
|
return $this->options[$name]; |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @since 1.1 |
89
|
|
|
* |
90
|
|
|
* @return array |
91
|
|
|
*/ |
92
|
|
|
protected abstract function getDefaultOptions(); |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @since 1.1 |
96
|
|
|
* |
97
|
|
|
* @return HookHandler |
98
|
|
|
*/ |
99
|
|
|
public function getHandler() { |
100
|
|
|
return $this->handler; |
101
|
|
|
} |
102
|
|
|
|
103
|
|
|
/** |
104
|
|
|
* @since 1.1 |
105
|
|
|
* |
106
|
|
|
* @return HookDefinition |
107
|
|
|
*/ |
108
|
1 |
|
public function getDefinition() { |
109
|
1 |
|
return $this->definition; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
} |
113
|
|
|
|