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