1 | <?php |
||
27 | class Controller { |
||
28 | |||
29 | use \Aviat\Ion\Di\ContainerAware; |
||
30 | |||
31 | /** |
||
32 | * The global configuration object |
||
33 | * @var object $config |
||
34 | */ |
||
35 | protected $config; |
||
36 | |||
37 | /** |
||
38 | * Request object |
||
39 | * @var object $request |
||
40 | */ |
||
41 | protected $request; |
||
42 | |||
43 | /** |
||
44 | * Response object |
||
45 | * @var object $response |
||
46 | */ |
||
47 | protected $response; |
||
48 | |||
49 | /** |
||
50 | * The api model for the current controller |
||
51 | * @var object |
||
52 | */ |
||
53 | protected $model; |
||
54 | |||
55 | /** |
||
56 | * Url generatation class |
||
57 | * @var UrlGenerator |
||
58 | */ |
||
59 | protected $urlGenerator; |
||
60 | |||
61 | /** |
||
62 | * Session segment |
||
63 | * @var [type] |
||
64 | */ |
||
65 | protected $session; |
||
66 | |||
67 | /** |
||
68 | * Common data to be sent to views |
||
69 | * @var array |
||
70 | */ |
||
71 | protected $base_data = [ |
||
72 | 'url_type' => 'anime', |
||
73 | 'other_type' => 'manga', |
||
74 | 'menu_name' => '' |
||
75 | ]; |
||
76 | |||
77 | /** |
||
78 | * Constructor |
||
79 | * |
||
80 | * @param ContainerInterface $container |
||
81 | */ |
||
82 | public function __construct(ContainerInterface $container) |
||
103 | |||
104 | /** |
||
105 | * Redirect to the default controller/url from an empty path |
||
106 | */ |
||
107 | public function redirect_to_default() |
||
112 | |||
113 | /** |
||
114 | * Redirect to the previous page |
||
115 | * |
||
116 | * @return void |
||
117 | */ |
||
118 | public function redirect_to_previous() |
||
123 | |||
124 | /** |
||
125 | * Set the current url in the session as the target of a future redirect |
||
126 | * |
||
127 | * @param string|null $url |
||
128 | * @return void |
||
129 | */ |
||
130 | public function set_session_redirect($url=NULL) |
||
152 | |||
153 | /** |
||
154 | * Redirect to the url previously set in the session |
||
155 | * |
||
156 | * @return void |
||
157 | */ |
||
158 | public function session_redirect() |
||
171 | |||
172 | /** |
||
173 | * Get a class member |
||
174 | * |
||
175 | * @param string $key |
||
176 | * @return object |
||
177 | */ |
||
178 | public function __get($key) |
||
189 | |||
190 | /** |
||
191 | * Get the string output of a partial template |
||
192 | * |
||
193 | * @param HtmlView $view |
||
194 | * @param string $template |
||
195 | * @param array $data |
||
196 | * @return string |
||
197 | */ |
||
198 | protected function load_partial($view, $template, array $data = []) |
||
222 | |||
223 | /** |
||
224 | * Render a template with header and footer |
||
225 | * |
||
226 | * @param HtmlView $view |
||
227 | * @param string $template |
||
228 | * @param array $data |
||
229 | * @return void |
||
230 | */ |
||
231 | protected function render_full_page($view, $template, array $data) |
||
243 | |||
244 | /** |
||
245 | * Show the login form |
||
246 | * |
||
247 | * @codeCoverageIgnore |
||
248 | * @param string $status |
||
249 | * @return void |
||
250 | */ |
||
251 | public function login($status = "") |
||
270 | |||
271 | /** |
||
272 | * Attempt login authentication |
||
273 | * |
||
274 | * @return void |
||
275 | */ |
||
276 | public function login_action() |
||
286 | |||
287 | /** |
||
288 | * Deauthorize the current user |
||
289 | * |
||
290 | * @return void |
||
291 | */ |
||
292 | public function logout() |
||
299 | |||
300 | /** |
||
301 | * 404 action |
||
302 | * |
||
303 | * @return void |
||
304 | */ |
||
305 | public function not_found() |
||
311 | |||
312 | /** |
||
313 | * Set a session flash variable to display a message on |
||
314 | * next page load |
||
315 | * |
||
316 | * @param string $message |
||
317 | * @param string $type |
||
318 | * @return void |
||
319 | */ |
||
320 | public function set_flash_message($message, $type="info") |
||
327 | |||
328 | /** |
||
329 | * Add a message box to the page |
||
330 | * |
||
331 | * @codeCoverageIgnore |
||
332 | * @param HtmlView $view |
||
333 | * @param string $type |
||
334 | * @param string $message |
||
335 | * @return string |
||
336 | */ |
||
337 | protected function show_message($view, $type, $message) |
||
344 | |||
345 | /** |
||
346 | * Output a template to HTML, using the provided data |
||
347 | * |
||
348 | * @param string $template |
||
349 | * @param array $data |
||
350 | * @param HtmlView|null $view |
||
351 | * @return void |
||
352 | */ |
||
353 | protected function outputHTML($template, array $data = [], $view = NULL) |
||
362 | |||
363 | /** |
||
364 | * Output a JSON Response |
||
365 | * |
||
366 | * @param mixed $data |
||
367 | * @return void |
||
368 | */ |
||
369 | protected function outputJSON($data = []) |
||
374 | |||
375 | /** |
||
376 | * Redirect to the selected page |
||
377 | * |
||
378 | * @param string $url |
||
379 | * @param int $code |
||
380 | * @return void |
||
381 | */ |
||
382 | protected function redirect($url, $code) |
||
387 | } |
||
388 | // End of BaseController.php |