|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace vfalies\tmdb\Items; |
|
4
|
|
|
|
|
5
|
|
|
use vfalies\tmdb\Abstracts\Item; |
|
6
|
|
|
use vfalies\tmdb\Interfaces\Items\CollectionInterface; |
|
7
|
|
|
use vfalies\tmdb\Tmdb; |
|
8
|
|
|
use vfalies\tmdb\lib\Guzzle\Client as HttpClient; |
|
9
|
|
|
use vfalies\tmdb\Exceptions\NotFoundException; |
|
10
|
|
|
use vfalies\tmdb\Traits\ElementTrait; |
|
11
|
|
|
use vfalies\tmdb\Results\Movie; |
|
|
|
|
|
|
12
|
|
|
use vfalies\tmdb\Results\Image; |
|
13
|
|
|
|
|
14
|
|
|
class Collection extends Item implements CollectionInterface |
|
15
|
|
|
{ |
|
16
|
|
|
|
|
17
|
|
|
use ElementTrait; |
|
18
|
|
|
|
|
19
|
|
|
// Private loaded data |
|
20
|
|
|
protected $data = null; |
|
21
|
|
|
protected $conf = null; |
|
22
|
|
|
protected $id = null; |
|
23
|
|
|
protected $tmdb = null; |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Constructor |
|
27
|
|
|
* @param Tmdb $tmdb |
|
28
|
|
|
* @param int $collection_id |
|
29
|
|
|
* @param array $options |
|
30
|
|
|
*/ |
|
31
|
19 |
|
public function __construct(Tmdb $tmdb, $collection_id, array $options = array()) |
|
32
|
|
|
{ |
|
33
|
19 |
|
parent::__construct($tmdb, $collection_id, $options, 'collection'); |
|
34
|
18 |
|
} |
|
35
|
|
|
|
|
36
|
|
|
/** |
|
37
|
|
|
* Get collection ID |
|
38
|
|
|
* @return int |
|
39
|
|
|
*/ |
|
40
|
2 |
|
public function getId() |
|
41
|
|
|
{ |
|
42
|
2 |
|
return $this->id; |
|
43
|
|
|
} |
|
44
|
|
|
|
|
45
|
|
|
/** |
|
46
|
|
|
* Get collection name |
|
47
|
|
|
* @return string |
|
48
|
|
|
* @throws NotFoundException |
|
49
|
|
|
*/ |
|
50
|
2 |
|
public function getName() |
|
51
|
|
|
{ |
|
52
|
2 |
|
if (isset($this->data->name)) { |
|
53
|
1 |
|
return $this->data->name; |
|
54
|
|
|
} |
|
55
|
1 |
|
$this->logger->error('Collection name not found', array('collection_id' => $this->id)); |
|
56
|
1 |
|
throw new NotFoundException; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Get collection parts |
|
61
|
|
|
* @return Generator |
|
62
|
|
|
*/ |
|
63
|
2 |
|
public function getParts() |
|
64
|
|
|
{ |
|
65
|
2 |
|
if (!empty($this->data->parts)) { |
|
66
|
1 |
|
foreach ($this->data->parts as $part) { |
|
67
|
1 |
|
$movie = new Movie($this->tmdb, $part); |
|
68
|
1 |
|
yield $movie; |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
2 |
|
} |
|
72
|
|
|
|
|
73
|
9 |
|
public function getBackdrops() |
|
74
|
|
|
{ |
|
75
|
9 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/collection/'.(int) $this->id.'/images', null, $this->params); |
|
76
|
|
|
|
|
77
|
9 |
|
foreach ($data->backdrops as $b) |
|
78
|
|
|
{ |
|
79
|
9 |
|
$image = new Image($this->tmdb, $this->id, $b); |
|
80
|
9 |
|
yield $image; |
|
81
|
|
|
} |
|
82
|
1 |
|
} |
|
83
|
|
|
|
|
84
|
1 |
|
public function getPosters() |
|
85
|
|
|
{ |
|
86
|
1 |
|
$data = $this->tmdb->sendRequest(new HttpClient(new \GuzzleHttp\Client()), '/collection/'.(int) $this->id.'/images', null, $this->params); |
|
87
|
|
|
|
|
88
|
1 |
|
foreach ($data->posters as $b) |
|
89
|
|
|
{ |
|
90
|
1 |
|
$image = new Image($this->tmdb, $this->id, $b); |
|
91
|
1 |
|
yield $image; |
|
92
|
|
|
} |
|
93
|
1 |
|
} |
|
94
|
|
|
} |
|
95
|
|
|
|
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: