|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace vfalies\tmdb\Items; |
|
4
|
|
|
|
|
5
|
|
|
abstract class Item |
|
6
|
|
|
{ |
|
7
|
|
|
/** |
|
8
|
|
|
* Constructor |
|
9
|
|
|
* @param \vfalies\tmdb\Tmdb $tmdb |
|
10
|
|
|
* @param int $item_id |
|
11
|
|
|
* @param array $options |
|
12
|
|
|
* @param string $item_name |
|
13
|
|
|
* @throws \Exception |
|
14
|
|
|
*/ |
|
15
|
71 |
|
public function __construct(\vfalies\tmdb\Tmdb $tmdb, int $item_id, array $options, string $item_name) |
|
16
|
|
|
{ |
|
17
|
|
|
try |
|
18
|
|
|
{ |
|
19
|
71 |
|
$this->id = (int) $item_id; |
|
|
|
|
|
|
20
|
71 |
|
$this->tmdb = $tmdb; |
|
|
|
|
|
|
21
|
71 |
|
$this->conf = $this->tmdb->getConfiguration(); |
|
|
|
|
|
|
22
|
71 |
|
$params = $this->tmdb->checkOptions($options); |
|
23
|
71 |
|
$this->data = $this->tmdb->sendRequest(new \vfalies\tmdb\CurlRequest(), $item_name . '/'.(int) $item_id, null, $params); |
|
|
|
|
|
|
24
|
|
|
} |
|
25
|
3 |
|
catch (\Exception $ex) |
|
26
|
|
|
{ |
|
27
|
3 |
|
throw new \Exception($ex->getMessage(), $ex->getCode(), $ex); |
|
28
|
|
|
} |
|
29
|
68 |
|
} |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* Get item poster |
|
33
|
|
|
* @param string $size |
|
34
|
|
|
* @return string |
|
35
|
|
|
*/ |
|
36
|
12 |
View Code Duplication |
public function getPoster(string $size = 'w185'): string |
|
|
|
|
|
|
37
|
|
|
{ |
|
38
|
12 |
|
if (isset($this->data->poster_path)) |
|
39
|
|
|
{ |
|
40
|
9 |
|
if (!isset($this->conf->images->base_url)) |
|
41
|
|
|
{ |
|
42
|
3 |
|
throw new \Exception('base_url configuration not found'); |
|
43
|
|
|
} |
|
44
|
6 |
|
if (!in_array($size, $this->conf->images->poster_sizes)) |
|
45
|
|
|
{ |
|
46
|
3 |
|
throw new \Exception('Incorrect poster size : ' . $size); |
|
47
|
|
|
} |
|
48
|
3 |
|
return $this->conf->images->base_url . $size . $this->data->poster_path; |
|
49
|
|
|
} |
|
50
|
3 |
|
return ''; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
/** |
|
54
|
|
|
* Get item backdrop |
|
55
|
|
|
* @param string $size |
|
56
|
|
|
* @return string|null |
|
57
|
|
|
*/ |
|
58
|
12 |
View Code Duplication |
public function getBackdrop(string $size = 'w780'): string |
|
|
|
|
|
|
59
|
|
|
{ |
|
60
|
12 |
|
if (isset($this->data->backdrop_path)) |
|
61
|
|
|
{ |
|
62
|
9 |
|
if (!isset($this->conf->images->base_url)) |
|
63
|
|
|
{ |
|
64
|
3 |
|
throw new \Exception('base_url configuration not found'); |
|
65
|
|
|
} |
|
66
|
6 |
|
if (!in_array($size, $this->conf->images->backdrop_sizes)) |
|
67
|
|
|
{ |
|
68
|
3 |
|
throw new \Exception('Incorrect backdrop size : ' . $size); |
|
69
|
|
|
} |
|
70
|
3 |
|
return $this->conf->images->base_url . $size . $this->data->backdrop_path; |
|
71
|
|
|
} |
|
72
|
3 |
|
return ''; |
|
73
|
|
|
} |
|
74
|
|
|
|
|
75
|
|
|
} |
|
76
|
|
|
|
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: