HummingBirdAnimeClient/src/AnimeClient/Controller/People.php

84 lines
1.9 KiB
PHP
Raw Normal View History

<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu to manage anime and manga watch lists
*
2020-12-10 17:06:50 -05:00
* PHP version 7.4+
*
* @package HummingbirdAnimeClient
* @author Timothy J. Warren <tim@timshomepage.net>
2021-01-13 01:52:03 -05:00
* @copyright 2015 - 2021 Timothy J. Warren
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
* @link https://git.timshomepage.net/timw4mail/HummingBirdAnimeClient
*/
namespace Aviat\AnimeClient\Controller;
2019-12-09 14:34:23 -05:00
use Aviat\AnimeClient\API\Kitsu\Model;
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\AnimeClient\API\Kitsu\Transformer\PersonTransformer;
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;
/**
* Controller for People pages
*/
final class People extends BaseController {
/**
2019-12-09 14:34:23 -05:00
* @var Model
*/
2020-04-10 20:01:46 -04:00
private Model $model;
/**
* People constructor.
*
* @param ContainerInterface $container
2019-12-09 14:34:23 -05:00
* @throws ContainerException
* @throws NotFoundException
*/
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->model = $container->get('kitsu-model');
}
/**
* Show information about a person
*
* @param string $slug
* @return void
* @throws ContainerException
* @throws NotFoundException
*/
public function index(string $slug): void
{
$rawData = $this->model->getPerson($slug);
$data = (new PersonTransformer())->transform($rawData)->toArray();
if (( ! array_key_exists('data', $rawData)) || empty($rawData['data']))
{
$this->notFound(
$this->formatTitle(
'People',
'Person not found'
),
'Person Not Found'
);
return;
}
$this->outputHTML('person/details', [
'title' => $this->formatTitle(
'People',
$data['name']
),
'data' => $data,
]);
}
}