|
1
|
|
|
<?php declare(strict_types = 1); |
|
2
|
|
|
/** |
|
3
|
|
|
* This file is part of the Tmdb package. |
|
4
|
|
|
* |
|
5
|
|
|
* (c) Vincent Faliès <[email protected]> |
|
6
|
|
|
* |
|
7
|
|
|
* For the full copyright and license information, please view the LICENSE |
|
8
|
|
|
* file that was distributed with this source code. |
|
9
|
|
|
* |
|
10
|
|
|
* @author Vincent Faliès <[email protected]> |
|
11
|
|
|
* @copyright Copyright (c) 2017-2020 |
|
12
|
|
|
*/ |
|
13
|
|
|
|
|
14
|
|
|
namespace VfacTmdb; |
|
15
|
|
|
|
|
16
|
|
|
use VfacTmdb\Exceptions\TmdbException; |
|
17
|
|
|
use VfacTmdb\Interfaces\TmdbInterface; |
|
18
|
|
|
use VfacTmdb\Traits\ListItems; |
|
19
|
|
|
use VfacTmdb\Traits\GeneratorTrait; |
|
20
|
|
|
|
|
21
|
|
|
/** |
|
22
|
|
|
* Change class |
|
23
|
|
|
* @package Tmdb |
|
24
|
|
|
* @author Steve Richter <[email protected]> |
|
25
|
|
|
* @copyright Copyright (c) 2017-2020 |
|
26
|
|
|
*/ |
|
27
|
|
|
class Change |
|
28
|
|
|
{ |
|
29
|
|
|
use ListItems; |
|
30
|
|
|
use GeneratorTrait; |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* Tmdb object |
|
34
|
|
|
* @var TmdbInterface |
|
35
|
|
|
*/ |
|
36
|
|
|
private $tmdb = null; |
|
37
|
|
|
/** |
|
38
|
|
|
* Logger |
|
39
|
|
|
* @var \Psr\Log\LoggerInterface |
|
40
|
|
|
*/ |
|
41
|
|
|
private $logger = null; |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Constructor |
|
45
|
|
|
* @param TmdbInterface $tmdb |
|
46
|
|
|
*/ |
|
47
|
33 |
|
public function __construct(TmdbInterface $tmdb) |
|
48
|
|
|
{ |
|
49
|
33 |
|
$this->tmdb = $tmdb; |
|
50
|
33 |
|
$this->logger = $tmdb->getLogger(); |
|
51
|
33 |
|
$this->setGeneratorTrait($tmdb); |
|
52
|
33 |
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Get changes for type |
|
56
|
|
|
* @param string $type Type to get changes for: movie / tv / person |
|
57
|
|
|
* @param array $options Array of options for the request |
|
58
|
|
|
* @return \Generator |
|
59
|
|
|
* @throws TmdbException |
|
60
|
|
|
*/ |
|
61
|
33 |
|
private function typeChanges(string $type, array $options) : \Generator |
|
62
|
|
|
{ |
|
63
|
|
|
try { |
|
64
|
33 |
|
$this->logger->debug('Starting changes for type', array('type' => $type, 'options' => $options)); |
|
65
|
|
|
|
|
66
|
33 |
|
$params = $this->checkTypeChangesOptions($options); |
|
67
|
|
|
|
|
68
|
24 |
|
$response = $this->tmdb->getRequest($type . '/changes', $params); |
|
69
|
|
|
|
|
70
|
24 |
|
$this->page = (int) $response->page; |
|
71
|
24 |
|
$this->total_pages = (int) $response->total_pages; |
|
72
|
24 |
|
$this->total_results = (int) $response->total_results; |
|
73
|
|
|
|
|
74
|
24 |
|
return $this->typeChangeGenerator($response->results); |
|
75
|
9 |
|
} catch (TmdbException $ex) { |
|
76
|
9 |
|
throw $ex; |
|
77
|
|
|
} |
|
78
|
|
|
} |
|
79
|
|
|
|
|
80
|
|
|
/** |
|
81
|
|
|
* Check the type changes API options |
|
82
|
|
|
* @param array $options |
|
83
|
|
|
* @return array |
|
84
|
|
|
*/ |
|
85
|
33 |
|
private function checkTypeChangesOptions(array $options) : array |
|
86
|
|
|
{ |
|
87
|
33 |
|
$params = []; |
|
88
|
33 |
|
$this->tmdb->checkOptionPage($options, $params); |
|
89
|
33 |
|
$this->tmdb->checkOptionDateRange($options, $params); |
|
90
|
|
|
|
|
91
|
24 |
|
return $params; |
|
92
|
|
|
} |
|
93
|
|
|
|
|
94
|
|
|
/** |
|
95
|
|
|
* Get changed Movies |
|
96
|
|
|
* @param array $options Array of options for the request |
|
97
|
|
|
* @return \Generator|Results\Change |
|
98
|
|
|
* @throws TmdbException |
|
99
|
|
|
*/ |
|
100
|
15 |
|
public function movie(array $options = array()) : \Generator |
|
101
|
|
|
{ |
|
102
|
|
|
try { |
|
103
|
15 |
|
$this->logger->debug('Starting movie changes', array('options' => $options)); |
|
104
|
15 |
|
return $this->typeChanges('movie', $options); |
|
105
|
3 |
|
} catch (TmdbException $ex) { |
|
106
|
3 |
|
throw $ex; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
|
|
110
|
|
|
/** |
|
111
|
|
|
* Get changed TVShows |
|
112
|
|
|
* @param array $options Array of options for the request |
|
113
|
|
|
* @return \Generator|Results\Change |
|
114
|
|
|
* @throws TmdbException |
|
115
|
|
|
*/ |
|
116
|
9 |
|
public function tvshow(array $options = array()) : \Generator |
|
117
|
|
|
{ |
|
118
|
|
|
try { |
|
119
|
9 |
|
$this->logger->debug('Starting TVShow changes', array('options' => $options)); |
|
120
|
9 |
|
return $this->typeChanges('tv', $options); |
|
121
|
3 |
|
} catch (TmdbException $ex) { |
|
122
|
3 |
|
throw $ex; |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
|
126
|
|
|
/** |
|
127
|
|
|
* Get changed People |
|
128
|
|
|
* @param array $options Array of options for the request |
|
129
|
|
|
* @return \Generator|Results\Change |
|
130
|
|
|
* @throws TmdbException |
|
131
|
|
|
*/ |
|
132
|
9 |
|
public function person(array $options = array()) : \Generator |
|
133
|
|
|
{ |
|
134
|
|
|
try { |
|
135
|
9 |
|
$this->logger->debug('Starting person changes', array('options' => $options)); |
|
136
|
9 |
|
return $this->typeChanges('person', $options); |
|
137
|
3 |
|
} catch (TmdbException $ex) { |
|
138
|
3 |
|
throw $ex; |
|
139
|
|
|
} |
|
140
|
|
|
} |
|
141
|
|
|
} |
|
142
|
|
|
|