1 | <?php |
||
47 | class ActionDescriptor extends AbstractNameAwareDescriptor implements ActionDescriptorInterface |
||
48 | { |
||
49 | |||
50 | /** |
||
51 | * The action method name. |
||
52 | * |
||
53 | * @var string |
||
54 | */ |
||
55 | protected $methodName; |
||
56 | |||
57 | /** |
||
58 | * The request methods the action is listening to. |
||
59 | * |
||
60 | * @var array |
||
61 | */ |
||
62 | protected $requestMethods = array(); |
||
63 | |||
64 | protected $mappedRequestMethods = array( |
||
65 | HttpProtocol::METHOD_CONNECT => Connect::class, |
||
66 | HttpProtocol::METHOD_DELETE => Delete::class, |
||
67 | HttpProtocol::METHOD_GET => Get::class, |
||
68 | HttpProtocol::METHOD_HEAD => Head::class, |
||
69 | HttpProtocol::METHOD_OPTIONS => Options::class, |
||
70 | HttpProtocol::METHOD_POST => Post::class, |
||
71 | HttpProtocol::METHOD_PUT => Put::class, |
||
72 | HttpProtocol::METHOD_TRACE => Trace::class, |
||
73 | HttpProtocol::METHOD_PATCH => Patch::class |
||
74 | ); |
||
75 | |||
76 | /** |
||
77 | * The restrictions for the route placeholders. |
||
78 | * |
||
79 | * @var array |
||
80 | */ |
||
81 | protected $restrictions; |
||
82 | |||
83 | /** |
||
84 | * The defaults for the route placeholders. |
||
85 | * |
||
86 | * @var array |
||
87 | */ |
||
88 | protected $defaults; |
||
89 | |||
90 | /** |
||
91 | * Initializes the descriptor with the default |
||
92 | * request methods the action is listening to. |
||
93 | */ |
||
94 | 9 | public function __construct() |
|
95 | { |
||
96 | |||
97 | // initialize restrictions and defaults |
||
98 | 9 | $this->defaults = array(); |
|
99 | 9 | $this->restrictions = array(); |
|
100 | |||
101 | // initialize the request methods |
||
102 | 9 | $this->requestMethods = array_keys($this->getMappedRequestMethods()); |
|
103 | 9 | } |
|
104 | |||
105 | /** |
||
106 | * Sets the action method name. |
||
107 | * |
||
108 | * @param string $methodName The action method name |
||
109 | * |
||
110 | * @return void |
||
111 | */ |
||
112 | 8 | public function setMethodName($methodName) |
|
113 | { |
||
114 | 8 | $this->methodName = $methodName; |
|
115 | 8 | } |
|
116 | |||
117 | /** |
||
118 | * Returns the action method name. |
||
119 | * |
||
120 | * @return string The action method name |
||
121 | */ |
||
122 | 3 | public function getMethodName() |
|
123 | { |
||
124 | 3 | return $this->methodName; |
|
125 | } |
||
126 | |||
127 | /** |
||
128 | * Sets the request methods the action is listening to. |
||
129 | * |
||
130 | * @param array $requestMethods The request methods |
||
131 | * |
||
132 | * @return void |
||
133 | */ |
||
134 | 6 | public function setRequestMethods(array $requestMethods) |
|
135 | { |
||
136 | 6 | $this->requestMethods = $requestMethods; |
|
137 | 6 | } |
|
138 | |||
139 | /** |
||
140 | * Returns the request methods the action is listening to. |
||
141 | * |
||
142 | * @return array The request methods |
||
143 | */ |
||
144 | 5 | public function getRequestMethods() |
|
145 | { |
||
146 | 5 | return $this->requestMethods; |
|
147 | } |
||
148 | |||
149 | /** |
||
150 | * Add's the passed key => value pair as restriction. |
||
151 | * |
||
152 | * @param string $name The parameter name to add the restriction for |
||
153 | * @param string $value The restriction value itself |
||
154 | * |
||
155 | * @return void |
||
156 | */ |
||
157 | public function addRestriction($name, $value) |
||
158 | { |
||
159 | $this->restrictions[$name] = $value; |
||
160 | } |
||
161 | |||
162 | /** |
||
163 | * Sets the restrictions for the route placeholders. |
||
164 | * |
||
165 | * @param array $restrictions The restrictions for the route placeholders |
||
166 | * |
||
167 | * @return void |
||
168 | */ |
||
169 | public function setRestrictions(array $restrictions) |
||
170 | { |
||
171 | $this->restrictions = $restrictions; |
||
172 | } |
||
173 | |||
174 | /** |
||
175 | * Returns the restrictions for the route placeholders. |
||
176 | * |
||
177 | * @return array The restrictions for the route placeholders |
||
178 | */ |
||
179 | public function getRestrictions() |
||
180 | { |
||
181 | return $this->restrictions; |
||
182 | } |
||
183 | |||
184 | /** |
||
185 | * Add's the passed key => value pair as default. |
||
186 | * |
||
187 | * @param string $name The parameter name to add the default for |
||
188 | * @param string $value The default value itself |
||
189 | * |
||
190 | * @return void |
||
191 | */ |
||
192 | public function addDefault($name, $value) |
||
193 | { |
||
194 | $this->defaults[$name] = $value; |
||
195 | } |
||
196 | |||
197 | /** |
||
198 | * Sets the defaults for the route placeholders. |
||
199 | * |
||
200 | * @param array $defaults The defaults for the route placeholders |
||
201 | * |
||
202 | * @return void |
||
203 | */ |
||
204 | public function setDefaults(array $defaults) |
||
205 | { |
||
206 | $this->defaults = $defaults; |
||
207 | } |
||
208 | |||
209 | /** |
||
210 | * Returns the defaults for the route placeholders. |
||
211 | * |
||
212 | * @return array The defaults for the route placeholders |
||
213 | */ |
||
214 | public function getDefaults() |
||
215 | { |
||
216 | return $this->defaults; |
||
217 | } |
||
218 | |||
219 | /** |
||
220 | * Returns a new descriptor instance. |
||
221 | * |
||
222 | * @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The descriptor instance |
||
223 | */ |
||
224 | 4 | public static function newDescriptorInstance() |
|
228 | |||
229 | /** |
||
230 | * Return's the array with the reqeust method => annotation class mapping. |
||
231 | * |
||
232 | * @return array The mapping |
||
233 | */ |
||
234 | 9 | protected function getMappedRequestMethods() |
|
235 | { |
||
236 | 9 | return $this->mappedRequestMethods; |
|
237 | } |
||
238 | |||
239 | /** |
||
240 | * Initializes the action configuration instance from the passed reflection method instance. |
||
241 | * |
||
242 | * @param \AppserverIo\Lang\Reflection\MethodInterface $reflectionMethod The reflection method with the action configuration |
||
243 | * |
||
244 | * @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor |
||
245 | */ |
||
246 | 8 | public function fromReflectionMethod(MethodInterface $reflectionMethod) |
|
311 | |||
312 | /** |
||
313 | * Initializes a action configuration instance from the passed deployment descriptor node. |
||
314 | * |
||
315 | * @param \SimpleXmlElement $node The deployment node with the action configuration |
||
316 | * |
||
317 | * @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor |
||
318 | */ |
||
319 | 1 | public function fromDeploymentDescriptor(\SimpleXmlElement $node) |
|
322 | |||
323 | /** |
||
324 | * Initializes a action configuration instance from the passed configuration node. |
||
325 | * |
||
326 | * @param \AppserverIo\Configuration\Interfaces\NodeInterface $node The configuration node with the action configuration |
||
327 | * |
||
328 | * @return \AppserverIo\Routlt\Description\ActionDescriptorInterface The initialized descriptor |
||
329 | */ |
||
330 | public function fromConfiguration(NodeInterface $node) |
||
333 | |||
334 | /** |
||
335 | * Merges the passed configuration into this one. Configuration values |
||
336 | * of the passed configuration will overwrite this one. |
||
337 | * |
||
338 | * @param \AppserverIo\Routlt\Description\ActionDescriptorInterface $actionDescriptor The configuration to merge |
||
339 | * |
||
340 | * @return void |
||
341 | * @throws \AppserverIo\Routlt\Description\DescriptorException Is thrown if the passed descriptor has a different method name |
||
342 | */ |
||
343 | 2 | public function merge(ActionDescriptorInterface $actionDescriptor) |
|
358 | } |
||
359 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.