2016-10-20 22:09:36 -04:00
|
|
|
<?php declare(strict_types=1);
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
2015-11-16 11:40:01 -05:00
|
|
|
* Hummingbird Anime Client
|
|
|
|
*
|
|
|
|
* An API client for Hummingbird to manage anime and manga watch lists
|
|
|
|
*
|
2016-10-20 22:09:36 -04:00
|
|
|
* PHP version 7
|
2016-08-30 10:01:18 -04:00
|
|
|
*
|
2015-11-16 11:40:01 -05:00
|
|
|
* @package HummingbirdAnimeClient
|
2016-08-30 10:01:18 -04:00
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
|
|
* @copyright 2015 - 2016 Timothy J. Warren
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
|
|
* @version 3.1
|
2015-11-16 11:40:01 -05:00
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient
|
2015-06-16 11:11:35 -04:00
|
|
|
*/
|
2016-10-20 22:09:36 -04:00
|
|
|
|
2015-09-15 13:19:29 -04:00
|
|
|
namespace Aviat\AnimeClient;
|
2015-06-24 16:01:35 -04:00
|
|
|
|
2017-02-08 15:48:20 -05:00
|
|
|
use const Aviat\AnimeClient\SESSION_SEGMENT;
|
|
|
|
|
2016-12-20 12:58:37 -05:00
|
|
|
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
|
|
|
|
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
|
2016-10-20 22:09:36 -04:00
|
|
|
use InvalidArgumentException;
|
2015-09-17 23:11:18 -04:00
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
2015-09-17 23:11:18 -04:00
|
|
|
* Controller base, defines output methods
|
2015-10-06 10:44:33 -04:00
|
|
|
*
|
|
|
|
* @property Response object $response
|
2015-06-11 16:44:52 -04:00
|
|
|
*/
|
2015-09-14 10:54:50 -04:00
|
|
|
class Controller {
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2016-10-20 22:09:36 -04:00
|
|
|
use ContainerAware;
|
2015-09-17 23:11:18 -04:00
|
|
|
|
2016-04-21 11:14:21 -04:00
|
|
|
/**
|
|
|
|
* Cache manager
|
|
|
|
* @var \Aviat\Ion\Cache\CacheInterface
|
|
|
|
*/
|
|
|
|
protected $cache;
|
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
|
|
|
* The global configuration object
|
2016-07-27 14:32:37 -04:00
|
|
|
* @var Aviat\Ion\ConfigInterface $config
|
2015-06-11 16:44:52 -04:00
|
|
|
*/
|
2015-06-09 18:18:53 -04:00
|
|
|
protected $config;
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2015-10-06 11:38:20 -04:00
|
|
|
/**
|
|
|
|
* Request object
|
|
|
|
* @var object $request
|
|
|
|
*/
|
|
|
|
protected $request;
|
|
|
|
|
2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* Response object
|
|
|
|
* @var object $response
|
|
|
|
*/
|
|
|
|
protected $response;
|
|
|
|
|
2015-06-26 16:39:10 -04:00
|
|
|
/**
|
|
|
|
* The api model for the current controller
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
protected $model;
|
|
|
|
|
2015-09-14 15:49:20 -04:00
|
|
|
/**
|
2016-08-30 10:57:41 -04:00
|
|
|
* Url generation class
|
2015-09-14 15:49:20 -04:00
|
|
|
* @var UrlGenerator
|
|
|
|
*/
|
|
|
|
protected $urlGenerator;
|
|
|
|
|
2016-01-04 10:53:03 -05:00
|
|
|
/**
|
|
|
|
* Session segment
|
|
|
|
* @var [type]
|
|
|
|
*/
|
|
|
|
protected $session;
|
|
|
|
|
2015-06-26 16:39:10 -04:00
|
|
|
/**
|
|
|
|
* Common data to be sent to views
|
|
|
|
* @var array
|
|
|
|
*/
|
2017-02-15 11:30:16 -05:00
|
|
|
protected $baseData = [
|
2015-06-30 13:03:20 -04:00
|
|
|
'url_type' => 'anime',
|
|
|
|
'other_type' => 'manga',
|
2015-10-09 14:34:55 -04:00
|
|
|
'menu_name' => ''
|
2015-06-30 13:03:20 -04:00
|
|
|
];
|
2015-06-26 16:39:10 -04:00
|
|
|
|
2015-06-11 16:44:52 -04:00
|
|
|
/**
|
|
|
|
* Constructor
|
2015-06-30 13:03:20 -04:00
|
|
|
*
|
2015-10-06 10:24:48 -04:00
|
|
|
* @param ContainerInterface $container
|
2015-06-11 16:44:52 -04:00
|
|
|
*/
|
2015-09-17 23:11:18 -04:00
|
|
|
public function __construct(ContainerInterface $container)
|
2015-05-22 12:36:26 -04:00
|
|
|
{
|
2015-09-17 23:11:18 -04:00
|
|
|
$this->setContainer($container);
|
2016-03-03 16:53:17 -05:00
|
|
|
$auraUrlGenerator = $container->get('aura-router')->getGenerator();
|
2015-09-17 23:11:18 -04:00
|
|
|
$urlGenerator = $container->get('url-generator');
|
2016-04-21 11:14:21 -04:00
|
|
|
$this->cache = $container->get('cache');
|
2015-09-14 10:54:50 -04:00
|
|
|
$this->config = $container->get('config');
|
|
|
|
$this->request = $container->get('request');
|
|
|
|
$this->response = $container->get('response');
|
2017-02-15 11:30:16 -05:00
|
|
|
$this->baseData['url'] = $auraUrlGenerator;
|
|
|
|
$this->baseData['urlGenerator'] = $urlGenerator;
|
|
|
|
$this->baseData['auth'] = $container->get('auth');
|
|
|
|
$this->baseData['config'] = $this->config;
|
2015-09-17 23:11:18 -04:00
|
|
|
$this->urlGenerator = $urlGenerator;
|
2016-01-04 10:53:03 -05:00
|
|
|
|
|
|
|
$session = $container->get('session');
|
2017-02-08 15:48:20 -05:00
|
|
|
$this->session = $session->getSegment(SESSION_SEGMENT);
|
2016-01-04 10:53:03 -05:00
|
|
|
|
|
|
|
// Set a 'previous' flash value for better redirects
|
2016-02-17 11:36:37 -05:00
|
|
|
$server_params = $this->request->getServerParams();
|
|
|
|
if (array_key_exists('HTTP_REFERER', $server_params))
|
|
|
|
{
|
|
|
|
$this->session->setFlash('previous', $server_params['HTTP_REFERER']);
|
|
|
|
}
|
2016-01-04 10:53:03 -05:00
|
|
|
|
|
|
|
// Set a message box if available
|
2017-02-15 11:30:16 -05:00
|
|
|
$this->baseData['message'] = $this->session->getFlash('message');
|
2015-05-22 12:36:26 -04:00
|
|
|
}
|
|
|
|
|
2015-10-20 16:41:51 -04:00
|
|
|
/**
|
|
|
|
* Redirect to the default controller/url from an empty path
|
2016-08-30 10:57:41 -04:00
|
|
|
*
|
|
|
|
* @return void
|
2015-10-20 16:41:51 -04:00
|
|
|
*/
|
2017-01-06 21:39:01 -05:00
|
|
|
public function redirectToDefaultRoute()
|
2015-10-20 16:41:51 -04:00
|
|
|
{
|
2016-01-06 11:08:56 -05:00
|
|
|
$default_type = $this->config->get(['routes', 'route_config', 'default_list']);
|
2017-02-15 15:56:10 -05:00
|
|
|
$this->redirect($this->urlGenerator->defaultUrl($default_type), 303);
|
2015-10-20 16:41:51 -04:00
|
|
|
}
|
|
|
|
|
2016-01-04 10:53:03 -05:00
|
|
|
/**
|
|
|
|
* Redirect to the previous page
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function redirect_to_previous()
|
|
|
|
{
|
|
|
|
$previous = $this->session->getFlash('previous');
|
|
|
|
$this->redirect($previous, 303);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the current url in the session as the target of a future redirect
|
|
|
|
*
|
|
|
|
* @param string|null $url
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-01-04 11:15:25 -05:00
|
|
|
public function set_session_redirect($url = NULL)
|
2016-01-04 10:53:03 -05:00
|
|
|
{
|
2016-04-19 13:23:49 -04:00
|
|
|
$server_params = $this->request->getServerParams();
|
|
|
|
|
|
|
|
if ( ! array_key_exists('HTTP_REFERER', $server_params))
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-27 14:32:37 -04:00
|
|
|
$util = $this->container->get('util');
|
2016-08-30 10:57:41 -04:00
|
|
|
$double_form_page = $server_params['HTTP_REFERER'] === $this->request->getUri();
|
2016-01-04 10:53:03 -05:00
|
|
|
|
|
|
|
// Don't attempt to set the redirect url if
|
|
|
|
// the page is one of the form type pages,
|
|
|
|
// and the previous page is also a form type page_segments
|
|
|
|
if ($double_form_page)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (is_null($url))
|
|
|
|
{
|
2016-10-20 22:09:36 -04:00
|
|
|
$url = $util->is_view_page()
|
2016-01-04 10:53:03 -05:00
|
|
|
? $this->request->url->get()
|
2016-04-19 13:23:49 -04:00
|
|
|
: $server_params['HTTP_REFERER'];
|
2016-01-04 10:53:03 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
$this->session->set('redirect_url', $url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirect to the url previously set in the session
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function session_redirect()
|
|
|
|
{
|
|
|
|
$target = $this->session->get('redirect_url');
|
|
|
|
if (empty($target))
|
|
|
|
{
|
2016-12-20 12:58:37 -05:00
|
|
|
$this->notFound();
|
2016-01-04 10:53:03 -05:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$this->redirect($target, 303);
|
|
|
|
$this->session->set('redirect_url', NULL);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-07-02 14:04:04 -04:00
|
|
|
/**
|
|
|
|
* Get a class member
|
|
|
|
*
|
|
|
|
* @param string $key
|
2016-10-20 22:09:36 -04:00
|
|
|
* @return mixed
|
2015-07-02 14:04:04 -04:00
|
|
|
*/
|
2016-10-20 22:09:36 -04:00
|
|
|
public function __get(string $key)
|
2015-07-02 14:04:04 -04:00
|
|
|
{
|
2015-09-17 23:11:18 -04:00
|
|
|
$allowed = ['response', 'config'];
|
2015-07-02 14:04:04 -04:00
|
|
|
|
|
|
|
if (in_array($key, $allowed))
|
|
|
|
{
|
|
|
|
return $this->$key;
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2015-05-22 12:36:26 -04:00
|
|
|
/**
|
2015-06-24 16:01:35 -04:00
|
|
|
* Get the string output of a partial template
|
2015-05-22 12:36:26 -04:00
|
|
|
*
|
2015-10-06 11:38:20 -04:00
|
|
|
* @param HtmlView $view
|
2015-05-22 12:36:26 -04:00
|
|
|
* @param string $template
|
2015-10-06 12:15:19 -04:00
|
|
|
* @param array $data
|
2016-10-20 22:09:36 -04:00
|
|
|
* @throws InvalidArgumentException
|
2015-06-24 16:01:35 -04:00
|
|
|
* @return string
|
2015-05-22 12:36:26 -04:00
|
|
|
*/
|
2015-11-04 16:36:54 -05:00
|
|
|
protected function load_partial($view, $template, array $data = [])
|
2015-05-22 12:36:26 -04:00
|
|
|
{
|
2015-10-09 14:34:55 -04:00
|
|
|
$router = $this->container->get('dispatcher');
|
2015-09-17 23:11:18 -04:00
|
|
|
|
2017-02-15 11:30:16 -05:00
|
|
|
if (isset($this->baseData))
|
2015-06-24 16:01:35 -04:00
|
|
|
{
|
2017-02-15 11:30:16 -05:00
|
|
|
$data = array_merge($this->baseData, $data);
|
2015-06-24 16:01:35 -04:00
|
|
|
}
|
|
|
|
|
2016-12-20 12:58:37 -05:00
|
|
|
$route = $router->getRoute();
|
|
|
|
$data['route_path'] = $route ? $router->getRoute()->path : '';
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2015-10-05 16:54:25 -04:00
|
|
|
|
2015-10-06 11:38:20 -04:00
|
|
|
$template_path = _dir($this->config->get('view_path'), "{$template}.php");
|
2015-06-16 11:11:35 -04:00
|
|
|
|
|
|
|
if ( ! is_file($template_path))
|
2015-05-22 12:36:26 -04:00
|
|
|
{
|
2016-10-20 22:09:36 -04:00
|
|
|
throw new InvalidArgumentException("Invalid template : {$template}");
|
2015-05-22 12:36:26 -04:00
|
|
|
}
|
|
|
|
|
2016-10-20 22:09:36 -04:00
|
|
|
return $view->renderTemplate($template_path, (array)$data);
|
2015-09-17 23:11:18 -04:00
|
|
|
}
|
2015-05-22 12:36:26 -04:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
/**
|
|
|
|
* Render a template with header and footer
|
|
|
|
*
|
2015-10-06 10:24:48 -04:00
|
|
|
* @param HtmlView $view
|
2015-09-17 23:11:18 -04:00
|
|
|
* @param string $template
|
2015-10-09 14:34:55 -04:00
|
|
|
* @param array $data
|
2015-09-17 23:11:18 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2015-11-04 16:36:54 -05:00
|
|
|
protected function render_full_page($view, $template, array $data)
|
2015-09-17 23:11:18 -04:00
|
|
|
{
|
|
|
|
$view->appendOutput($this->load_partial($view, 'header', $data));
|
2016-01-04 10:53:03 -05:00
|
|
|
|
|
|
|
if (array_key_exists('message', $data) && is_array($data['message']))
|
|
|
|
{
|
|
|
|
$view->appendOutput($this->load_partial($view, 'message', $data['message']));
|
|
|
|
}
|
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
$view->appendOutput($this->load_partial($view, $template, $data));
|
|
|
|
$view->appendOutput($this->load_partial($view, 'footer', $data));
|
2015-06-24 16:01:35 -04:00
|
|
|
}
|
|
|
|
|
2015-11-04 16:36:54 -05:00
|
|
|
/**
|
|
|
|
* Show the login form
|
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
* @param string $status
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-10-20 22:09:36 -04:00
|
|
|
public function login(string $status = '')
|
2015-11-04 16:36:54 -05:00
|
|
|
{
|
2016-10-20 22:09:36 -04:00
|
|
|
$message = '';
|
2015-11-04 16:36:54 -05:00
|
|
|
|
|
|
|
$view = new HtmlView($this->container);
|
|
|
|
|
2016-10-20 22:09:36 -04:00
|
|
|
if ($status !== '')
|
2015-11-04 16:36:54 -05:00
|
|
|
{
|
|
|
|
$message = $this->show_message($view, 'error', $status);
|
|
|
|
}
|
|
|
|
|
2016-01-04 10:53:03 -05:00
|
|
|
// Set the redirect url
|
|
|
|
$this->set_session_redirect();
|
|
|
|
|
2015-11-04 16:36:54 -05:00
|
|
|
$this->outputHTML('login', [
|
|
|
|
'title' => 'Api login',
|
|
|
|
'message' => $message
|
|
|
|
], $view);
|
|
|
|
}
|
|
|
|
|
2015-11-13 11:33:27 -05:00
|
|
|
/**
|
|
|
|
* Attempt login authentication
|
|
|
|
*
|
2015-11-18 10:48:05 -05:00
|
|
|
* @return void
|
2015-11-13 11:33:27 -05:00
|
|
|
*/
|
2016-12-20 12:58:37 -05:00
|
|
|
public function loginAction()
|
2015-11-13 11:33:27 -05:00
|
|
|
{
|
|
|
|
$auth = $this->container->get('auth');
|
2016-02-17 11:36:37 -05:00
|
|
|
$post = $this->request->getParsedBody();
|
|
|
|
if ($auth->authenticate($post['password']))
|
2015-11-13 11:33:27 -05:00
|
|
|
{
|
2016-01-04 10:53:03 -05:00
|
|
|
return $this->session_redirect();
|
2015-11-13 11:33:27 -05:00
|
|
|
}
|
|
|
|
|
2017-01-12 15:41:20 -05:00
|
|
|
$this->set_flash_message('Invalid username or password.');
|
|
|
|
$this->redirect($this->urlGenerator->url('login'), 303);
|
2015-11-13 11:33:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Deauthorize the current user
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function logout()
|
|
|
|
{
|
|
|
|
$auth = $this->container->get('auth');
|
|
|
|
$auth->logout();
|
|
|
|
|
2017-01-06 21:39:01 -05:00
|
|
|
$this->redirectToDefaultRoute();
|
2015-11-13 11:33:27 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 404 action
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-20 12:58:37 -05:00
|
|
|
public function notFound()
|
2015-11-13 11:33:27 -05:00
|
|
|
{
|
|
|
|
$this->outputHTML('404', [
|
|
|
|
'title' => 'Sorry, page not found'
|
2016-01-07 20:48:18 -05:00
|
|
|
], NULL, 404);
|
2015-11-13 11:33:27 -05:00
|
|
|
}
|
|
|
|
|
2016-01-06 11:08:56 -05:00
|
|
|
/**
|
|
|
|
* Display a generic error page
|
|
|
|
*
|
2017-02-15 11:30:16 -05:00
|
|
|
* @param int $httpCode
|
2016-01-06 11:08:56 -05:00
|
|
|
* @param string $title
|
|
|
|
* @param string $message
|
|
|
|
* @param string $long_message
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-02-15 11:30:16 -05:00
|
|
|
public function errorPage($httpCode, $title, $message, $long_message = "")
|
2016-01-06 11:08:56 -05:00
|
|
|
{
|
|
|
|
$this->outputHTML('error', [
|
|
|
|
'title' => $title,
|
|
|
|
'message' => $message,
|
|
|
|
'long_message' => $long_message
|
2017-02-15 11:30:16 -05:00
|
|
|
], NULL, $httpCode);
|
2016-01-06 11:08:56 -05:00
|
|
|
}
|
|
|
|
|
2016-01-04 10:53:03 -05:00
|
|
|
/**
|
|
|
|
* Set a session flash variable to display a message on
|
|
|
|
* next page load
|
|
|
|
*
|
|
|
|
* @param string $message
|
|
|
|
* @param string $type
|
|
|
|
* @return void
|
|
|
|
*/
|
2017-01-06 21:39:01 -05:00
|
|
|
public function set_flash_message($message, $type = "info")
|
2016-01-04 10:53:03 -05:00
|
|
|
{
|
|
|
|
$this->session->setFlash('message', [
|
|
|
|
'message_type' => $type,
|
|
|
|
'message' => $message
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2016-04-21 11:14:21 -04:00
|
|
|
/**
|
|
|
|
* Purges the API cache
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2016-12-20 12:58:37 -05:00
|
|
|
public function clearCache()
|
2016-04-21 11:14:21 -04:00
|
|
|
{
|
2017-01-16 11:26:19 -05:00
|
|
|
$this->cache->clear();
|
2016-04-21 11:14:21 -04:00
|
|
|
$this->outputHTML('blank', [
|
|
|
|
'title' => 'Cache cleared'
|
|
|
|
], NULL, 200);
|
|
|
|
}
|
|
|
|
|
2015-11-04 16:36:54 -05:00
|
|
|
/**
|
|
|
|
* Add a message box to the page
|
|
|
|
*
|
|
|
|
* @codeCoverageIgnore
|
|
|
|
* @param HtmlView $view
|
|
|
|
* @param string $type
|
|
|
|
* @param string $message
|
|
|
|
* @return string
|
|
|
|
*/
|
2016-12-20 12:58:37 -05:00
|
|
|
protected function showMessage($view, $type, $message)
|
2015-11-04 16:36:54 -05:00
|
|
|
{
|
|
|
|
return $this->load_partial($view, 'message', [
|
2016-01-04 10:53:03 -05:00
|
|
|
'message_type' => $type,
|
2015-11-04 16:36:54 -05:00
|
|
|
'message' => $message
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2015-06-24 16:01:35 -04:00
|
|
|
/**
|
|
|
|
* Output a template to HTML, using the provided data
|
|
|
|
*
|
|
|
|
* @param string $template
|
2015-10-09 14:34:55 -04:00
|
|
|
* @param array $data
|
2015-11-04 16:53:22 -05:00
|
|
|
* @param HtmlView|null $view
|
2016-01-07 20:48:18 -05:00
|
|
|
* @param int $code
|
2015-06-24 16:01:35 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2016-01-07 20:48:18 -05:00
|
|
|
protected function outputHTML($template, array $data = [], $view = NULL, $code = 200)
|
2015-06-24 16:01:35 -04:00
|
|
|
{
|
2015-11-04 16:36:54 -05:00
|
|
|
if (is_null($view))
|
|
|
|
{
|
|
|
|
$view = new HtmlView($this->container);
|
|
|
|
}
|
|
|
|
|
2016-01-07 20:48:18 -05:00
|
|
|
$view->setStatusCode($code);
|
2015-09-17 23:11:18 -04:00
|
|
|
$this->render_full_page($view, $template, $data);
|
|
|
|
}
|
2015-06-24 16:01:35 -04:00
|
|
|
|
2015-09-17 23:11:18 -04:00
|
|
|
/**
|
|
|
|
* Output a JSON Response
|
|
|
|
*
|
|
|
|
* @param mixed $data
|
2016-02-02 11:34:03 -05:00
|
|
|
* @param int $code - the http status code
|
2015-09-17 23:11:18 -04:00
|
|
|
* @return void
|
|
|
|
*/
|
2017-01-06 21:39:01 -05:00
|
|
|
protected function outputJSON($data = 'Empty response', int $code = 200)
|
2015-09-17 23:11:18 -04:00
|
|
|
{
|
2017-01-06 21:39:01 -05:00
|
|
|
(new JsonView($this->container))
|
|
|
|
->setStatusCode($code)
|
|
|
|
->setOutput($data)
|
|
|
|
->send();
|
2015-05-22 12:36:26 -04:00
|
|
|
}
|
|
|
|
|
2015-06-16 11:11:35 -04:00
|
|
|
/**
|
|
|
|
* Redirect to the selected page
|
|
|
|
*
|
2015-10-20 16:41:51 -04:00
|
|
|
* @param string $url
|
2015-06-16 11:11:35 -04:00
|
|
|
* @param int $code
|
|
|
|
* @return void
|
|
|
|
*/
|
2015-11-04 16:36:54 -05:00
|
|
|
protected function redirect($url, $code)
|
2015-06-16 11:11:35 -04:00
|
|
|
{
|
2015-09-17 23:11:18 -04:00
|
|
|
$http = new HttpView($this->container);
|
|
|
|
$http->redirect($url, $code);
|
2015-06-24 16:01:35 -04:00
|
|
|
}
|
2015-06-11 16:44:52 -04:00
|
|
|
}
|
2015-09-15 13:19:29 -04:00
|
|
|
// End of BaseController.php
|