Mercurial > hg > cmmr2012-drupal-site
comparison vendor/zendframework/zend-feed/src/Writer/Extension/ITunes/Entry.php @ 2:5311817fb629
Theme updates
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 13:19:18 +0000 |
parents | c75dbcec494b |
children | a9cd425dd02b |
comparison
equal
deleted
inserted
replaced
1:0b0e5f3b1e83 | 2:5311817fb629 |
---|---|
7 * @license http://framework.zend.com/license/new-bsd New BSD License | 7 * @license http://framework.zend.com/license/new-bsd New BSD License |
8 */ | 8 */ |
9 | 9 |
10 namespace Zend\Feed\Writer\Extension\ITunes; | 10 namespace Zend\Feed\Writer\Extension\ITunes; |
11 | 11 |
12 use Zend\Feed\Uri; | |
12 use Zend\Feed\Writer; | 13 use Zend\Feed\Writer; |
13 use Zend\Feed\Writer\Extension; | |
14 use Zend\Stdlib\StringUtils; | 14 use Zend\Stdlib\StringUtils; |
15 use Zend\Stdlib\StringWrapper\StringWrapperInterface; | 15 use Zend\Stdlib\StringWrapper\StringWrapperInterface; |
16 | 16 |
17 /** | 17 /** |
18 */ | 18 */ |
74 * @return Entry | 74 * @return Entry |
75 * @throws Writer\Exception\InvalidArgumentException | 75 * @throws Writer\Exception\InvalidArgumentException |
76 */ | 76 */ |
77 public function setItunesBlock($value) | 77 public function setItunesBlock($value) |
78 { | 78 { |
79 if (!ctype_alpha($value) && strlen($value) > 0) { | 79 if (! ctype_alpha($value) && strlen($value) > 0) { |
80 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' | 80 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' |
81 . ' contain alphabetic characters'); | 81 . ' contain alphabetic characters'); |
82 } | 82 } |
83 | 83 |
84 if ($this->stringWrapper->strlen($value) > 255) { | 84 if ($this->stringWrapper->strlen($value) > 255) { |
113 { | 113 { |
114 if ($this->stringWrapper->strlen($value) > 255) { | 114 if ($this->stringWrapper->strlen($value) > 255) { |
115 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' | 115 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' |
116 . ' contain a maximum of 255 characters each'); | 116 . ' contain a maximum of 255 characters each'); |
117 } | 117 } |
118 if (!isset($this->data['authors'])) { | 118 if (! isset($this->data['authors'])) { |
119 $this->data['authors'] = []; | 119 $this->data['authors'] = []; |
120 } | 120 } |
121 $this->data['authors'][] = $value; | 121 $this->data['authors'][] = $value; |
122 return $this; | 122 return $this; |
123 } | 123 } |
130 * @throws Writer\Exception\InvalidArgumentException | 130 * @throws Writer\Exception\InvalidArgumentException |
131 */ | 131 */ |
132 public function setItunesDuration($value) | 132 public function setItunesDuration($value) |
133 { | 133 { |
134 $value = (string) $value; | 134 $value = (string) $value; |
135 if (!ctype_digit($value) | 135 if (! ctype_digit($value) |
136 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) | 136 && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) |
137 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) | 137 && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) |
138 ) { | 138 ) { |
139 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only' | 139 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only' |
140 . ' be of a specified [[HH:]MM:]SS format'); | 140 . ' be of a specified [[HH:]MM:]SS format'); |
141 } | 141 } |
142 $this->data['duration'] = $value; | 142 $this->data['duration'] = $value; |
150 * @return Entry | 150 * @return Entry |
151 * @throws Writer\Exception\InvalidArgumentException | 151 * @throws Writer\Exception\InvalidArgumentException |
152 */ | 152 */ |
153 public function setItunesExplicit($value) | 153 public function setItunesExplicit($value) |
154 { | 154 { |
155 if (!in_array($value, ['yes', 'no', 'clean'])) { | 155 if (! in_array($value, ['yes', 'no', 'clean'])) { |
156 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only' | 156 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only' |
157 . ' be one of "yes", "no" or "clean"'); | 157 . ' be one of "yes", "no" or "clean"'); |
158 } | 158 } |
159 $this->data['explicit'] = $value; | 159 $this->data['explicit'] = $value; |
160 return $this; | 160 return $this; |
161 } | 161 } |
162 | 162 |
163 /** | 163 /** |
164 * Set keywords | 164 * Set keywords |
165 * | 165 * |
166 * @deprecated since 2.10.0; itunes:keywords is no longer part of the | |
167 * iTunes podcast RSS specification. | |
166 * @param array $value | 168 * @param array $value |
167 * @return Entry | 169 * @return Entry |
168 * @throws Writer\Exception\InvalidArgumentException | 170 * @throws Writer\Exception\InvalidArgumentException |
169 */ | 171 */ |
170 public function setItunesKeywords(array $value) | 172 public function setItunesKeywords(array $value) |
171 { | 173 { |
174 trigger_error( | |
175 'itunes:keywords has been deprecated in the iTunes podcast RSS specification,' | |
176 . ' and should not be relied on.', | |
177 \E_USER_DEPRECATED | |
178 ); | |
179 | |
172 if (count($value) > 12) { | 180 if (count($value) > 12) { |
173 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' | 181 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' |
174 . ' contain a maximum of 12 terms'); | 182 . ' contain a maximum of 12 terms'); |
175 } | 183 } |
176 | 184 |
217 $this->data['summary'] = $value; | 225 $this->data['summary'] = $value; |
218 return $this; | 226 return $this; |
219 } | 227 } |
220 | 228 |
221 /** | 229 /** |
230 * Set entry image (icon) | |
231 * | |
232 * @param string $value | |
233 * @return Feed | |
234 * @throws Writer\Exception\InvalidArgumentException | |
235 */ | |
236 public function setItunesImage($value) | |
237 { | |
238 if (! is_string($value) || ! Uri::factory($value)->isValid()) { | |
239 throw new Writer\Exception\InvalidArgumentException( | |
240 'invalid parameter: "image" may only be a valid URI/IRI' | |
241 ); | |
242 } | |
243 | |
244 if (! in_array(substr($value, -3), ['jpg', 'png'])) { | |
245 throw new Writer\Exception\InvalidArgumentException( | |
246 'invalid parameter: "image" may only use file extension "jpg"' | |
247 . ' or "png" which must be the last three characters of the URI' | |
248 . ' (i.e. no query string or fragment)' | |
249 ); | |
250 } | |
251 | |
252 $this->data['image'] = $value; | |
253 return $this; | |
254 } | |
255 | |
256 /** | |
257 * Set the episode number | |
258 * | |
259 * @param int $number | |
260 * @return self | |
261 * @throws Writer\Exception\InvalidArgumentException | |
262 */ | |
263 public function setItunesEpisode($number) | |
264 { | |
265 if (! is_numeric($number) || is_float($number)) { | |
266 throw new Writer\Exception\InvalidArgumentException(sprintf( | |
267 'invalid parameter: "number" may only be an integer; received %s', | |
268 is_object($number) ? get_class($number) : gettype($number) | |
269 )); | |
270 } | |
271 | |
272 $this->data['episode'] = (int) $number; | |
273 | |
274 return $this; | |
275 } | |
276 | |
277 /** | |
278 * Set the episode type | |
279 * | |
280 * @param string $type One of "full", "trailer", or "bonus". | |
281 * @return self | |
282 * @throws Writer\Exception\InvalidArgumentException | |
283 */ | |
284 public function setItunesEpisodeType($type) | |
285 { | |
286 $validTypes = ['full', 'trailer', 'bonus']; | |
287 if (! in_array($type, $validTypes, true)) { | |
288 throw new Writer\Exception\InvalidArgumentException(sprintf( | |
289 'invalid parameter: "episodeType" MUST be one of the strings [%s]; received %s', | |
290 implode(', ', $validTypes), | |
291 is_object($type) ? get_class($type) : var_export($type, true) | |
292 )); | |
293 } | |
294 | |
295 $this->data['episodeType'] = $type; | |
296 | |
297 return $this; | |
298 } | |
299 | |
300 /** | |
301 * Set the status of closed captioning | |
302 * | |
303 * @param bool $status | |
304 * @return self | |
305 * @throws Writer\Exception\InvalidArgumentException | |
306 */ | |
307 public function setItunesIsClosedCaptioned($status) | |
308 { | |
309 if (! is_bool($status)) { | |
310 throw new Writer\Exception\InvalidArgumentException(sprintf( | |
311 'invalid parameter: "isClosedCaptioned" MUST be a boolean; received %s', | |
312 is_object($status) ? get_class($status) : var_export($status, true) | |
313 )); | |
314 } | |
315 | |
316 if (! $status) { | |
317 return $this; | |
318 } | |
319 | |
320 $this->data['isClosedCaptioned'] = true; | |
321 | |
322 return $this; | |
323 } | |
324 | |
325 /** | |
326 * Set the season number to which the episode belongs | |
327 * | |
328 * @param int $number | |
329 * @return self | |
330 * @throws Writer\Exception\InvalidArgumentException | |
331 */ | |
332 public function setItunesSeason($number) | |
333 { | |
334 if (! is_numeric($number) || is_float($number)) { | |
335 throw new Writer\Exception\InvalidArgumentException(sprintf( | |
336 'invalid parameter: "season" may only be an integer; received %s', | |
337 is_object($number) ? get_class($number) : gettype($number) | |
338 )); | |
339 } | |
340 | |
341 $this->data['season'] = (int) $number; | |
342 | |
343 return $this; | |
344 } | |
345 | |
346 /** | |
222 * Overloading to itunes specific setters | 347 * Overloading to itunes specific setters |
223 * | 348 * |
224 * @param string $method | 349 * @param string $method |
225 * @param array $params | 350 * @param array $params |
226 * @throws Writer\Exception\BadMethodCallException | 351 * @throws Writer\Exception\BadMethodCallException |
227 * @return mixed | 352 * @return mixed |
228 */ | 353 */ |
229 public function __call($method, array $params) | 354 public function __call($method, array $params) |
230 { | 355 { |
231 $point = lcfirst(substr($method, 9)); | 356 $point = lcfirst(substr($method, 9)); |
232 if (!method_exists($this, 'setItunes' . ucfirst($point)) | 357 if (! method_exists($this, 'setItunes' . ucfirst($point)) |
233 && !method_exists($this, 'addItunes' . ucfirst($point)) | 358 && ! method_exists($this, 'addItunes' . ucfirst($point)) |
234 ) { | 359 ) { |
235 throw new Writer\Exception\BadMethodCallException( | 360 throw new Writer\Exception\BadMethodCallException( |
236 'invalid method: ' . $method | 361 'invalid method: ' . $method |
237 ); | 362 ); |
238 } | 363 } |
239 if (!array_key_exists($point, $this->data) | 364 if (! array_key_exists($point, $this->data) |
240 || empty($this->data[$point]) | 365 || empty($this->data[$point]) |
241 ) { | 366 ) { |
242 return; | 367 return; |
243 } | 368 } |
244 return $this->data[$point]; | 369 return $this->data[$point]; |