Version 5.1 - All the GraphQL #32
@ -1,21 +0,0 @@
|
|||||||
<?php declare(strict_types=1);
|
|
||||||
/**
|
|
||||||
* Hummingbird Anime List Client
|
|
||||||
*
|
|
||||||
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists
|
|
||||||
*
|
|
||||||
* PHP version 7
|
|
||||||
*
|
|
||||||
* @package HummingbirdAnimeClient
|
|
||||||
* @author Timothy J. Warren <tim@timshomepage.net>
|
|
||||||
* @copyright 2015 - 2018 Timothy J. Warren
|
|
||||||
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
|
||||||
* @version 4.0
|
|
||||||
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
||||||
*/
|
|
||||||
|
|
||||||
namespace Aviat\AnimeClient\API;
|
|
||||||
|
|
||||||
abstract class AbstractListItem implements ListItemInterface {
|
|
||||||
|
|
||||||
}
|
|
@ -21,15 +21,17 @@ use const Aviat\AnimeClient\SESSION_SEGMENT;
|
|||||||
use function Amp\Promise\wait;
|
use function Amp\Promise\wait;
|
||||||
|
|
||||||
use Amp\Artax\Request;
|
use Amp\Artax\Request;
|
||||||
use Aviat\AnimeClient\API\{AbstractListItem, HummingbirdClient};
|
use Aviat\AnimeClient\API\{
|
||||||
|
HummingbirdClient,
|
||||||
|
ListItemInterface
|
||||||
|
};
|
||||||
use Aviat\Ion\Di\ContainerAware;
|
use Aviat\Ion\Di\ContainerAware;
|
||||||
use Aviat\Ion\Json;
|
use Aviat\Ion\Json;
|
||||||
use RuntimeException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CRUD operations for Kitsu list items
|
* CRUD operations for Kitsu list items
|
||||||
*/
|
*/
|
||||||
class ListItem extends AbstractListItem {
|
class ListItem implements ListItemInterface {
|
||||||
use ContainerAware;
|
use ContainerAware;
|
||||||
use KitsuTrait;
|
use KitsuTrait;
|
||||||
|
|
||||||
@ -41,7 +43,7 @@ class ListItem extends AbstractListItem {
|
|||||||
->get('session')
|
->get('session')
|
||||||
->getSegment(SESSION_SEGMENT);
|
->getSegment(SESSION_SEGMENT);
|
||||||
|
|
||||||
if ( ! is_null($sessionSegment->get('auth_token')))
|
if ($sessionSegment->get('auth_token') !== NULL)
|
||||||
{
|
{
|
||||||
$token = $sessionSegment->get('auth_token');
|
$token = $sessionSegment->get('auth_token');
|
||||||
return "bearer {$token}";
|
return "bearer {$token}";
|
||||||
|
@ -169,7 +169,7 @@ class Model {
|
|||||||
*/
|
*/
|
||||||
public function getUserIdByUsername(string $username = NULL): string
|
public function getUserIdByUsername(string $username = NULL): string
|
||||||
{
|
{
|
||||||
if (is_null($username))
|
if ($username === NULL)
|
||||||
{
|
{
|
||||||
$username = $this->getUsername();
|
$username = $this->getUsername();
|
||||||
}
|
}
|
||||||
|
@ -18,7 +18,6 @@ namespace Aviat\AnimeClient\API\MAL;
|
|||||||
|
|
||||||
use Amp\Artax\{FormBody, Request};
|
use Amp\Artax\{FormBody, Request};
|
||||||
use Aviat\AnimeClient\API\{
|
use Aviat\AnimeClient\API\{
|
||||||
AbstractListItem,
|
|
||||||
XML
|
XML
|
||||||
};
|
};
|
||||||
use Aviat\Ion\Di\ContainerAware;
|
use Aviat\Ion\Di\ContainerAware;
|
||||||
|
@ -18,8 +18,7 @@ namespace Aviat\AnimeClient\API\MAL;
|
|||||||
|
|
||||||
use Aviat\AnimeClient\API\{
|
use Aviat\AnimeClient\API\{
|
||||||
APIRequestBuilder,
|
APIRequestBuilder,
|
||||||
MAL as M,
|
MAL as M
|
||||||
XML
|
|
||||||
};
|
};
|
||||||
|
|
||||||
class MALRequestBuilder extends APIRequestBuilder {
|
class MALRequestBuilder extends APIRequestBuilder {
|
||||||
|
@ -178,7 +178,7 @@ trait MALTrait {
|
|||||||
$response = $this->getResponse('POST', ...$args);
|
$response = $this->getResponse('POST', ...$args);
|
||||||
$validResponseCodes = [200, 201];
|
$validResponseCodes = [200, 201];
|
||||||
|
|
||||||
if ( ! in_array((int) $response->getStatus(), $validResponseCodes))
|
if ( ! \in_array((int) $response->getStatus(), $validResponseCodes, TRUE))
|
||||||
{
|
{
|
||||||
if ($logger)
|
if ($logger)
|
||||||
{
|
{
|
||||||
|
@ -40,7 +40,7 @@ class ParallelAPIRequest {
|
|||||||
*/
|
*/
|
||||||
public function addRequest($request, $key = NULL): self
|
public function addRequest($request, $key = NULL): self
|
||||||
{
|
{
|
||||||
if ( ! is_null($key))
|
if ($key !== NULL)
|
||||||
{
|
{
|
||||||
$this->requests[$key] = $request;
|
$this->requests[$key] = $request;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -174,14 +174,12 @@ class XML {
|
|||||||
*/
|
*/
|
||||||
private static function stripXMLWhitespace(string $xml): string
|
private static function stripXMLWhitespace(string $xml): string
|
||||||
{
|
{
|
||||||
|
|
||||||
// Get rid of unimportant text nodes by removing
|
// Get rid of unimportant text nodes by removing
|
||||||
// whitespace characters from between xml tags,
|
// whitespace characters from between xml tags,
|
||||||
// except for the xml declaration tag, Which looks
|
// except for the xml declaration tag, Which looks
|
||||||
// something like:
|
// something like:
|
||||||
/* <?xml version="1.0" encoding="UTF-8"?> */
|
/* <?xml version="1.0" encoding="UTF-8"?> */
|
||||||
|
return preg_replace('/([^?])>\s+</', '$1><', $xml);
|
||||||
return preg_replace('/([^\?])>\s+</', '$1><', $xml);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -191,7 +189,7 @@ class XML {
|
|||||||
* @param DOMNodeList $nodeList The current NodeList object
|
* @param DOMNodeList $nodeList The current NodeList object
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function childNodesToArray(array &$root, DOMNodelist $nodeList)
|
private static function childNodesToArray(array &$root, DOMNodelist $nodeList): void
|
||||||
{
|
{
|
||||||
$length = $nodeList->length;
|
$length = $nodeList->length;
|
||||||
for ($i = 0; $i < $length; $i++)
|
for ($i = 0; $i < $length; $i++)
|
||||||
@ -200,14 +198,14 @@ class XML {
|
|||||||
$current =& $root[$el->nodeName];
|
$current =& $root[$el->nodeName];
|
||||||
|
|
||||||
// It's a top level element!
|
// It's a top level element!
|
||||||
if (is_a($el->childNodes->item(0), 'DomText') OR ( ! $el->hasChildNodes()))
|
if (( ! $el->hasChildNodes()) || is_a($el->childNodes->item(0), 'DomText'))
|
||||||
{
|
{
|
||||||
$current = $el->textContent;
|
$current = $el->textContent;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
// An empty value at the current root
|
// An empty value at the current root
|
||||||
if (is_null($current))
|
if ($current === NULL)
|
||||||
{
|
{
|
||||||
$current = [];
|
$current = [];
|
||||||
static::childNodesToArray($current, $el->childNodes);
|
static::childNodesToArray($current, $el->childNodes);
|
||||||
@ -230,7 +228,7 @@ class XML {
|
|||||||
$current = [$current];
|
$current = [$current];
|
||||||
}
|
}
|
||||||
|
|
||||||
array_push($current, []);
|
$current[] = [];
|
||||||
$index = count($current) - 1;
|
$index = count($current) - 1;
|
||||||
|
|
||||||
static::childNodesToArray($current[$index], $el->childNodes);
|
static::childNodesToArray($current[$index], $el->childNodes);
|
||||||
@ -245,7 +243,7 @@ class XML {
|
|||||||
* @param array $data The data for the current node
|
* @param array $data The data for the current node
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
private static function arrayPropertiesToXmlNodes(DOMDocument &$dom, DOMNode &$parent, array $data)
|
private static function arrayPropertiesToXmlNodes(DOMDocument $dom, DOMNode $parent, array $data): void
|
||||||
{
|
{
|
||||||
foreach($data as $key => $props)
|
foreach($data as $key => $props)
|
||||||
{
|
{
|
||||||
@ -260,7 +258,7 @@ class XML {
|
|||||||
|
|
||||||
$node = $dom->createElement($key);
|
$node = $dom->createElement($key);
|
||||||
|
|
||||||
if (is_array($props))
|
if (\is_array($props))
|
||||||
{
|
{
|
||||||
static::arrayPropertiesToXmlNodes($dom, $node, $props);
|
static::arrayPropertiesToXmlNodes($dom, $node, $props);
|
||||||
}
|
}
|
||||||
|
@ -22,10 +22,6 @@ use Aviat\Ion\Di\{
|
|||||||
ContainerAware,
|
ContainerAware,
|
||||||
ContainerInterface
|
ContainerInterface
|
||||||
};
|
};
|
||||||
use Aviat\Ion\Di\Exception\{
|
|
||||||
ContainerException,
|
|
||||||
NotFoundException
|
|
||||||
};
|
|
||||||
use Aviat\Ion\Exception\DoubleRenderException;
|
use Aviat\Ion\Exception\DoubleRenderException;
|
||||||
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
|
use Aviat\Ion\View\{HtmlView, HttpView, JsonView};
|
||||||
use InvalidArgumentException;
|
use InvalidArgumentException;
|
||||||
@ -92,9 +88,9 @@ class Controller {
|
|||||||
/**
|
/**
|
||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
* @throws ContainerException
|
|
||||||
* @throws NotFoundException
|
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -135,7 +131,7 @@ class Controller {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function redirectToPrevious()
|
public function redirectToPrevious(): void
|
||||||
{
|
{
|
||||||
$previous = $this->session->getFlash('previous');
|
$previous = $this->session->getFlash('previous');
|
||||||
$this->redirect($previous, 303);
|
$this->redirect($previous, 303);
|
||||||
@ -144,9 +140,9 @@ class Controller {
|
|||||||
/**
|
/**
|
||||||
* Set the current url in the session as the target of a future redirect
|
* Set the current url in the session as the target of a future redirect
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @param string|null $url
|
* @param string|null $url
|
||||||
* @throws ContainerException
|
|
||||||
* @throws NotFoundException
|
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function setSessionRedirect(string $url = NULL): void
|
public function setSessionRedirect(string $url = NULL): void
|
||||||
@ -312,6 +308,7 @@ class Controller {
|
|||||||
/**
|
/**
|
||||||
* Redirect to the default controller/url from an empty path
|
* Redirect to the default controller/url from an empty path
|
||||||
*
|
*
|
||||||
|
* @throws InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function redirectToDefaultRoute(): void
|
public function redirectToDefaultRoute(): void
|
||||||
|
@ -41,6 +41,8 @@ class Anime extends BaseController {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -63,11 +65,14 @@ class Anime extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param string|int $type - The section of the list
|
* @param string|int $type - The section of the list
|
||||||
* @param string $view - List or cover view
|
* @param string $view - List or cover view
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL)
|
public function index($type = KitsuWatchingStatus::WATCHING, string $view = NULL): void
|
||||||
{
|
{
|
||||||
$title = (array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE))
|
$title = array_key_exists($type, AnimeWatchingStatus::ROUTE_TO_TITLE)
|
||||||
? $this->formatTitle(
|
? $this->formatTitle(
|
||||||
$this->config->get('whose_list') . "'s Anime List",
|
$this->config->get('whose_list') . "'s Anime List",
|
||||||
AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
|
AnimeWatchingStatus::ROUTE_TO_TITLE[$type]
|
||||||
@ -92,9 +97,13 @@ class Anime extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Form to add an anime
|
* Form to add an anime
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \Aura\Router\Exception\RouteNotFound
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addForm()
|
public function addForm(): void
|
||||||
{
|
{
|
||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
$this->outputHTML('anime/add', [
|
$this->outputHTML('anime/add', [
|
||||||
@ -110,9 +119,11 @@ class Anime extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Add an anime to the list
|
* Add an anime to the list
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add()
|
public function add(): void
|
||||||
{
|
{
|
||||||
$data = $this->request->getParsedBody();
|
$data = $this->request->getParsedBody();
|
||||||
if ( ! array_key_exists('id', $data))
|
if ( ! array_key_exists('id', $data))
|
||||||
@ -140,9 +151,12 @@ class Anime extends BaseController {
|
|||||||
*
|
*
|
||||||
* @param int $id
|
* @param int $id
|
||||||
* @param string $status
|
* @param string $status
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function edit($id, $status = "all")
|
public function edit($id, $status = 'all'): void
|
||||||
{
|
{
|
||||||
$item = $this->model->getLibraryItem($id);
|
$item = $this->model->getLibraryItem($id);
|
||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
@ -165,7 +179,7 @@ class Anime extends BaseController {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function search()
|
public function search(): void
|
||||||
{
|
{
|
||||||
$queryParams = $this->request->getQueryParams();
|
$queryParams = $this->request->getQueryParams();
|
||||||
$query = $queryParams['query'];
|
$query = $queryParams['query'];
|
||||||
@ -175,9 +189,11 @@ class Anime extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Update an anime item via a form submission
|
* Update an anime item via a form submission
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function formUpdate()
|
public function formUpdate(): void
|
||||||
{
|
{
|
||||||
$data = $this->request->getParsedBody();
|
$data = $this->request->getParsedBody();
|
||||||
|
|
||||||
@ -205,7 +221,7 @@ class Anime extends BaseController {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function update()
|
public function update(): void
|
||||||
{
|
{
|
||||||
if (stripos($this->request->getHeader('content-type')[0], 'application/json') !== FALSE)
|
if (stripos($this->request->getHeader('content-type')[0], 'application/json') !== FALSE)
|
||||||
{
|
{
|
||||||
@ -225,9 +241,11 @@ class Anime extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Remove an anime from the list
|
* Remove an anime from the list
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function delete()
|
public function delete(): void
|
||||||
{
|
{
|
||||||
$body = $this->request->getParsedBody();
|
$body = $this->request->getParsedBody();
|
||||||
$response = $this->model->deleteLibraryItem($body['id'], $body['mal_id']);
|
$response = $this->model->deleteLibraryItem($body['id'], $body['mal_id']);
|
||||||
@ -249,9 +267,12 @@ class Anime extends BaseController {
|
|||||||
* View details of an anime
|
* View details of an anime
|
||||||
*
|
*
|
||||||
* @param string $animeId
|
* @param string $animeId
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function details(string $animeId)
|
public function details(string $animeId): void
|
||||||
{
|
{
|
||||||
$show_data = $this->model->getAnime($animeId);
|
$show_data = $this->model->getAnime($animeId);
|
||||||
$characters = [];
|
$characters = [];
|
||||||
@ -287,5 +308,14 @@ class Anime extends BaseController {
|
|||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find anime matching the selected genre
|
||||||
|
*
|
||||||
|
* @param string $genre
|
||||||
|
*/
|
||||||
|
public function genre(string $genre): void
|
||||||
|
{
|
||||||
|
// @TODO: implement
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// End of AnimeController.php
|
// End of AnimeController.php
|
@ -44,6 +44,8 @@ class AnimeCollection extends BaseController {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -63,6 +65,7 @@ class AnimeCollection extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Search for anime
|
* Search for anime
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Exception\DoubleRenderException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function search()
|
public function search()
|
||||||
@ -76,6 +79,9 @@ class AnimeCollection extends BaseController {
|
|||||||
* Show the anime collection page
|
* Show the anime collection page
|
||||||
*
|
*
|
||||||
* @param string $view
|
* @param string $view
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function index($view)
|
public function index($view)
|
||||||
@ -98,13 +104,17 @@ class AnimeCollection extends BaseController {
|
|||||||
* Show the anime collection add/edit form
|
* Show the anime collection add/edit form
|
||||||
*
|
*
|
||||||
* @param integer|null $id
|
* @param integer|null $id
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \Aura\Router\Exception\RouteNotFound
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function form($id = NULL)
|
public function form($id = NULL)
|
||||||
{
|
{
|
||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
|
|
||||||
$action = (is_null($id)) ? "Add" : "Edit";
|
$action = $id === NULL ? 'Add' : 'Edit';
|
||||||
$urlAction = strtolower($action);
|
$urlAction = strtolower($action);
|
||||||
|
|
||||||
$this->outputHTML('collection/' . $urlAction, [
|
$this->outputHTML('collection/' . $urlAction, [
|
||||||
@ -115,13 +125,16 @@ class AnimeCollection extends BaseController {
|
|||||||
$action
|
$action
|
||||||
),
|
),
|
||||||
'media_items' => $this->animeCollectionModel->getMediaTypeList(),
|
'media_items' => $this->animeCollectionModel->getMediaTypeList(),
|
||||||
'item' => ($action === "Edit") ? $this->animeCollectionModel->get($id) : []
|
'item' => ($action === 'Edit') ? $this->animeCollectionModel->get($id) : []
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a collection item
|
* Update a collection item
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit()
|
||||||
@ -143,6 +156,9 @@ class AnimeCollection extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Add a collection item
|
* Add a collection item
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add()
|
public function add()
|
||||||
@ -171,13 +187,13 @@ class AnimeCollection extends BaseController {
|
|||||||
$data = $this->request->getParsedBody();
|
$data = $this->request->getParsedBody();
|
||||||
if ( ! array_key_exists('hummingbird_id', $data))
|
if ( ! array_key_exists('hummingbird_id', $data))
|
||||||
{
|
{
|
||||||
$this->redirect("/anime-collection/view", 303);
|
$this->redirect('/anime-collection/view', 303);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->animeCollectionModel->delete($data);
|
$this->animeCollectionModel->delete($data);
|
||||||
$this->setFlashMessage("Successfully removed anime from collection.", 'success');
|
$this->setFlashMessage('Successfully removed anime from collection.', 'success');
|
||||||
|
|
||||||
$this->redirect("/anime-collection/view", 303);
|
$this->redirect('/anime-collection/view', 303);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of CollectionController.php
|
// End of CollectionController.php
|
@ -27,7 +27,16 @@ class Character extends BaseController {
|
|||||||
|
|
||||||
use ArrayWrapper;
|
use ArrayWrapper;
|
||||||
|
|
||||||
public function index(string $slug)
|
/**
|
||||||
|
* Show information about a character
|
||||||
|
*
|
||||||
|
* @param string $slug
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function index(string $slug): void
|
||||||
{
|
{
|
||||||
$model = $this->container->get('kitsu-model');
|
$model = $this->container->get('kitsu-model');
|
||||||
|
|
||||||
@ -88,8 +97,9 @@ class Character extends BaseController {
|
|||||||
|
|
||||||
|
|
||||||
$person = current($role['relationships']['person']['people'])['attributes'];
|
$person = current($role['relationships']['person']['people'])['attributes'];
|
||||||
|
$hasName = array_key_exists($person['name'], $people);
|
||||||
|
|
||||||
if ( ! array_key_exists($person['name'], $people))
|
if ( ! $hasName)
|
||||||
{
|
{
|
||||||
$people[$person['name']] = $i;
|
$people[$person['name']] = $i;
|
||||||
$role['relationships']['media']['anime'] = [current($role['relationships']['media']['anime'])];
|
$role['relationships']['media']['anime'] = [current($role['relationships']['media']['anime'])];
|
||||||
@ -99,8 +109,7 @@ class Character extends BaseController {
|
|||||||
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else if(array_key_exists($person['name'], $people))
|
|
||||||
{
|
|
||||||
if (array_key_exists('anime', $role['relationships']['media']))
|
if (array_key_exists('anime', $role['relationships']['media']))
|
||||||
{
|
{
|
||||||
$key = $people[$person['name']];
|
$key = $people[$person['name']];
|
||||||
@ -108,7 +117,6 @@ class Character extends BaseController {
|
|||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
return $output;
|
return $output;
|
||||||
}
|
}
|
||||||
@ -122,7 +130,7 @@ class Character extends BaseController {
|
|||||||
if (
|
if (
|
||||||
array_key_exists('attributes', $role) &&
|
array_key_exists('attributes', $role) &&
|
||||||
array_key_exists('role', $role['attributes']) &&
|
array_key_exists('role', $role['attributes']) &&
|
||||||
( ! is_null($role['attributes']['role']))
|
$role['attributes']['role'] !== NULL
|
||||||
) {
|
) {
|
||||||
$count++;
|
$count++;
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,9 @@ class Index extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Purges the API cache
|
* Purges the API cache
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function clearCache()
|
public function clearCache()
|
||||||
@ -37,13 +40,16 @@ class Index extends BaseController {
|
|||||||
$this->cache->clear();
|
$this->cache->clear();
|
||||||
$this->outputHTML('blank', [
|
$this->outputHTML('blank', [
|
||||||
'title' => 'Cache cleared'
|
'title' => 'Cache cleared'
|
||||||
], NULL, 200);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Show the login form
|
* Show the login form
|
||||||
*
|
*
|
||||||
* @param string $status
|
* @param string $status
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function login(string $status = '')
|
public function login(string $status = '')
|
||||||
@ -69,6 +75,10 @@ class Index extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Attempt login authentication
|
* Attempt login authentication
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \Aura\Router\Exception\RouteNotFound
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function loginAction()
|
public function loginAction()
|
||||||
@ -88,6 +98,9 @@ class Index extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Deauthorize the current user
|
* Deauthorize the current user
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function logout()
|
public function logout()
|
||||||
@ -101,6 +114,9 @@ class Index extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Show the user profile page
|
* Show the user profile page
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function me()
|
public function me()
|
||||||
@ -125,9 +141,17 @@ class Index extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Get image covers from kitsu
|
* Get image covers from kitsu
|
||||||
*
|
*
|
||||||
|
* @param string $type The category of image
|
||||||
|
* @param string $file The filename to look for
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
|
* @throws \TypeError
|
||||||
|
* @throws \Error
|
||||||
|
* @throws \Throwable
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function images($type, $file)
|
public function images(string $type, string $file): void
|
||||||
{
|
{
|
||||||
$kitsuUrl = 'https://media.kitsu.io/';
|
$kitsuUrl = 'https://media.kitsu.io/';
|
||||||
list($id, $ext) = explode('.', basename($file));
|
list($id, $ext) = explode('.', basename($file));
|
||||||
@ -164,9 +188,14 @@ class Index extends BaseController {
|
|||||||
echo $data;
|
echo $data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reorganize favorites data to be more useful
|
||||||
|
*
|
||||||
|
* @param array $rawfavorites
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
private function organizeFavorites(array $rawfavorites): array
|
private function organizeFavorites(array $rawfavorites): array
|
||||||
{
|
{
|
||||||
// return $rawfavorites;
|
|
||||||
$output = [];
|
$output = [];
|
||||||
|
|
||||||
unset($rawfavorites['data']);
|
unset($rawfavorites['data']);
|
||||||
|
@ -40,6 +40,8 @@ class Manga extends Controller {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -59,9 +61,12 @@ class Manga extends Controller {
|
|||||||
*
|
*
|
||||||
* @param string $status
|
* @param string $status
|
||||||
* @param string $view
|
* @param string $view
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function index($status = "all", $view = "")
|
public function index($status = 'all', $view = ''): void
|
||||||
{
|
{
|
||||||
$statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status];
|
$statusTitle = MangaReadingStatus::ROUTE_TO_TITLE[$status];
|
||||||
|
|
||||||
@ -88,9 +93,13 @@ class Manga extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Form to add an manga
|
* Form to add an manga
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \Aura\Router\Exception\RouteNotFound
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function addForm()
|
public function addForm(): void
|
||||||
{
|
{
|
||||||
$statuses = MangaReadingStatus::KITSU_TO_TITLE;
|
$statuses = MangaReadingStatus::KITSU_TO_TITLE;
|
||||||
|
|
||||||
@ -108,14 +117,16 @@ class Manga extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Add an manga to the list
|
* Add an manga to the list
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add()
|
public function add(): void
|
||||||
{
|
{
|
||||||
$data = $this->request->getParsedBody();
|
$data = $this->request->getParsedBody();
|
||||||
if ( ! array_key_exists('id', $data))
|
if ( ! array_key_exists('id', $data))
|
||||||
{
|
{
|
||||||
$this->redirect("manga/add", 303);
|
$this->redirect('manga/add', 303);
|
||||||
}
|
}
|
||||||
|
|
||||||
$result = $this->model->createLibraryItem($data);
|
$result = $this->model->createLibraryItem($data);
|
||||||
@ -138,9 +149,13 @@ class Manga extends Controller {
|
|||||||
*
|
*
|
||||||
* @param string $id
|
* @param string $id
|
||||||
* @param string $status
|
* @param string $status
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \Aura\Router\Exception\RouteNotFound
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function edit($id, $status = "All")
|
public function edit($id, $status = 'All'): void
|
||||||
{
|
{
|
||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
$item = $this->model->getLibraryItem($id);
|
$item = $this->model->getLibraryItem($id);
|
||||||
@ -164,7 +179,7 @@ class Manga extends Controller {
|
|||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function search()
|
public function search(): void
|
||||||
{
|
{
|
||||||
$query_data = $this->request->getQueryParams();
|
$query_data = $this->request->getQueryParams();
|
||||||
$this->outputJSON($this->model->search($query_data['query']));
|
$this->outputJSON($this->model->search($query_data['query']));
|
||||||
@ -173,9 +188,11 @@ class Manga extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Update an manga item via a form submission
|
* Update an manga item via a form submission
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function formUpdate()
|
public function formUpdate(): void
|
||||||
{
|
{
|
||||||
$data = $this->request->getParsedBody();
|
$data = $this->request->getParsedBody();
|
||||||
|
|
||||||
@ -202,9 +219,11 @@ class Manga extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Update a manga item
|
* Update a manga item
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function update()
|
public function update(): void
|
||||||
{
|
{
|
||||||
if (stripos($this->request->getHeader('content-type')[0], 'application/json') !== FALSE)
|
if (stripos($this->request->getHeader('content-type')[0], 'application/json') !== FALSE)
|
||||||
{
|
{
|
||||||
@ -224,9 +243,11 @@ class Manga extends Controller {
|
|||||||
/**
|
/**
|
||||||
* Remove an manga from the list
|
* Remove an manga from the list
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function delete()
|
public function delete(): void
|
||||||
{
|
{
|
||||||
$body = $this->request->getParsedBody();
|
$body = $this->request->getParsedBody();
|
||||||
$id = $body['id'];
|
$id = $body['id'];
|
||||||
@ -250,9 +271,12 @@ class Manga extends Controller {
|
|||||||
* View details of an manga
|
* View details of an manga
|
||||||
*
|
*
|
||||||
* @param string $manga_id
|
* @param string $manga_id
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function details($manga_id)
|
public function details($manga_id): void
|
||||||
{
|
{
|
||||||
$data = $this->model->getManga($manga_id);
|
$data = $this->model->getManga($manga_id);
|
||||||
$characters = [];
|
$characters = [];
|
||||||
@ -286,5 +310,15 @@ class Manga extends Controller {
|
|||||||
'data' => $data,
|
'data' => $data,
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Find manga matching the selected genre
|
||||||
|
*
|
||||||
|
* @param string $genre
|
||||||
|
*/
|
||||||
|
public function genre(string $genre): void
|
||||||
|
{
|
||||||
|
// @TODO: implement
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// End of MangaController.php
|
// End of MangaController.php
|
@ -21,7 +21,6 @@ use Aviat\AnimeClient\Model\{
|
|||||||
Manga as MangaModel,
|
Manga as MangaModel,
|
||||||
MangaCollection as MangaCollectionModel
|
MangaCollection as MangaCollectionModel
|
||||||
};
|
};
|
||||||
use Aviat\AnimeClient\UrlGenerator;
|
|
||||||
use Aviat\Ion\Di\ContainerInterface;
|
use Aviat\Ion\Di\ContainerInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -45,6 +44,9 @@ class MangaCollection extends BaseController {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -64,9 +66,10 @@ class MangaCollection extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Search for manga
|
* Search for manga
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Exception\DoubleRenderException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function search()
|
public function search(): void
|
||||||
{
|
{
|
||||||
$queryParams = $this->request->getQueryParams();
|
$queryParams = $this->request->getQueryParams();
|
||||||
$query = $queryParams['query'];
|
$query = $queryParams['query'];
|
||||||
@ -77,9 +80,12 @@ class MangaCollection extends BaseController {
|
|||||||
* Show the manga collection page
|
* Show the manga collection page
|
||||||
*
|
*
|
||||||
* @param string $view
|
* @param string $view
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function index($view)
|
public function index($view): void
|
||||||
{
|
{
|
||||||
$viewMap = [
|
$viewMap = [
|
||||||
'' => 'cover',
|
'' => 'cover',
|
||||||
@ -99,13 +105,17 @@ class MangaCollection extends BaseController {
|
|||||||
* Show the manga collection add/edit form
|
* Show the manga collection add/edit form
|
||||||
*
|
*
|
||||||
* @param integer|null $id
|
* @param integer|null $id
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \Aura\Router\Exception\RouteNotFound
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function form($id = NULL)
|
public function form($id = NULL): void
|
||||||
{
|
{
|
||||||
$this->setSessionRedirect();
|
$this->setSessionRedirect();
|
||||||
|
|
||||||
$action = (is_null($id)) ? "Add" : "Edit";
|
$action = $id === NULL ? 'Add' : 'Edit';
|
||||||
$urlAction = strtolower($action);
|
$urlAction = strtolower($action);
|
||||||
|
|
||||||
$this->outputHTML('collection/' . $urlAction, [
|
$this->outputHTML('collection/' . $urlAction, [
|
||||||
@ -116,13 +126,16 @@ class MangaCollection extends BaseController {
|
|||||||
$action
|
$action
|
||||||
),
|
),
|
||||||
'media_items' => $this->mangaCollectionModel->getMediaTypeList(),
|
'media_items' => $this->mangaCollectionModel->getMediaTypeList(),
|
||||||
'item' => ($action === "Edit") ? $this->mangaCollectionModel->get($id) : []
|
'item' => ($action === 'Edit') ? $this->mangaCollectionModel->get($id) : []
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Update a collection item
|
* Update a collection item
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function edit()
|
public function edit()
|
||||||
@ -144,6 +157,9 @@ class MangaCollection extends BaseController {
|
|||||||
/**
|
/**
|
||||||
* Add a collection item
|
* Add a collection item
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \InvalidArgumentException
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function add()
|
public function add()
|
||||||
@ -172,13 +188,13 @@ class MangaCollection extends BaseController {
|
|||||||
$data = $this->request->getParsedBody();
|
$data = $this->request->getParsedBody();
|
||||||
if ( ! array_key_exists('hummingbird_id', $data))
|
if ( ! array_key_exists('hummingbird_id', $data))
|
||||||
{
|
{
|
||||||
$this->redirect("/manga-collection/view", 303);
|
$this->redirect('/manga-collection/view', 303);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->mangaCollectionModel->delete($data);
|
$this->mangaCollectionModel->delete($data);
|
||||||
$this->setFlashMessage("Successfully removed manga from collection.", 'success');
|
$this->setFlashMessage('Successfully removed manga from collection.', 'success');
|
||||||
|
|
||||||
$this->redirect("/manga-collection/view", 303);
|
$this->redirect('/manga-collection/view', 303);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// End of CollectionController.php
|
// End of CollectionController.php
|
@ -45,6 +45,8 @@ class Manga extends API
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -61,7 +63,7 @@ class Manga extends API
|
|||||||
* @param string $status
|
* @param string $status
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getList($status)
|
public function getList($status): array
|
||||||
{
|
{
|
||||||
if ($status === 'All')
|
if ($status === 'All')
|
||||||
{
|
{
|
||||||
@ -79,7 +81,7 @@ class Manga extends API
|
|||||||
* @param string $manga_id
|
* @param string $manga_id
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function getManga($manga_id)
|
public function getManga($manga_id): array
|
||||||
{
|
{
|
||||||
return $this->kitsuModel->getManga($manga_id);
|
return $this->kitsuModel->getManga($manga_id);
|
||||||
}
|
}
|
||||||
@ -122,7 +124,7 @@ class Manga extends API
|
|||||||
$malData = $data;
|
$malData = $data;
|
||||||
$malId = $this->kitsuModel->getMalIdForManga($malData['id']);
|
$malId = $this->kitsuModel->getMalIdForManga($malData['id']);
|
||||||
|
|
||||||
if ( ! is_null($malId))
|
if ($malId !== NULL)
|
||||||
{
|
{
|
||||||
$malData['id'] = $malId;
|
$malData['id'] = $malId;
|
||||||
$requester->addRequest($this->malModel->createListItem($malData, 'manga'), 'mal');
|
$requester->addRequest($this->malModel->createListItem($malData, 'manga'), 'mal');
|
||||||
@ -155,7 +157,7 @@ class Manga extends API
|
|||||||
|
|
||||||
$results = $requester->makeRequests();
|
$results = $requester->makeRequests();
|
||||||
$body = Json::decode($results['kitsu']);
|
$body = Json::decode($results['kitsu']);
|
||||||
$statusCode = (array_key_exists('error', $body)) ? 400: 200;
|
$statusCode = array_key_exists('error', $body) ? 400: 200;
|
||||||
|
|
||||||
return [
|
return [
|
||||||
'body' => Json::decode($results['kitsu']),
|
'body' => Json::decode($results['kitsu']),
|
||||||
@ -174,7 +176,7 @@ class Manga extends API
|
|||||||
{
|
{
|
||||||
$requester = new ParallelAPIRequest();
|
$requester = new ParallelAPIRequest();
|
||||||
|
|
||||||
if ($this->useMALAPI && ! is_null($malId))
|
if ($this->useMALAPI && $malId !== NULL)
|
||||||
{
|
{
|
||||||
$requester->addRequest($this->malModel->deleteListItem($malId, 'manga'), 'MAL');
|
$requester->addRequest($this->malModel->deleteListItem($malId, 'manga'), 'MAL');
|
||||||
}
|
}
|
||||||
@ -192,7 +194,7 @@ class Manga extends API
|
|||||||
* @param string $name
|
* @param string $name
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function search($name)
|
public function search($name): array
|
||||||
{
|
{
|
||||||
return $this->kitsuModel->search('manga', $name);
|
return $this->kitsuModel->search('manga', $name);
|
||||||
}
|
}
|
||||||
@ -203,7 +205,7 @@ class Manga extends API
|
|||||||
* @param array $data
|
* @param array $data
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
private function mapByStatus($data)
|
private function mapByStatus(array $data): array
|
||||||
{
|
{
|
||||||
$output = [
|
$output = [
|
||||||
Title::READING => [],
|
Title::READING => [],
|
||||||
|
@ -54,6 +54,9 @@ class RoutingBase {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
|
* @throws \Aviat\Ion\Exception\ConfigException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -64,7 +67,7 @@ class RoutingBase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retreive the appropriate value for the routing key
|
* Retrieve the appropriate value for the routing key
|
||||||
*
|
*
|
||||||
* @param string $key
|
* @param string $key
|
||||||
* @return mixed
|
* @return mixed
|
||||||
@ -79,10 +82,11 @@ class RoutingBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the current url path
|
* Get the current url path
|
||||||
*
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function path()
|
public function path(): string
|
||||||
{
|
{
|
||||||
$request = $this->container->get('request');
|
$request = $this->container->get('request');
|
||||||
$path = $request->getUri()->getPath();
|
$path = $request->getUri()->getPath();
|
||||||
@ -97,10 +101,11 @@ class RoutingBase {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the url segments
|
* Get the url segments
|
||||||
*
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return array
|
* @return array
|
||||||
*/
|
*/
|
||||||
public function segments()
|
public function segments(): array
|
||||||
{
|
{
|
||||||
$path = $this->path();
|
$path = $this->path();
|
||||||
return explode('/', $path);
|
return explode('/', $path);
|
||||||
@ -110,20 +115,24 @@ class RoutingBase {
|
|||||||
* Get a segment of the current url
|
* Get a segment of the current url
|
||||||
*
|
*
|
||||||
* @param int $num
|
* @param int $num
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return string|null
|
* @return string|null
|
||||||
*/
|
*/
|
||||||
public function getSegment($num)
|
public function getSegment($num): ?string
|
||||||
{
|
{
|
||||||
$segments = $this->segments();
|
$segments = $this->segments();
|
||||||
return (array_key_exists($num, $segments)) ? $segments[$num] : NULL;
|
return $segments[$num] ?? NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the last url segment
|
* Retrieve the last url segment
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function lastSegment()
|
public function lastSegment(): string
|
||||||
{
|
{
|
||||||
$segments = $this->segments();
|
$segments = $this->segments();
|
||||||
return end($segments);
|
return end($segments);
|
||||||
|
@ -34,6 +34,8 @@ class UrlGenerator extends RoutingBase {
|
|||||||
* Constructor
|
* Constructor
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -44,17 +46,17 @@ class UrlGenerator extends RoutingBase {
|
|||||||
/**
|
/**
|
||||||
* Get the base url for css/js/images
|
* Get the base url for css/js/images
|
||||||
*
|
*
|
||||||
* @param string ...$args url segments to apend to the base asset url
|
* @param string[] ...$args
|
||||||
* @return string
|
* @return string
|
||||||
*/
|
*/
|
||||||
public function assetUrl(...$args): string
|
public function assetUrl(string ...$args): string
|
||||||
{
|
{
|
||||||
$baseUrl = rtrim($this->url(""), '/');
|
$baseUrl = rtrim($this->url(''), '/')
|
||||||
$baseUrl = "{$baseUrl}" . $this->__get("asset_path");
|
. $this->__get('asset_path');
|
||||||
|
|
||||||
array_unshift($args, $baseUrl);
|
array_unshift($args, $baseUrl);
|
||||||
|
|
||||||
return implode("/", $args);
|
return implode('/', $args);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -82,7 +84,7 @@ class UrlGenerator extends RoutingBase {
|
|||||||
$segments[$i + 1] = "";
|
$segments[$i + 1] = "";
|
||||||
}
|
}
|
||||||
|
|
||||||
$path_segments[$i] = preg_replace('`{.*?}`i', $segments[$i + 1], $path_segments[$i]);
|
$path_segments[$i] = preg_replace('`{.*?}`', $segments[$i + 1], $path_segments[$i]);
|
||||||
}
|
}
|
||||||
$path = implode('/', $path_segments);
|
$path = implode('/', $path_segments);
|
||||||
|
|
||||||
@ -101,7 +103,7 @@ class UrlGenerator extends RoutingBase {
|
|||||||
$type = trim($type);
|
$type = trim($type);
|
||||||
$defaultPath = $this->__get("default_{$type}_list_path");
|
$defaultPath = $this->__get("default_{$type}_list_path");
|
||||||
|
|
||||||
if ( ! is_null($defaultPath))
|
if ($defaultPath !== NULL)
|
||||||
{
|
{
|
||||||
return $this->url("{$type}/{$defaultPath}");
|
return $this->url("{$type}/{$defaultPath}");
|
||||||
}
|
}
|
||||||
|
13
src/Util.php
13
src/Util.php
@ -18,7 +18,6 @@ namespace Aviat\AnimeClient;
|
|||||||
|
|
||||||
use Aviat\Ion\ConfigInterface;
|
use Aviat\Ion\ConfigInterface;
|
||||||
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
|
use Aviat\Ion\Di\{ContainerAware, ContainerInterface};
|
||||||
use DomainException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Utility method class
|
* Utility method class
|
||||||
@ -53,6 +52,8 @@ class Util {
|
|||||||
* Set up the Util class
|
* Set up the Util class
|
||||||
*
|
*
|
||||||
* @param ContainerInterface $container
|
* @param ContainerInterface $container
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
*/
|
*/
|
||||||
public function __construct(ContainerInterface $container)
|
public function __construct(ContainerInterface $container)
|
||||||
{
|
{
|
||||||
@ -87,12 +88,14 @@ class Util {
|
|||||||
/**
|
/**
|
||||||
* Determine whether to show the sub-menu
|
* Determine whether to show the sub-menu
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function isViewPage()
|
public function isViewPage(): bool
|
||||||
{
|
{
|
||||||
$url = $this->container->get('request')->getUri();
|
$url = $this->container->get('request')->getUri();
|
||||||
$pageSegments = explode("/", (string) $url);
|
$pageSegments = explode('/', (string) $url);
|
||||||
|
|
||||||
$intersect = array_intersect($pageSegments, self::$formPages);
|
$intersect = array_intersect($pageSegments, self::$formPages);
|
||||||
|
|
||||||
@ -103,9 +106,11 @@ class Util {
|
|||||||
* Determine whether the page is a page with a form, and
|
* Determine whether the page is a page with a form, and
|
||||||
* not suitable for redirection
|
* not suitable for redirection
|
||||||
*
|
*
|
||||||
|
* @throws \Aviat\Ion\Di\ContainerException
|
||||||
|
* @throws \Aviat\Ion\Di\NotFoundException
|
||||||
* @return boolean
|
* @return boolean
|
||||||
*/
|
*/
|
||||||
public function isFormPage()
|
public function isFormPage(): bool
|
||||||
{
|
{
|
||||||
return ! $this->isViewPage();
|
return ! $this->isViewPage();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user