|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace vfalies\tmdb; |
|
4
|
|
|
|
|
5
|
|
|
use vfalies\tmdb\Tmdb; |
|
6
|
|
|
use vfalies\tmdb\Exceptions\NotFoundException; |
|
7
|
|
|
use vfalies\tmdb\Exceptions\IncorrectParamException; |
|
8
|
|
|
|
|
9
|
|
|
class Media |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
protected $tmdb = null; |
|
13
|
|
|
protected $conf = null; |
|
14
|
|
|
protected $logger = null; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Constructor |
|
18
|
|
|
* @param Tmdb $tmdb |
|
19
|
|
|
*/ |
|
20
|
3 |
|
public function __construct(Tmdb $tmdb) |
|
21
|
|
|
{ |
|
22
|
3 |
|
$this->tmdb = $tmdb; |
|
23
|
3 |
|
$this->logger = $tmdb->logger; |
|
24
|
3 |
|
$this->conf = $this->tmdb->getConfiguration(); |
|
25
|
3 |
|
} |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* Get backdrop url |
|
29
|
|
|
* @param string $path |
|
30
|
|
|
* @param string $size |
|
31
|
|
|
* @return string|null |
|
32
|
|
|
*/ |
|
33
|
3 |
|
public function getBackdropUrl(string $path, string $size = 'w780'): string |
|
34
|
|
|
{ |
|
35
|
3 |
|
return $this->getImage('backdrop', $size, $path); |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* Get poster url |
|
40
|
|
|
* @param string $path |
|
41
|
|
|
* @param string $size |
|
42
|
|
|
* @return string |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function getPosterUrl(string $path, string $size = 'w185'): string |
|
45
|
|
|
{ |
|
46
|
1 |
|
return $this->getImage('poster', $size, $path); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Get logos url |
|
51
|
|
|
* @param string $path |
|
52
|
|
|
* @param string $size |
|
53
|
|
|
* @return string |
|
54
|
|
|
*/ |
|
55
|
1 |
|
public function getlogoUrl(string $path, string $size = 'w92'): string |
|
56
|
|
|
{ |
|
57
|
1 |
|
return $this->getImage('logo', $size, $path); |
|
58
|
|
|
} |
|
59
|
|
|
|
|
60
|
|
|
/** |
|
61
|
|
|
* Get profile url |
|
62
|
|
|
* @param string $path |
|
63
|
|
|
* @param string $size |
|
64
|
|
|
* @return string |
|
65
|
|
|
*/ |
|
66
|
1 |
|
public function getProfileUrl(string $path, string $size = 'w185'): string |
|
67
|
|
|
{ |
|
68
|
1 |
|
return $this->getImage('profile', $size, $path); |
|
69
|
|
|
} |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* Get poster url |
|
73
|
|
|
* @param string $path |
|
74
|
|
|
* @param string $size |
|
75
|
|
|
* @return string |
|
76
|
|
|
*/ |
|
77
|
1 |
|
public function getStillUrl(string $path, string $size = 'w185'): string |
|
78
|
|
|
{ |
|
79
|
1 |
|
return $this->getImage('still', $size, $path); |
|
80
|
|
|
} |
|
81
|
|
|
|
|
82
|
|
|
/** |
|
83
|
|
|
* Get image url from type and size |
|
84
|
|
|
* @param string $type |
|
85
|
|
|
* @param string $size |
|
86
|
|
|
* @param string $filepath |
|
87
|
|
|
* @return string |
|
88
|
|
|
* @throws NotFoundException |
|
89
|
|
|
* @throws IncorrectParamException |
|
90
|
|
|
*/ |
|
91
|
3 |
|
private function getImage(string $type, string $size, string $filepath): string |
|
92
|
|
|
{ |
|
93
|
3 |
|
if (!isset($this->conf->images->base_url)) { |
|
94
|
1 |
|
$this->logger->error('No image base url found from configuration'); |
|
95
|
1 |
|
throw new NotFoundException; |
|
96
|
|
|
} |
|
97
|
2 |
|
$sizes = $type . '_sizes'; |
|
98
|
2 |
|
if (!in_array($size, $this->conf->images->$sizes)) { |
|
99
|
1 |
|
$this->logger->error('Incorrect param image size', array('type' => $type, 'size' => $size, 'filepath' => $filepath)); |
|
100
|
1 |
|
throw new IncorrectParamException; |
|
101
|
|
|
} |
|
102
|
1 |
|
return $this->conf->images->base_url . $size . $filepath; |
|
103
|
|
|
} |
|
104
|
|
|
} |
|
105
|
|
|
|