2017-03-30 16:49:48 -04:00
|
|
|
<?php declare(strict_types=1);
|
|
|
|
/**
|
|
|
|
* Hummingbird Anime List Client
|
|
|
|
*
|
2018-08-22 13:48:27 -04:00
|
|
|
* An API client for Kitsu to manage anime and manga watch lists
|
2017-03-30 16:49:48 -04:00
|
|
|
*
|
2020-04-10 15:39:39 -04:00
|
|
|
* PHP version 7.4
|
2017-03-30 16:49:48 -04:00
|
|
|
*
|
|
|
|
* @package HummingbirdAnimeClient
|
|
|
|
* @author Timothy J. Warren <tim@timshomepage.net>
|
2020-01-08 15:39:49 -05:00
|
|
|
* @copyright 2015 - 2020 Timothy J. Warren
|
2017-03-30 16:49:48 -04:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License
|
2020-04-10 15:39:39 -04:00
|
|
|
* @version 5
|
2017-03-30 16:49:48 -04:00
|
|
|
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
|
|
|
|
*/
|
|
|
|
|
2017-04-05 13:01:51 -04:00
|
|
|
namespace Aviat\AnimeClient\Controller;
|
|
|
|
|
2019-12-09 14:34:23 -05:00
|
|
|
use Aviat\AnimeClient\API\Kitsu\Model;
|
2017-04-05 13:01:51 -04:00
|
|
|
use Aviat\AnimeClient\Controller as BaseController;
|
2018-11-08 11:36:42 -05:00
|
|
|
use Aviat\AnimeClient\API\Kitsu\Transformer\CharacterTransformer;
|
|
|
|
|
|
|
|
use Aviat\Ion\Di\ContainerInterface;
|
2019-12-09 14:34:23 -05:00
|
|
|
use Aviat\Ion\Di\Exception\ContainerException;
|
|
|
|
use Aviat\Ion\Di\Exception\NotFoundException;
|
2017-04-05 13:01:51 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Controller for character description pages
|
|
|
|
*/
|
2018-10-19 09:30:27 -04:00
|
|
|
class Character extends BaseController {
|
2017-04-05 13:01:51 -04:00
|
|
|
|
2018-11-08 11:36:42 -05:00
|
|
|
/**
|
2019-12-09 14:34:23 -05:00
|
|
|
* @var Model
|
2018-11-08 11:36:42 -05:00
|
|
|
*/
|
2020-04-10 20:01:46 -04:00
|
|
|
private Model $model;
|
2018-11-08 11:36:42 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Character constructor.
|
|
|
|
*
|
|
|
|
* @param ContainerInterface $container
|
2019-12-09 14:34:23 -05:00
|
|
|
* @throws ContainerException
|
|
|
|
* @throws NotFoundException
|
2018-11-08 11:36:42 -05:00
|
|
|
*/
|
|
|
|
public function __construct(ContainerInterface $container)
|
|
|
|
{
|
|
|
|
parent::__construct($container);
|
|
|
|
$this->model = $container->get('kitsu-model');
|
|
|
|
}
|
2017-04-05 13:01:51 -04:00
|
|
|
|
2018-02-02 09:50:58 -05:00
|
|
|
/**
|
|
|
|
* Show information about a character
|
|
|
|
*
|
|
|
|
* @param string $slug
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function index(string $slug): void
|
2017-04-05 13:01:51 -04:00
|
|
|
{
|
2018-11-08 11:36:42 -05:00
|
|
|
$rawData = $this->model->getCharacter($slug);
|
2017-04-05 13:01:51 -04:00
|
|
|
|
|
|
|
if (( ! array_key_exists('data', $rawData)) || empty($rawData['data']))
|
|
|
|
{
|
2018-01-16 14:58:07 -05:00
|
|
|
$this->notFound(
|
2017-04-05 13:01:51 -04:00
|
|
|
$this->formatTitle(
|
|
|
|
'Characters',
|
|
|
|
'Character not found'
|
|
|
|
),
|
|
|
|
'Character Not Found'
|
|
|
|
);
|
2018-01-16 14:58:07 -05:00
|
|
|
|
|
|
|
return;
|
2017-04-05 13:01:51 -04:00
|
|
|
}
|
|
|
|
|
2018-11-08 11:36:42 -05:00
|
|
|
$data = (new CharacterTransformer())->transform($rawData)->toArray();
|
2018-10-19 09:30:27 -04:00
|
|
|
|
2018-11-08 11:36:42 -05:00
|
|
|
$this->outputHTML('character/details', [
|
2017-04-05 13:01:51 -04:00
|
|
|
'title' => $this->formatTitle(
|
|
|
|
'Characters',
|
2018-11-08 11:36:42 -05:00
|
|
|
$data['name']
|
2017-04-05 13:01:51 -04:00
|
|
|
),
|
|
|
|
'data' => $data,
|
2018-11-08 11:36:42 -05:00
|
|
|
]);
|
2017-04-05 13:01:51 -04:00
|
|
|
}
|
2017-03-08 12:55:49 -05:00
|
|
|
}
|