1 | <?php |
||
10 | class Parameters implements Arrayable, \Iterator { |
||
11 | |||
12 | use RefPart; |
||
13 | |||
14 | /** @var ArrayList */ |
||
15 | private $parameters; |
||
16 | |||
17 | 12 | public function __construct($contents = []) { |
|
18 | 12 | $this->parse($contents === null ? [] : $contents); |
|
19 | 12 | } |
|
20 | |||
21 | 12 | private function parse($contents) { |
|
22 | 12 | $data = CollectionUtils::toMap($contents); |
|
23 | |||
24 | 12 | $this->parameters = new ArrayList(); |
|
25 | 12 | $this->parseRef($data); |
|
26 | |||
27 | 12 | if (!$this->hasRef()) { |
|
28 | 12 | foreach ($data as $param) { |
|
29 | 4 | $this->parameters->add(new Parameter($param)); |
|
30 | 12 | } |
|
31 | 12 | } |
|
32 | 12 | } |
|
33 | |||
34 | 8 | public function toArray() { |
|
35 | 8 | if ($this->hasRef()) { |
|
36 | 1 | return ['$ref' => $this->getRef()]; |
|
37 | } |
||
38 | |||
39 | 7 | return $this->parameters->toArray(); |
|
40 | } |
||
41 | |||
42 | 1 | public function size() { |
|
45 | |||
46 | /** |
||
47 | * Searches whether a parameter with the given name exists |
||
48 | * |
||
49 | * @param string $name |
||
50 | * @return boolean |
||
51 | */ |
||
52 | public function searchByName($name) { |
||
57 | |||
58 | /** |
||
59 | * Returns parameter with the given name if it exists |
||
60 | * |
||
61 | * @param string $name |
||
62 | * @return Parameter|void |
||
63 | */ |
||
64 | 12 | public function findByName($name) { |
|
71 | |||
72 | /** |
||
73 | * Searches for the parameter with the given name. Creates a parameter with the given name |
||
74 | * if none exists |
||
75 | * |
||
76 | * @param string $name |
||
77 | * @return Parameter |
||
78 | */ |
||
79 | public function getByName($name) { |
||
89 | |||
90 | public function find($in, $name) { |
||
97 | |||
98 | public function get($in, $name) { |
||
109 | |||
110 | /** |
||
111 | * Adds a parameter |
||
112 | * |
||
113 | * @param Parameter $param |
||
114 | */ |
||
115 | 1 | public function add(Parameter $param) { |
|
118 | |||
119 | /** |
||
120 | * Removes a parameter |
||
121 | * |
||
122 | * @param Parameter $param |
||
123 | */ |
||
124 | 1 | public function remove(Parameter $param) { |
|
127 | |||
128 | /** |
||
129 | * Returns whether a given parameter exists |
||
130 | * |
||
131 | * @param Parameter $param |
||
132 | * @return boolean |
||
133 | */ |
||
134 | 1 | public function contains(Parameter $param) { |
|
137 | |||
138 | public function current() { |
||
141 | |||
142 | public function key() { |
||
145 | |||
146 | public function next() { |
||
149 | |||
150 | public function rewind() { |
||
153 | |||
154 | public function valid() { |
||
157 | } |
||
158 |