HummingBirdAnimeClient/src/AnimeClient/Controller/User.php

81 lines
1.9 KiB
PHP
Raw Normal View History

2018-11-01 22:12:41 -04:00
<?php declare(strict_types=1);
/**
* Hummingbird Anime List Client
*
* An API client for Kitsu to manage anime and manga watch lists
*
2021-02-04 11:57:01 -05:00
* PHP version 8
2018-11-01 22:12:41 -04:00
*
2022-03-04 15:50:35 -05:00
* @copyright 2015 - 2022 Timothy J. Warren <tim@timshome.page>
2018-11-01 22:12:41 -04:00
* @license http://www.opensource.org/licenses/mit-license.html MIT License
2020-12-10 17:06:50 -05:00
* @version 5.2
2022-03-04 15:50:35 -05:00
* @link https://git.timshome.page/timw4mail/HummingBirdAnimeClient
2018-11-01 22:12:41 -04:00
*/
namespace Aviat\AnimeClient\Controller;
2019-12-09 14:34:23 -05:00
use Aviat\AnimeClient\API\Kitsu\Model;
use Aviat\AnimeClient\API\Kitsu\Transformer\UserTransformer;
2018-11-01 22:12:41 -04:00
use Aviat\AnimeClient\Controller as BaseController;
use Aviat\Ion\Attribute\Controller;
use Aviat\Ion\Attribute\Route;
2018-11-01 22:12:41 -04:00
use Aviat\Ion\Di\ContainerInterface;
use Aviat\Ion\Di\Exception\{ContainerException, NotFoundException};
2018-11-01 22:12:41 -04:00
/**
* Controller for handling routes that don't fit elsewhere
*/
#[Controller]
final class User extends BaseController
{
2020-04-10 20:01:46 -04:00
private Model $kitsuModel;
2018-11-01 22:12:41 -04:00
/**
* User constructor.
*
2019-12-09 14:34:23 -05:00
* @throws ContainerException
* @throws NotFoundException
*/
2018-11-01 22:12:41 -04:00
public function __construct(ContainerInterface $container)
{
parent::__construct($container);
$this->kitsuModel = $container->get('kitsu-model');
}
/**
* Show the user profile page for the configured user
*/
#[Route('default_user_info', '/me')]
2018-11-01 22:12:41 -04:00
public function me(): void
{
$this->about('me');
}
/**
* Show the user profile page
*/
#[Route('user_info', '/user/{username}')]
2018-11-01 22:12:41 -04:00
public function about(string $username): void
{
$isMainUser = $username === 'me';
$username = $isMainUser
? $this->config->get(['kitsu_username'])
: $username;
$whom = $isMainUser
? $this->config->get('whose_list')
: $username;
$rawData = $this->kitsuModel->getUserData($username);
$data = (new UserTransformer())->transform($rawData)->toArray();
2018-11-01 22:12:41 -04:00
$this->outputHTML('user/details', [
'title' => 'About ' . $whom,
'data' => $data,
2018-11-01 22:12:41 -04:00
]);
}
}