1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Jalle19\HaPHProxy\Section; |
4
|
|
|
|
5
|
|
|
use Jalle19\HaPHProxy\Parameter\Parameter; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class AbstractSection |
9
|
|
|
* @package Jalle19\HaPHProxy\Section |
10
|
|
|
* @author Sam Stenvall <[email protected]> |
11
|
|
|
* @license GNU General Public License 2.0+ |
12
|
|
|
*/ |
13
|
|
|
abstract class AbstractSection |
14
|
|
|
{ |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var Parameter[] |
18
|
|
|
*/ |
19
|
|
|
protected $parameters = []; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $magicComments = []; |
25
|
|
|
|
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @return string the type of section |
29
|
|
|
*/ |
30
|
|
|
abstract public function getType(); |
31
|
|
|
|
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @param Parameter $parameter |
35
|
|
|
* |
36
|
|
|
* @return $this |
37
|
|
|
*/ |
38
|
|
|
public function addParameter(Parameter $parameter) |
39
|
|
|
{ |
40
|
|
|
$this->parameters[] = $parameter; |
41
|
|
|
|
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
/** |
47
|
|
|
* @param string $name |
48
|
|
|
* |
49
|
|
|
* @return bool whether the specified parameter exists |
50
|
|
|
*/ |
51
|
|
|
public function hasParameter($name) |
52
|
|
|
{ |
53
|
|
|
return $this->getParameterByName($name) !== null; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* @param string $name |
59
|
|
|
* |
60
|
|
|
* @return Parameter|null the parameter matching the specified name, or null if not found |
61
|
|
|
*/ |
62
|
|
|
public function getParameterByName($name) |
63
|
|
|
{ |
64
|
|
|
foreach ($this->parameters as $parameter) { |
65
|
|
|
if ($parameter->getName() === $name) { |
66
|
|
|
return $parameter; |
67
|
|
|
} |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
return null; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* @return Parameter[] |
76
|
|
|
*/ |
77
|
|
|
public function getParameters() |
78
|
|
|
{ |
79
|
|
|
return $this->parameters; |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* @param string $name |
85
|
|
|
* |
86
|
|
|
* @return Parameter[] all parameters matching the specified nameF |
87
|
|
|
*/ |
88
|
|
|
public function getParametersByName($name) |
89
|
|
|
{ |
90
|
|
|
$parameters = []; |
91
|
|
|
|
92
|
|
|
foreach ($this->parameters as $parameter) { |
93
|
|
|
if ($parameter->getName() === $name) { |
94
|
|
|
$parameters[] = $parameter; |
95
|
|
|
} |
96
|
|
|
} |
97
|
|
|
|
98
|
|
|
return $parameters; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @return array |
104
|
|
|
*/ |
105
|
|
|
public function getMagicComments() |
106
|
|
|
{ |
107
|
|
|
return $this->magicComments; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* @param string $comment |
113
|
|
|
*/ |
114
|
|
|
public function addMagicComment($comment) |
115
|
|
|
{ |
116
|
|
|
$this->magicComments[] = $comment; |
117
|
|
|
} |
118
|
|
|
|
119
|
|
|
} |
120
|
|
|
|