|
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\Ion\Transformer\AbstractTransformer; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Transformer for anime description page |
|
23
|
|
|
*/ |
|
24
|
|
|
class MangaTransformer extends AbstractTransformer { |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Convert raw api response to a more |
|
28
|
|
|
* logical and workable structure |
|
29
|
|
|
* |
|
30
|
|
|
* @param array $item API library item |
|
31
|
|
|
* @return array |
|
32
|
|
|
*/ |
|
33
|
|
|
public function transform($item) |
|
34
|
|
|
{ |
|
35
|
|
|
$genres = []; |
|
36
|
|
|
|
|
37
|
|
|
foreach($item['included'] as $included) |
|
38
|
|
|
{ |
|
39
|
|
|
if ($included['type'] === 'genres') |
|
40
|
|
|
{ |
|
41
|
|
|
$genres[] = $included['attributes']['name']; |
|
42
|
|
|
} |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
sort($genres); |
|
46
|
|
|
|
|
47
|
|
|
return [ |
|
48
|
|
|
'title' => $item['canonicalTitle'], |
|
49
|
|
|
'en_title' => $item['titles']['en'], |
|
50
|
|
|
'jp_title' => $item['titles']['en_jp'], |
|
51
|
|
|
'cover_image' => $item['posterImage']['small'], |
|
52
|
|
|
'manga_type' => $item['mangaType'], |
|
53
|
|
|
'chapter_count' => $this->count($item['chapterCount']), |
|
54
|
|
|
'volume_count' => $this->count($item['volumeCount']), |
|
55
|
|
|
'synopsis' => $item['synopsis'], |
|
56
|
|
|
'url' => "https://kitsu.io/manga/{$item['slug']}", |
|
57
|
|
|
'genres' => $genres, |
|
58
|
|
|
]; |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
private function count(int $value = null) |
|
62
|
|
|
{ |
|
63
|
|
|
return ((int)$value === 0) |
|
64
|
|
|
? '-' |
|
65
|
|
|
: $value; |
|
66
|
|
|
} |
|
67
|
|
|
} |