Mercurial > hg > cmmr2012-drupal-site
comparison vendor/zendframework/zend-feed/src/Writer/Extension/ITunes/Feed.php @ 2:5311817fb629
Theme updates
author | Chris Cannam |
---|---|
date | Tue, 10 Jul 2018 13:19:18 +0000 |
parents | c75dbcec494b |
children |
comparison
equal
deleted
inserted
replaced
1:0b0e5f3b1e83 | 2:5311817fb629 |
---|---|
75 * @return Feed | 75 * @return Feed |
76 * @throws Writer\Exception\InvalidArgumentException | 76 * @throws Writer\Exception\InvalidArgumentException |
77 */ | 77 */ |
78 public function setItunesBlock($value) | 78 public function setItunesBlock($value) |
79 { | 79 { |
80 if (!ctype_alpha($value) && strlen($value) > 0) { | 80 if (! ctype_alpha($value) && strlen($value) > 0) { |
81 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' | 81 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' |
82 . ' contain alphabetic characters'); | 82 . ' contain alphabetic characters'); |
83 } | 83 } |
84 if ($this->stringWrapper->strlen($value) > 255) { | 84 if ($this->stringWrapper->strlen($value) > 255) { |
85 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' | 85 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "block" may only' |
114 { | 114 { |
115 if ($this->stringWrapper->strlen($value) > 255) { | 115 if ($this->stringWrapper->strlen($value) > 255) { |
116 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' | 116 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "author" may only' |
117 . ' contain a maximum of 255 characters each'); | 117 . ' contain a maximum of 255 characters each'); |
118 } | 118 } |
119 if (!isset($this->data['authors'])) { | 119 if (! isset($this->data['authors'])) { |
120 $this->data['authors'] = []; | 120 $this->data['authors'] = []; |
121 } | 121 } |
122 $this->data['authors'][] = $value; | 122 $this->data['authors'][] = $value; |
123 return $this; | 123 return $this; |
124 } | 124 } |
130 * @return Feed | 130 * @return Feed |
131 * @throws Writer\Exception\InvalidArgumentException | 131 * @throws Writer\Exception\InvalidArgumentException |
132 */ | 132 */ |
133 public function setItunesCategories(array $values) | 133 public function setItunesCategories(array $values) |
134 { | 134 { |
135 if (!isset($this->data['categories'])) { | 135 if (! isset($this->data['categories'])) { |
136 $this->data['categories'] = []; | 136 $this->data['categories'] = []; |
137 } | 137 } |
138 foreach ($values as $key => $value) { | 138 foreach ($values as $key => $value) { |
139 if (!is_array($value)) { | 139 if (! is_array($value)) { |
140 if ($this->stringWrapper->strlen($value) > 255) { | 140 if ($this->stringWrapper->strlen($value) > 255) { |
141 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' | 141 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "category" may only' |
142 . ' contain a maximum of 255 characters each'); | 142 . ' contain a maximum of 255 characters each'); |
143 } | 143 } |
144 $this->data['categories'][] = $value; | 144 $this->data['categories'][] = $value; |
167 * @return Feed | 167 * @return Feed |
168 * @throws Writer\Exception\InvalidArgumentException | 168 * @throws Writer\Exception\InvalidArgumentException |
169 */ | 169 */ |
170 public function setItunesImage($value) | 170 public function setItunesImage($value) |
171 { | 171 { |
172 if (!Uri::factory($value)->isValid()) { | 172 if (! is_string($value) || ! Uri::factory($value)->isValid()) { |
173 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "image" may only' | 173 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "image" may only' |
174 . ' be a valid URI/IRI'); | 174 . ' be a valid URI/IRI'); |
175 } | 175 } |
176 if (!in_array(substr($value, -3), ['jpg', 'png'])) { | 176 if (! in_array(substr($value, -3), ['jpg', 'png'])) { |
177 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "image" may only' | 177 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "image" may only' |
178 . ' use file extension "jpg" or "png" which must be the last three' | 178 . ' use file extension "jpg" or "png" which must be the last three' |
179 . ' characters of the URI (i.e. no query string or fragment)'); | 179 . ' characters of the URI (i.e. no query string or fragment)'); |
180 } | 180 } |
181 $this->data['image'] = $value; | 181 $this->data['image'] = $value; |
190 * @throws Writer\Exception\InvalidArgumentException | 190 * @throws Writer\Exception\InvalidArgumentException |
191 */ | 191 */ |
192 public function setItunesDuration($value) | 192 public function setItunesDuration($value) |
193 { | 193 { |
194 $value = (string) $value; | 194 $value = (string) $value; |
195 if (!ctype_digit($value) | 195 if (! ctype_digit($value) |
196 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) | 196 && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}$/", $value) |
197 && !preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) | 197 && ! preg_match("/^\d+:[0-5]{1}[0-9]{1}:[0-5]{1}[0-9]{1}$/", $value) |
198 ) { | 198 ) { |
199 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only' | 199 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "duration" may only' |
200 . ' be of a specified [[HH:]MM:]SS format'); | 200 . ' be of a specified [[HH:]MM:]SS format'); |
201 } | 201 } |
202 $this->data['duration'] = $value; | 202 $this->data['duration'] = $value; |
210 * @return Feed | 210 * @return Feed |
211 * @throws Writer\Exception\InvalidArgumentException | 211 * @throws Writer\Exception\InvalidArgumentException |
212 */ | 212 */ |
213 public function setItunesExplicit($value) | 213 public function setItunesExplicit($value) |
214 { | 214 { |
215 if (!in_array($value, ['yes', 'no', 'clean'])) { | 215 if (! in_array($value, ['yes', 'no', 'clean'])) { |
216 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only' | 216 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "explicit" may only' |
217 . ' be one of "yes", "no" or "clean"'); | 217 . ' be one of "yes", "no" or "clean"'); |
218 } | 218 } |
219 $this->data['explicit'] = $value; | 219 $this->data['explicit'] = $value; |
220 return $this; | 220 return $this; |
221 } | 221 } |
222 | 222 |
223 /** | 223 /** |
224 * Set feed keywords | 224 * Set feed keywords |
225 * | 225 * |
226 * @deprecated since 2.10.0; itunes:keywords is no longer part of the | |
227 * iTunes podcast RSS specification. | |
226 * @param array $value | 228 * @param array $value |
227 * @return Feed | 229 * @return Feed |
228 * @throws Writer\Exception\InvalidArgumentException | 230 * @throws Writer\Exception\InvalidArgumentException |
229 */ | 231 */ |
230 public function setItunesKeywords(array $value) | 232 public function setItunesKeywords(array $value) |
231 { | 233 { |
234 trigger_error( | |
235 'itunes:keywords has been deprecated in the iTunes podcast RSS specification,' | |
236 . ' and should not be relied on.', | |
237 \E_USER_DEPRECATED | |
238 ); | |
239 | |
232 if (count($value) > 12) { | 240 if (count($value) > 12) { |
233 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' | 241 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "keywords" may only' |
234 . ' contain a maximum of 12 terms'); | 242 . ' contain a maximum of 12 terms'); |
235 } | 243 } |
236 $concat = implode(',', $value); | 244 $concat = implode(',', $value); |
250 * @return Feed | 258 * @return Feed |
251 * @throws Writer\Exception\InvalidArgumentException | 259 * @throws Writer\Exception\InvalidArgumentException |
252 */ | 260 */ |
253 public function setItunesNewFeedUrl($value) | 261 public function setItunesNewFeedUrl($value) |
254 { | 262 { |
255 if (!Uri::factory($value)->isValid()) { | 263 if (! Uri::factory($value)->isValid()) { |
256 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "newFeedUrl" may only' | 264 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "newFeedUrl" may only' |
257 . ' be a valid URI/IRI'); | 265 . ' be a valid URI/IRI'); |
258 } | 266 } |
259 $this->data['newFeedUrl'] = $value; | 267 $this->data['newFeedUrl'] = $value; |
260 return $this; | 268 return $this; |
281 * @return Feed | 289 * @return Feed |
282 * @throws Writer\Exception\InvalidArgumentException | 290 * @throws Writer\Exception\InvalidArgumentException |
283 */ | 291 */ |
284 public function addItunesOwner(array $value) | 292 public function addItunesOwner(array $value) |
285 { | 293 { |
286 if (!isset($value['name']) || !isset($value['email'])) { | 294 if (! isset($value['name']) || ! isset($value['email'])) { |
287 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" must' | 295 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" must' |
288 . ' be an array containing keys "name" and "email"'); | 296 . ' be an array containing keys "name" and "email"'); |
289 } | 297 } |
290 if ($this->stringWrapper->strlen($value['name']) > 255 | 298 if ($this->stringWrapper->strlen($value['name']) > 255 |
291 || $this->stringWrapper->strlen($value['email']) > 255 | 299 || $this->stringWrapper->strlen($value['email']) > 255 |
292 ) { | 300 ) { |
293 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" may only' | 301 throw new Writer\Exception\InvalidArgumentException('invalid parameter: any "owner" may only' |
294 . ' contain a maximum of 255 characters each for "name" and "email"'); | 302 . ' contain a maximum of 255 characters each for "name" and "email"'); |
295 } | 303 } |
296 if (!isset($this->data['owners'])) { | 304 if (! isset($this->data['owners'])) { |
297 $this->data['owners'] = []; | 305 $this->data['owners'] = []; |
298 } | 306 } |
299 $this->data['owners'][] = $value; | 307 $this->data['owners'][] = $value; |
300 return $this; | 308 return $this; |
301 } | 309 } |
329 if ($this->stringWrapper->strlen($value) > 4000) { | 337 if ($this->stringWrapper->strlen($value) > 4000) { |
330 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only' | 338 throw new Writer\Exception\InvalidArgumentException('invalid parameter: "summary" may only' |
331 . ' contain a maximum of 4000 characters'); | 339 . ' contain a maximum of 4000 characters'); |
332 } | 340 } |
333 $this->data['summary'] = $value; | 341 $this->data['summary'] = $value; |
342 return $this; | |
343 } | |
344 | |
345 /** | |
346 * Set podcast type | |
347 * | |
348 * @param string $type | |
349 * @return Feed | |
350 * @throws Writer\Exception\InvalidArgumentException | |
351 */ | |
352 public function setItunesType($type) | |
353 { | |
354 $validTypes = ['episodic', 'serial']; | |
355 if (! in_array($type, $validTypes, true)) { | |
356 throw new Writer\Exception\InvalidArgumentException(sprintf( | |
357 'invalid parameter: "type" MUST be one of [%s]; received %s', | |
358 implode(', ', $validTypes), | |
359 is_object($type) ? get_class($type) : var_export($type, true) | |
360 )); | |
361 } | |
362 $this->data['type'] = $type; | |
363 return $this; | |
364 } | |
365 | |
366 /** | |
367 * Set "completion" status (whether more episodes will be released) | |
368 * | |
369 * @param bool $status | |
370 * @return Feed | |
371 * @throws Writer\Exception\InvalidArgumentException | |
372 */ | |
373 public function setItunesComplete($status) | |
374 { | |
375 if (! is_bool($status)) { | |
376 throw new Writer\Exception\InvalidArgumentException(sprintf( | |
377 'invalid parameter: "complete" MUST be boolean; received %s', | |
378 is_object($status) ? get_class($status) : var_export($status, true) | |
379 )); | |
380 } | |
381 | |
382 if (! $status) { | |
383 return $this; | |
384 } | |
385 | |
386 $this->data['complete'] = 'Yes'; | |
334 return $this; | 387 return $this; |
335 } | 388 } |
336 | 389 |
337 /** | 390 /** |
338 * Overloading: proxy to internal setters | 391 * Overloading: proxy to internal setters |
343 * @throws Writer\Exception\BadMethodCallException | 396 * @throws Writer\Exception\BadMethodCallException |
344 */ | 397 */ |
345 public function __call($method, array $params) | 398 public function __call($method, array $params) |
346 { | 399 { |
347 $point = lcfirst(substr($method, 9)); | 400 $point = lcfirst(substr($method, 9)); |
348 if (!method_exists($this, 'setItunes' . ucfirst($point)) | 401 if (! method_exists($this, 'setItunes' . ucfirst($point)) |
349 && !method_exists($this, 'addItunes' . ucfirst($point)) | 402 && ! method_exists($this, 'addItunes' . ucfirst($point)) |
350 ) { | 403 ) { |
351 throw new Writer\Exception\BadMethodCallException( | 404 throw new Writer\Exception\BadMethodCallException( |
352 'invalid method: ' . $method | 405 'invalid method: ' . $method |
353 ); | 406 ); |
354 } | 407 } |
355 if (!array_key_exists($point, $this->data) || empty($this->data[$point])) { | 408 |
409 if (! array_key_exists($point, $this->data) || empty($this->data[$point])) { | |
356 return; | 410 return; |
357 } | 411 } |
358 return $this->data[$point]; | 412 return $this->data[$point]; |
359 } | 413 } |
360 } | 414 } |