1 | <?php |
||
22 | abstract class AbstractController |
||
23 | { |
||
24 | |||
25 | /** |
||
26 | * Class of controller |
||
27 | * |
||
28 | * @var string |
||
29 | */ |
||
30 | private $controllerClass = ''; |
||
31 | |||
32 | /** |
||
33 | * Name of controller |
||
34 | * |
||
35 | * @var string |
||
36 | */ |
||
37 | private $controllerName = ''; |
||
38 | |||
39 | /** |
||
40 | * List of actions provided by controller |
||
41 | * |
||
42 | * @var array |
||
43 | */ |
||
44 | private $actions = null; |
||
45 | |||
46 | /** |
||
47 | * Request |
||
48 | * |
||
49 | * @var \Nkey\Caribu\Mvc\Controller\Request |
||
50 | */ |
||
51 | private $request; |
||
52 | |||
53 | /** |
||
54 | * Response |
||
55 | * |
||
56 | * @var \Nkey\Caribu\Mvc\Controller\Response |
||
57 | */ |
||
58 | protected $response; |
||
59 | |||
60 | /** |
||
61 | * View parameters |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $viewParams = array(); |
||
66 | |||
67 | /** |
||
68 | * Parse the parameters of action |
||
69 | * |
||
70 | * @param \ReflectionMethod $action |
||
71 | * |
||
72 | * @return boolean true if parameters meets conditions for a valid action method, false otherwise |
||
73 | */ |
||
74 | 29 | private function parseParameters(\ReflectionMethod $action) |
|
89 | |||
90 | /** |
||
91 | * Parse the settings out of annotations |
||
92 | * |
||
93 | * @param \ReflectionMethod $action |
||
94 | */ |
||
95 | 29 | private function parseAnnotations(\ReflectionMethod $action) |
|
115 | |||
116 | /** |
||
117 | * Get the controller prepared for service |
||
118 | * |
||
119 | * @return \Nkey\Caribu\Mvc\Controller\AbstractController The controller instance |
||
120 | */ |
||
121 | 29 | final public function getControllerSettings() |
|
138 | |||
139 | /** |
||
140 | * Checks whether controller has specific action |
||
141 | * |
||
142 | * @param string $action |
||
143 | * Name of action to search for |
||
144 | * |
||
145 | * @return boolean true if the action exists in controller, false otherwise |
||
146 | */ |
||
147 | 19 | final public function hasAction($action) |
|
151 | |||
152 | /** |
||
153 | * Call the action |
||
154 | * |
||
155 | * @param string $action |
||
156 | * The name of action to call in controller |
||
157 | * |
||
158 | * @return \Nkey\Caribu\Mvc\Controller\Response The response |
||
159 | */ |
||
160 | 20 | final public function call($action, Request $request, View $view) |
|
187 | |||
188 | /** |
||
189 | * Retrieve the simple name of controller |
||
190 | * |
||
191 | * @return string Name of controller |
||
192 | */ |
||
193 | 29 | final public function getControllerSimpleName() |
|
197 | |||
198 | /** |
||
199 | * Add the controls injected into view parameters |
||
200 | * |
||
201 | * @param Response $response |
||
202 | * The response rendered with controls |
||
203 | * @param Request $request |
||
204 | * The request |
||
205 | * @param View $view |
||
206 | * The View instance to use for rendering |
||
207 | */ |
||
208 | 20 | protected function addControls(Response &$response, Request $request, View $view) |
|
232 | |||
233 | /** |
||
234 | * Redirects the current request to another site |
||
235 | * |
||
236 | * @param string $controller |
||
237 | * The name of Controller to |
||
238 | * @param string $action |
||
239 | */ |
||
240 | protected function redirect($controller = null, $action = null) |
||
252 | } |
||
253 |
An exit expression should only be used in rare cases. For example, if you write a short command line script.
In most cases however, using an
exit
expression makes the code untestable and often causes incompatibilities with other libraries. Thus, unless you are absolutely sure it is required here, we recommend to refactor your code to avoid its usage.