1 | <?php |
||
11 | trait RouteAction |
||
12 | { |
||
13 | /** |
||
14 | * @var boolean |
||
15 | */ |
||
16 | protected $actionCancelled = false; |
||
17 | |||
18 | |||
19 | /** |
||
20 | * Get request, set for controller |
||
21 | * |
||
22 | * @return ServerRequestInterface |
||
23 | */ |
||
24 | abstract public function getRequest(); |
||
25 | |||
26 | /** |
||
27 | * Get response. set for controller |
||
28 | * |
||
29 | * @return ResponseInterface |
||
30 | */ |
||
31 | abstract public function getResponse(); |
||
32 | |||
33 | /** |
||
34 | * Respond with a server error |
||
35 | * |
||
36 | * @param string $message |
||
37 | * @param int $code HTTP status code |
||
38 | */ |
||
39 | abstract public function notFound($message = '', $code = 404); |
||
40 | |||
41 | |||
42 | /** |
||
43 | * Get the route |
||
44 | * |
||
45 | * @return \stdClass |
||
46 | */ |
||
47 | 13 | protected function getRoute() |
|
66 | |||
67 | /** |
||
68 | * Get the method name of the action |
||
69 | * |
||
70 | * @param string $action |
||
71 | * @return string |
||
72 | */ |
||
73 | 11 | protected function getActionMethod($action) |
|
77 | |||
78 | /** |
||
79 | * Called before executing the action. |
||
80 | * @codeCoverageIgnore |
||
81 | * |
||
82 | * <code> |
||
83 | * protected function beforeAction() |
||
84 | * { |
||
85 | * $this->respondWith('json'); // Respond with JSON by default |
||
86 | * |
||
87 | * if ($this->auth->getUser()->getCredits() <= 0) { |
||
88 | * $this->paymentRequired(); |
||
89 | * } |
||
90 | * } |
||
91 | * </code> |
||
92 | */ |
||
93 | protected function before() |
||
96 | |||
97 | /** |
||
98 | * Called before executing the action. |
||
99 | * @codeCoverageIgnore |
||
100 | */ |
||
101 | protected function after() |
||
104 | |||
105 | /** |
||
106 | * Cancel the action |
||
107 | * |
||
108 | * @return boolean |
||
109 | */ |
||
110 | 1 | public function cancel() |
|
114 | |||
115 | /** |
||
116 | * Check if the action is cancelled |
||
117 | * |
||
118 | * @return boolean |
||
119 | */ |
||
120 | 10 | public function isCancelled() |
|
124 | |||
125 | /** |
||
126 | * Run the controller |
||
127 | * |
||
128 | * @return ResponseInterface |
||
129 | */ |
||
130 | 13 | public function run() |
|
150 | |||
151 | /** |
||
152 | * Get the arguments for a function from a route using reflection |
||
153 | * |
||
154 | * @param object $route |
||
155 | * @param \ReflectionFunctionAbstract $refl |
||
156 | * @return array |
||
157 | */ |
||
158 | 6 | protected function getFunctionArgs($route, \ReflectionFunctionAbstract $refl) |
|
182 | } |
||
183 | |||
184 |
For interface and abstract methods, it is impossible to infer the return type from the immediate code. In these cases, it is generally advisible to explicitly annotate these methods with a
@return
doc comment to communicate to implementors of these methods what they are expected to return.