1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* Created by PhpStorm. |
4
|
|
|
* User: oguzu |
5
|
|
|
* Date: 29-3-2017 |
6
|
|
|
* Time: 16:29 |
7
|
|
|
*/ |
8
|
|
|
|
9
|
|
|
namespace Pbxg33k\MusicInfo\Service\VocaDB\Endpoint; |
10
|
|
|
|
11
|
|
|
use Doctrine\Common\Collections\ArrayCollection; |
12
|
|
|
use Pbxg33k\MusicInfo\Model\BaseModel; |
13
|
|
|
use Pbxg33k\MusicInfo\Model\IMusicServiceEndpoint; |
14
|
|
|
use Pbxg33k\VocaDB\Song as TrackEndpoint; |
15
|
|
|
use Pbxg33k\VocaDB\Models\Track as VocaDBTrackModel; |
16
|
|
|
use Pbxg33k\MusicInfo\Model\Track as TrackModel; |
17
|
|
|
use Pbxg33k\VocaDB\Client; |
18
|
|
|
use Psr\Cache\CacheItemPoolInterface; |
19
|
|
|
|
20
|
|
|
class Track extends TrackEndpoint implements IMusicServiceEndpoint |
21
|
|
|
{ |
22
|
|
|
const DATA_SOURCE = 'vocadb'; |
23
|
|
|
|
24
|
|
|
/** |
25
|
|
|
* @var CacheItemPoolInterface |
26
|
|
|
*/ |
27
|
|
|
protected $cache; |
28
|
|
|
|
29
|
|
|
protected $parent; |
30
|
|
|
|
31
|
39 |
|
public function __construct(Client $client, CacheItemPoolInterface $cache) |
32
|
|
|
{ |
33
|
39 |
|
$this->setCache($cache); |
34
|
39 |
|
parent::__construct($client); |
35
|
39 |
|
} |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* @param CacheItemPoolInterface $cacheItemPool |
39
|
|
|
* @return $this |
40
|
|
|
*/ |
41
|
39 |
|
public function setCache(CacheItemPoolInterface $cacheItemPool) |
42
|
|
|
{ |
43
|
39 |
|
$this->cache = $cacheItemPool; |
44
|
|
|
|
45
|
39 |
|
return $this; |
46
|
|
|
} |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @param $apiService |
50
|
|
|
* |
51
|
|
|
* @return Track |
52
|
|
|
*/ |
53
|
|
|
public function setParent($apiService) |
54
|
|
|
{ |
55
|
|
|
$this->parent = $apiService; |
56
|
|
|
|
57
|
|
|
return $this; |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Transform single item to model |
62
|
|
|
* |
63
|
|
|
* @param VocaDBTrackModel $raw |
64
|
|
|
* |
65
|
|
|
* @return BaseModel |
66
|
|
|
*/ |
67
|
|
|
public function transformSingle($raw) |
68
|
|
|
{ |
69
|
|
|
$object = new TrackModel(); |
70
|
|
|
$object |
71
|
|
|
->setId($raw->getId()) |
72
|
|
|
->setName($raw->getName()); |
73
|
|
|
|
74
|
|
|
var_dump( |
|
|
|
|
75
|
|
|
__FILE__, __LINE__, |
76
|
|
|
$raw |
77
|
|
|
); die(); |
|
|
|
|
78
|
|
|
|
79
|
|
|
return $object; |
|
|
|
|
80
|
|
|
|
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Transform collection to models |
85
|
|
|
* |
86
|
|
|
* @param $raw |
87
|
|
|
* |
88
|
|
|
* @return ArrayCollection |
89
|
|
|
*/ |
90
|
|
|
public function transformCollection($raw) |
91
|
|
|
{ |
92
|
|
|
$collection = new ArrayCollection(); |
93
|
|
|
foreach ($raw->collection as $artist) { |
94
|
|
|
$collection->add($this->transformSingle($artist)); |
95
|
|
|
} |
96
|
|
|
|
97
|
|
|
return $collection; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
/** |
101
|
|
|
* Transform to models |
102
|
|
|
* |
103
|
|
|
* @param $raw |
104
|
|
|
* |
105
|
|
|
* @return ArrayCollection |
106
|
|
|
*/ |
107
|
|
|
public function transform($raw) |
108
|
|
|
{ |
109
|
|
|
return $this->transformCollection($raw); |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @return mixed |
114
|
|
|
*/ |
115
|
|
|
public function getParent() |
116
|
|
|
{ |
117
|
|
|
return $this->parent; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @param $guid |
122
|
|
|
* |
123
|
|
|
* @return ArrayCollection |
124
|
|
|
*/ |
125
|
|
|
public function getByGuid($guid, $complete = true) |
126
|
|
|
{ |
127
|
|
|
return $this->transform(parent::getById($guid, $complete)); |
|
|
|
|
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function getByName($name, $complete = true) |
131
|
|
|
{ |
132
|
|
|
return $this->transform(parent::getByName($name, $complete)); |
133
|
|
|
} |
134
|
|
|
} |
135
|
|
|
|