Simplify/clean up some base classes
This commit is contained in:
parent
59403b9cb5
commit
0503cad15f
@ -20,7 +20,7 @@
|
|||||||
<log type="coverage-clover" target="logs/clover.xml"/>
|
<log type="coverage-clover" target="logs/clover.xml"/>
|
||||||
<log type="coverage-crap4j" target="logs/crap4j.xml"/>
|
<log type="coverage-crap4j" target="logs/crap4j.xml"/>
|
||||||
<log type="coverage-xml" target="logs/coverage" />
|
<log type="coverage-xml" target="logs/coverage" />
|
||||||
<log type="junit" target="logs/junit.xml" logIncompleteSkipped="false"/>
|
<log type="junit" target="logs/junit.xml" />
|
||||||
</logging>
|
</logging>
|
||||||
<php>
|
<php>
|
||||||
<server name="HTTP_USER_AGENT" value="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0" />
|
<server name="HTTP_USER_AGENT" value="Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Firefox/38.0" />
|
||||||
|
@ -72,7 +72,7 @@ final class AnimeListTransformer extends AbstractTransformer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$streamingLinks = (array_key_exists('streamingLinks', $anime['relationships']))
|
$streamingLinks = array_key_exists('streamingLinks', $anime['relationships'])
|
||||||
? Kitsu::parseListItemStreamingLinks($included, $animeId)
|
? Kitsu::parseListItemStreamingLinks($included, $animeId)
|
||||||
: [];
|
: [];
|
||||||
|
|
||||||
|
@ -79,11 +79,7 @@ class Controller {
|
|||||||
* Common data to be sent to views
|
* Common data to be sent to views
|
||||||
* @var array
|
* @var array
|
||||||
*/
|
*/
|
||||||
protected $baseData = [
|
protected $baseData = [];
|
||||||
'url_type' => 'anime',
|
|
||||||
'other_type' => 'manga',
|
|
||||||
'menu_name' => ''
|
|
||||||
];
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Controller constructor.
|
* Controller constructor.
|
||||||
@ -95,46 +91,29 @@ class Controller {
|
|||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
$this->setContainer($container);
|
$this->setContainer($container);
|
||||||
|
|
||||||
$auraUrlGenerator = $container->get('aura-router')->getGenerator();
|
$auraUrlGenerator = $container->get('aura-router')->getGenerator();
|
||||||
|
$session = $container->get('session');
|
||||||
$urlGenerator = $container->get('url-generator');
|
$urlGenerator = $container->get('url-generator');
|
||||||
|
|
||||||
$this->cache = $container->get('cache');
|
$this->cache = $container->get('cache');
|
||||||
$this->config = $container->get('config');
|
$this->config = $container->get('config');
|
||||||
$this->request = $container->get('request');
|
$this->request = $container->get('request');
|
||||||
$this->response = $container->get('response');
|
$this->response = $container->get('response');
|
||||||
|
$this->session = $session->getSegment(SESSION_SEGMENT);
|
||||||
$this->baseData = array_merge($this->baseData, [
|
|
||||||
'url' => $auraUrlGenerator,
|
|
||||||
'urlGenerator' => $urlGenerator,
|
|
||||||
'auth' => $container->get('auth'),
|
|
||||||
'config' => $this->config
|
|
||||||
]);
|
|
||||||
|
|
||||||
$this->url = $auraUrlGenerator;
|
$this->url = $auraUrlGenerator;
|
||||||
$this->urlGenerator = $urlGenerator;
|
$this->urlGenerator = $urlGenerator;
|
||||||
|
|
||||||
$session = $container->get('session');
|
$this->baseData = [
|
||||||
$this->session = $session->getSegment(SESSION_SEGMENT);
|
'auth' => $container->get('auth'),
|
||||||
|
'config' => $this->config,
|
||||||
// Set a 'previous' flash value for better redirects
|
'menu_name' => '',
|
||||||
$serverParams = $this->request->getServerParams();
|
'message' => $this->session->getFlash('message'), // Get message box data if it exists
|
||||||
if (array_key_exists('HTTP_REFERER', $serverParams) && false === stripos($serverParams['HTTP_REFERER'], 'login'))
|
'other_type' => 'manga',
|
||||||
{
|
'url' => $auraUrlGenerator,
|
||||||
$this->session->setFlash('previous', $serverParams['HTTP_REFERER']);
|
'url_type' => 'anime',
|
||||||
}
|
'urlGenerator' => $urlGenerator,
|
||||||
|
];
|
||||||
// Set a message box if available
|
|
||||||
$this->baseData['message'] = $this->session->getFlash('message');
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Redirect to the previous page
|
|
||||||
*
|
|
||||||
* @return void
|
|
||||||
*/
|
|
||||||
public function redirectToPrevious(): void
|
|
||||||
{
|
|
||||||
$previous = $this->session->getFlash('previous');
|
|
||||||
$this->redirect($previous, 303);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -159,7 +138,7 @@ class Controller {
|
|||||||
|
|
||||||
// Don't attempt to set the redirect url if
|
// Don't attempt to set the redirect url if
|
||||||
// the page is one of the form type pages,
|
// the page is one of the form type pages,
|
||||||
// and the previous page is also a form type page_segments
|
// and the previous page is also a form type
|
||||||
if ($doubleFormPage || $isLoginPage)
|
if ($doubleFormPage || $isLoginPage)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
@ -178,6 +157,8 @@ class Controller {
|
|||||||
/**
|
/**
|
||||||
* Redirect to the url previously set in the session
|
* Redirect to the url previously set in the session
|
||||||
*
|
*
|
||||||
|
* If one is not set, redirect to default url
|
||||||
|
*
|
||||||
* @throws InvalidArgumentException
|
* @throws InvalidArgumentException
|
||||||
* @throws \Aviat\Ion\Di\Exception\ContainerException
|
* @throws \Aviat\Ion\Di\Exception\ContainerException
|
||||||
* @throws \Aviat\Ion\Di\Exception\NotFoundException
|
* @throws \Aviat\Ion\Di\Exception\NotFoundException
|
||||||
@ -185,16 +166,10 @@ class Controller {
|
|||||||
*/
|
*/
|
||||||
public function sessionRedirect(): void
|
public function sessionRedirect(): void
|
||||||
{
|
{
|
||||||
$target = $this->session->get('redirect_url');
|
$target = $this->session->get('redirect_url') ?? '/';
|
||||||
if (empty($target))
|
|
||||||
{
|
$this->redirect($target, 303);
|
||||||
$this->notFound();
|
$this->session->set('redirect_url', NULL);
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$this->redirect($target, 303);
|
|
||||||
$this->session->set('redirect_url', NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -218,7 +193,7 @@ class Controller {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$route = $router->getRoute();
|
$route = $router->getRoute();
|
||||||
$data['route_path'] = $route ? $router->getRoute()->path : '';
|
$data['route_path'] = $route !== FALSE ? $route->path : '';
|
||||||
|
|
||||||
|
|
||||||
$templatePath = _dir($this->config->get('view_path'), "{$template}.php");
|
$templatePath = _dir($this->config->get('view_path'), "{$template}.php");
|
||||||
@ -275,7 +250,7 @@ class Controller {
|
|||||||
public function notFound(
|
public function notFound(
|
||||||
string $title = 'Sorry, page not found',
|
string $title = 'Sorry, page not found',
|
||||||
string $message = 'Page Not Found'
|
string $message = 'Page Not Found'
|
||||||
): void
|
): void
|
||||||
{
|
{
|
||||||
$this->outputHTML('404', [
|
$this->outputHTML('404', [
|
||||||
'title' => $title,
|
'title' => $title,
|
||||||
@ -408,7 +383,6 @@ class Controller {
|
|||||||
(new JsonView($this->container))
|
(new JsonView($this->container))
|
||||||
->setStatusCode($code)
|
->setStatusCode($code)
|
||||||
->setOutput($data);
|
->setOutput($data);
|
||||||
// ->send();
|
|
||||||
exit();
|
exit();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,8 +395,8 @@ class Controller {
|
|||||||
*/
|
*/
|
||||||
protected function redirect(string $url, int $code): void
|
protected function redirect(string $url, int $code): void
|
||||||
{
|
{
|
||||||
$http = new HttpView($this->container);
|
(new HttpView($this->container))->redirect($url, $code);
|
||||||
$http->redirect($url, $code);
|
exit();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of BaseController.php
|
// End of BaseController.php
|
@ -28,6 +28,7 @@ use Aviat\Ion\Json;
|
|||||||
* Controller for Anime-related pages
|
* Controller for Anime-related pages
|
||||||
*/
|
*/
|
||||||
final class Anime extends BaseController {
|
final class Anime extends BaseController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The anime list model
|
* The anime list model
|
||||||
* @var \Aviat\AnimeClient\Model\Anime $model
|
* @var \Aviat\AnimeClient\Model\Anime $model
|
||||||
@ -49,12 +50,9 @@ final class Anime extends BaseController {
|
|||||||
|
|
||||||
$this->baseData = array_merge($this->baseData, [
|
$this->baseData = array_merge($this->baseData, [
|
||||||
'menu_name' => 'anime_list',
|
'menu_name' => 'anime_list',
|
||||||
'url_type' => 'anime',
|
|
||||||
'other_type' => 'manga',
|
'other_type' => 'manga',
|
||||||
'config' => $this->config,
|
'url_type' => 'anime',
|
||||||
]);
|
]);
|
||||||
|
|
||||||
$this->cache = $container->get('cache');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -56,9 +56,8 @@ final class AnimeCollection extends BaseController {
|
|||||||
$this->baseData = array_merge($this->baseData, [
|
$this->baseData = array_merge($this->baseData, [
|
||||||
'collection_type' => 'anime',
|
'collection_type' => 'anime',
|
||||||
'menu_name' => 'collection',
|
'menu_name' => 'collection',
|
||||||
'url_type' => 'anime',
|
|
||||||
'other_type' => 'manga',
|
'other_type' => 'manga',
|
||||||
'config' => $this->config,
|
'url_type' => 'anime',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -131,8 +131,6 @@ final class Images extends BaseController {
|
|||||||
|
|
||||||
$data = wait($response->getBody());
|
$data = wait($response->getBody());
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
[$origWidth] = getimagesizefromstring($data);
|
[$origWidth] = getimagesizefromstring($data);
|
||||||
$gdImg = imagecreatefromstring($data);
|
$gdImg = imagecreatefromstring($data);
|
||||||
$resizedImg = imagescale($gdImg, $width ?? $origWidth);
|
$resizedImg = imagescale($gdImg, $width ?? $origWidth);
|
||||||
|
@ -29,8 +29,6 @@ use Aviat\Ion\{Json, StringWrapper};
|
|||||||
*/
|
*/
|
||||||
final class Manga extends Controller {
|
final class Manga extends Controller {
|
||||||
|
|
||||||
use StringWrapper;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The manga model
|
* The manga model
|
||||||
* @var MangaModel $model
|
* @var MangaModel $model
|
||||||
@ -51,9 +49,8 @@ final class Manga extends Controller {
|
|||||||
$this->model = $container->get('manga-model');
|
$this->model = $container->get('manga-model');
|
||||||
$this->baseData = array_merge($this->baseData, [
|
$this->baseData = array_merge($this->baseData, [
|
||||||
'menu_name' => 'manga_list',
|
'menu_name' => 'manga_list',
|
||||||
'config' => $this->config,
|
'other_type' => 'anime',
|
||||||
'url_type' => 'manga',
|
'url_type' => 'manga',
|
||||||
'other_type' => 'anime'
|
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -57,9 +57,8 @@ final class MangaCollection extends BaseController {
|
|||||||
$this->baseData = array_merge($this->baseData, [
|
$this->baseData = array_merge($this->baseData, [
|
||||||
'collection_type' => 'manga',
|
'collection_type' => 'manga',
|
||||||
'menu_name' => 'manga-collection',
|
'menu_name' => 'manga-collection',
|
||||||
'url_type' => 'manga',
|
|
||||||
'other_type' => 'anime',
|
'other_type' => 'anime',
|
||||||
'config' => $this->config,
|
'url_type' => 'manga',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -23,6 +23,7 @@ use Aviat\Ion\Di\ContainerInterface;
|
|||||||
* Controller for user settings
|
* Controller for user settings
|
||||||
*/
|
*/
|
||||||
final class Settings extends BaseController {
|
final class Settings extends BaseController {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var \Aviat\AnimeClient\API\Anilist\Model
|
* @var \Aviat\AnimeClient\API\Anilist\Model
|
||||||
*/
|
*/
|
||||||
@ -144,13 +145,9 @@ final class Settings extends BaseController {
|
|||||||
|
|
||||||
$saved = $this->settingsModel->saveSettingsFile($newSettings);
|
$saved = $this->settingsModel->saveSettingsFile($newSettings);
|
||||||
|
|
||||||
if ($saved)
|
$saved
|
||||||
{
|
? $this->setFlashMessage('Linked Anilist Account', 'success')
|
||||||
$this->setFlashMessage('Linked Anilist Account', 'success');
|
: $this->setFlashMessage('Error Linking Anilist Account', 'error');
|
||||||
} else
|
|
||||||
{
|
|
||||||
$this->setFlashMessage('Error Linking Anilist Account', 'error');
|
|
||||||
}
|
|
||||||
|
|
||||||
$this->redirect($this->url->generate('settings'), 303);
|
$this->redirect($this->url->generate('settings'), 303);
|
||||||
}
|
}
|
||||||
|
@ -20,14 +20,14 @@ use Aviat\AnimeClient\FormGenerator;
|
|||||||
use Aviat\Ion\Di\ContainerAware;
|
use Aviat\Ion\Di\ContainerAware;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* MenuGenerator helper wrapper
|
* FormGenerator helper wrapper
|
||||||
*/
|
*/
|
||||||
final class Form {
|
final class Form {
|
||||||
|
|
||||||
use ContainerAware;
|
use ContainerAware;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create the html for the selected menu
|
* Create the html for the specified form
|
||||||
*
|
*
|
||||||
* @param string $name
|
* @param string $name
|
||||||
* @param array $form
|
* @param array $form
|
||||||
@ -38,4 +38,3 @@ final class Form {
|
|||||||
return (new FormGenerator($this->container))->generate($name, $form);
|
return (new FormGenerator($this->container))->generate($name, $form);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of Menu.php
|
|
Loading…
Reference in New Issue
Block a user