|
1
|
|
|
<?php declare(strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* Anime List Client |
|
4
|
|
|
* |
|
5
|
|
|
* An API client for Kitsu and MyAnimeList to manage anime and manga watch lists |
|
6
|
|
|
* |
|
7
|
|
|
* PHP version 7 |
|
8
|
|
|
* |
|
9
|
|
|
* @package AnimeListClient |
|
10
|
|
|
* @author Timothy J. Warren <[email protected]> |
|
11
|
|
|
* @copyright 2015 - 2017 Timothy J. Warren |
|
12
|
|
|
* @license http://www.opensource.org/licenses/mit-license.html MIT License |
|
13
|
|
|
* @version 4.0 |
|
14
|
|
|
* @link https://github.com/timw4mail/HummingBirdAnimeClient |
|
15
|
|
|
*/ |
|
16
|
|
|
|
|
17
|
|
|
namespace Aviat\AnimeClient\API\Kitsu\Transformer; |
|
18
|
|
|
|
|
19
|
|
|
use Aviat\AnimeClient\API\{JsonAPI, Kitsu}; |
|
20
|
|
|
use Aviat\Ion\Transformer\AbstractTransformer; |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Transformer for anime description page |
|
24
|
|
|
*/ |
|
25
|
|
|
class AnimeTransformer extends AbstractTransformer { |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Convert raw api response to a more |
|
29
|
|
|
* logical and workable structure |
|
30
|
|
|
* |
|
31
|
|
|
* @param array $item API library item |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
|
|
public function transform($item) |
|
35
|
|
|
{ |
|
36
|
|
|
$item['included'] = JsonAPI::organizeIncludes($item['included']); |
|
37
|
|
|
$item['genres'] = array_column($item['included']['genres'], 'name') ?? []; |
|
38
|
|
|
sort($item['genres']); |
|
39
|
|
|
|
|
40
|
|
|
$titles = Kitsu::filterTitles($item); |
|
41
|
|
|
|
|
42
|
|
|
return [ |
|
43
|
|
|
'slug' => $item['slug'], |
|
44
|
|
|
'title' => $titles[0], |
|
45
|
|
|
'titles' => $titles, |
|
46
|
|
|
'status' => Kitsu::getAiringStatus($item['startDate'], $item['endDate']), |
|
47
|
|
|
'cover_image' => $item['posterImage']['small'], |
|
48
|
|
|
'show_type' => $this->string($item['showType'])->upperCaseFirst()->__toString(), |
|
49
|
|
|
'episode_count' => $item['episodeCount'], |
|
50
|
|
|
'episode_length' => $item['episodeLength'], |
|
51
|
|
|
'synopsis' => $item['synopsis'], |
|
52
|
|
|
'age_rating' => $item['ageRating'], |
|
53
|
|
|
'age_rating_guide' => $item['ageRatingGuide'], |
|
54
|
|
|
'url' => "https://kitsu.io/anime/{$item['slug']}", |
|
55
|
|
|
'genres' => $item['genres'], |
|
56
|
|
|
'streaming_links' => Kitsu::parseStreamingLinks($item['included']) |
|
57
|
|
|
]; |
|
58
|
|
|
} |
|
59
|
|
|
} |