1 | <?php |
||
26 | class Controller { |
||
27 | |||
28 | use \Aviat\Ion\Di\ContainerAware; |
||
29 | |||
30 | /** |
||
31 | * The global configuration object |
||
32 | * @var object $config |
||
33 | */ |
||
34 | protected $config; |
||
35 | |||
36 | /** |
||
37 | * Request object |
||
38 | * @var object $request |
||
39 | */ |
||
40 | protected $request; |
||
41 | |||
42 | /** |
||
43 | * Response object |
||
44 | * @var object $response |
||
45 | */ |
||
46 | protected $response; |
||
47 | |||
48 | /** |
||
49 | * The api model for the current controller |
||
50 | * @var object |
||
51 | */ |
||
52 | protected $model; |
||
53 | |||
54 | /** |
||
55 | * Url generatation class |
||
56 | * @var UrlGenerator |
||
57 | */ |
||
58 | protected $urlGenerator; |
||
59 | |||
60 | /** |
||
61 | * Session segment |
||
62 | * @var [type] |
||
63 | */ |
||
64 | protected $session; |
||
65 | |||
66 | /** |
||
67 | * Common data to be sent to views |
||
68 | * @var array |
||
69 | */ |
||
70 | protected $base_data = [ |
||
71 | 'url_type' => 'anime', |
||
72 | 'other_type' => 'manga', |
||
73 | 'menu_name' => '' |
||
74 | ]; |
||
75 | |||
76 | /** |
||
77 | * Constructor |
||
78 | * |
||
79 | * @param ContainerInterface $container |
||
80 | */ |
||
81 | public function __construct(ContainerInterface $container) |
||
108 | |||
109 | /** |
||
110 | * Redirect to the default controller/url from an empty path |
||
111 | */ |
||
112 | public function redirect_to_default() |
||
117 | |||
118 | /** |
||
119 | * Redirect to the previous page |
||
120 | * |
||
121 | * @return void |
||
122 | */ |
||
123 | public function redirect_to_previous() |
||
128 | |||
129 | /** |
||
130 | * Set the current url in the session as the target of a future redirect |
||
131 | * |
||
132 | * @param string|null $url |
||
133 | * @return void |
||
134 | */ |
||
135 | public function set_session_redirect($url = NULL) |
||
157 | |||
158 | /** |
||
159 | * Redirect to the url previously set in the session |
||
160 | * |
||
161 | * @return void |
||
162 | */ |
||
163 | public function session_redirect() |
||
176 | |||
177 | /** |
||
178 | * Get a class member |
||
179 | * |
||
180 | * @param string $key |
||
181 | * @return object |
||
182 | */ |
||
183 | public function __get($key) |
||
194 | |||
195 | /** |
||
196 | * Get the string output of a partial template |
||
197 | * |
||
198 | * @param HtmlView $view |
||
199 | * @param string $template |
||
200 | * @param array $data |
||
201 | * @return string |
||
202 | */ |
||
203 | protected function load_partial($view, $template, array $data = []) |
||
225 | |||
226 | /** |
||
227 | * Render a template with header and footer |
||
228 | * |
||
229 | * @param HtmlView $view |
||
230 | * @param string $template |
||
231 | * @param array $data |
||
232 | * @return void |
||
233 | */ |
||
234 | protected function render_full_page($view, $template, array $data) |
||
246 | |||
247 | /** |
||
248 | * Show the login form |
||
249 | * |
||
250 | * @codeCoverageIgnore |
||
251 | * @param string $status |
||
252 | * @return void |
||
253 | */ |
||
254 | public function login($status = "") |
||
273 | |||
274 | /** |
||
275 | * Attempt login authentication |
||
276 | * |
||
277 | * @return void |
||
278 | */ |
||
279 | public function login_action() |
||
290 | |||
291 | /** |
||
292 | * Deauthorize the current user |
||
293 | * |
||
294 | * @return void |
||
295 | */ |
||
296 | public function logout() |
||
303 | |||
304 | /** |
||
305 | * 404 action |
||
306 | * |
||
307 | * @return void |
||
308 | */ |
||
309 | public function not_found() |
||
315 | |||
316 | /** |
||
317 | * Display a generic error page |
||
318 | * |
||
319 | * @param int $http_code |
||
320 | * @param string $title |
||
321 | * @param string $message |
||
322 | * @param string $long_message |
||
323 | * @return void |
||
324 | */ |
||
325 | public function error_page($http_code, $title, $message, $long_message = "") |
||
333 | |||
334 | /** |
||
335 | * Set a session flash variable to display a message on |
||
336 | * next page load |
||
337 | * |
||
338 | * @param string $message |
||
339 | * @param string $type |
||
340 | * @return void |
||
341 | */ |
||
342 | public function set_flash_message($message, $type = "info") |
||
349 | |||
350 | /** |
||
351 | * Add a message box to the page |
||
352 | * |
||
353 | * @codeCoverageIgnore |
||
354 | * @param HtmlView $view |
||
355 | * @param string $type |
||
356 | * @param string $message |
||
357 | * @return string |
||
358 | */ |
||
359 | protected function show_message($view, $type, $message) |
||
366 | |||
367 | /** |
||
368 | * Output a template to HTML, using the provided data |
||
369 | * |
||
370 | * @param string $template |
||
371 | * @param array $data |
||
372 | * @param HtmlView|null $view |
||
373 | * @param int $code |
||
374 | * @return void |
||
375 | */ |
||
376 | protected function outputHTML($template, array $data = [], $view = NULL, $code = 200) |
||
386 | |||
387 | /** |
||
388 | * Output a JSON Response |
||
389 | * |
||
390 | * @param mixed $data |
||
391 | * @param int $code - the http status code |
||
392 | * @return void |
||
393 | */ |
||
394 | protected function outputJSON($data = [], $code = 200) |
||
400 | |||
401 | /** |
||
402 | * Redirect to the selected page |
||
403 | * |
||
404 | * @param string $url |
||
405 | * @param int $code |
||
406 | * @return void |
||
407 | */ |
||
408 | protected function redirect($url, $code) |
||
413 | } |
||
414 | // End of BaseController.php |