1 | <?php |
||
15 | class Arguments |
||
16 | { |
||
17 | /** |
||
18 | * The argument objects. |
||
19 | * |
||
20 | * @var Argument[] |
||
21 | */ |
||
22 | protected $arguments; |
||
23 | |||
24 | /** |
||
25 | * Create arguments object. |
||
26 | */ |
||
27 | 18 | public function __construct() |
|
31 | |||
32 | /** |
||
33 | * Return arguments as array of strings. |
||
34 | * |
||
35 | * @return string[] |
||
36 | */ |
||
37 | public function toArray() |
||
43 | |||
44 | /** |
||
45 | * Convert argument to argument object. |
||
46 | * |
||
47 | * @param string|Argument $argument |
||
48 | * |
||
49 | * @throws \InvalidArgumentException |
||
50 | * |
||
51 | * @return Argument |
||
52 | */ |
||
53 | 16 | protected function convertArgument($argument) |
|
54 | { |
||
55 | 16 | if (is_string($argument)) { |
|
56 | 14 | $argument = Argument::fromString($argument); |
|
57 | 7 | } |
|
58 | |||
59 | 16 | if (!$argument instanceof Argument) { |
|
60 | 2 | throw new \InvalidArgumentException('Invalid argument'); |
|
61 | } |
||
62 | |||
63 | 14 | return $argument; |
|
64 | } |
||
65 | |||
66 | /** |
||
67 | * Get argument object. |
||
68 | * |
||
69 | * @param string $name |
||
70 | * |
||
71 | * @return Argument|null |
||
72 | */ |
||
73 | 2 | public function getArgument($name) |
|
83 | |||
84 | /** |
||
85 | * Add argument. |
||
86 | * |
||
87 | * @param string|Argument $argument |
||
88 | * |
||
89 | * @throws \InvalidArgumentException |
||
90 | * |
||
91 | * @return $this |
||
92 | */ |
||
93 | 6 | public function addArgument($argument) |
|
99 | |||
100 | /** |
||
101 | * Add all arguments. |
||
102 | * |
||
103 | * @param array $arguments |
||
104 | * |
||
105 | * @throws \InvalidArgumentException |
||
106 | * |
||
107 | * @return $this |
||
108 | */ |
||
109 | 6 | public function addArguments(array $arguments) |
|
110 | { |
||
111 | 6 | foreach ($arguments as $argument) { |
|
112 | 6 | $this->addArgument($argument); |
|
113 | 3 | } |
|
114 | |||
115 | 6 | return $this; |
|
116 | } |
||
117 | |||
118 | /** |
||
119 | * Hash the name. |
||
120 | * |
||
121 | * @param string $name |
||
122 | * |
||
123 | * @return string |
||
124 | */ |
||
125 | 8 | protected function hashName($name) |
|
129 | |||
130 | /** |
||
131 | * Set argument. |
||
132 | * |
||
133 | * @param string|Argument $argument |
||
134 | * |
||
135 | * @throws \InvalidArgumentException |
||
136 | * |
||
137 | * @return $this |
||
138 | */ |
||
139 | 8 | public function setArgument($argument) |
|
149 | |||
150 | /** |
||
151 | * Set all arguments. |
||
152 | * |
||
153 | * @param array $arguments |
||
154 | * |
||
155 | * @throws \InvalidArgumentException |
||
156 | * |
||
157 | * @return $this |
||
158 | */ |
||
159 | 6 | public function setArguments(array $arguments) |
|
167 | } |
||
168 |