comparison vendor/zendframework/zend-feed/src/Writer/Entry.php @ 12:7a779792577d

Update Drupal core to v8.4.5 (via Composer)
author Chris Cannam
date Fri, 23 Feb 2018 15:52:07 +0000
parents 4c8ae668cc8c
children c2387f117808
comparison
equal deleted inserted replaced
11:bfffd8d7479a 12:7a779792577d
62 * @return Entry 62 * @return Entry
63 */ 63 */
64 public function addAuthor(array $author) 64 public function addAuthor(array $author)
65 { 65 {
66 // Check array values 66 // Check array values
67 if (!array_key_exists('name', $author) 67 if (! array_key_exists('name', $author)
68 || empty($author['name']) 68 || empty($author['name'])
69 || !is_string($author['name']) 69 || ! is_string($author['name'])
70 ) { 70 ) {
71 throw new Exception\InvalidArgumentException( 71 throw new Exception\InvalidArgumentException(
72 'Invalid parameter: author array must include a "name" key with a non-empty string value'); 72 'Invalid parameter: author array must include a "name" key with a non-empty string value'
73 );
73 } 74 }
74 75
75 if (isset($author['email'])) { 76 if (isset($author['email'])) {
76 if (empty($author['email']) || !is_string($author['email'])) { 77 if (empty($author['email']) || ! is_string($author['email'])) {
77 throw new Exception\InvalidArgumentException( 78 throw new Exception\InvalidArgumentException(
78 'Invalid parameter: "email" array value must be a non-empty string'); 79 'Invalid parameter: "email" array value must be a non-empty string'
80 );
79 } 81 }
80 } 82 }
81 if (isset($author['uri'])) { 83 if (isset($author['uri'])) {
82 if (empty($author['uri']) || !is_string($author['uri']) || 84 if (empty($author['uri']) || ! is_string($author['uri']) ||
83 !Uri::factory($author['uri'])->isValid() 85 ! Uri::factory($author['uri'])->isValid()
84 ) { 86 ) {
85 throw new Exception\InvalidArgumentException( 87 throw new Exception\InvalidArgumentException(
86 'Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI'); 88 'Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI'
89 );
87 } 90 }
88 } 91 }
89 92
90 $this->data['authors'][] = $author; 93 $this->data['authors'][] = $author;
91 94
115 * @throws Exception\InvalidArgumentException 118 * @throws Exception\InvalidArgumentException
116 * @return Entry 119 * @return Entry
117 */ 120 */
118 public function setEncoding($encoding) 121 public function setEncoding($encoding)
119 { 122 {
120 if (empty($encoding) || !is_string($encoding)) { 123 if (empty($encoding) || ! is_string($encoding)) {
121 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string'); 124 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
122 } 125 }
123 $this->data['encoding'] = $encoding; 126 $this->data['encoding'] = $encoding;
124 127
125 return $this; 128 return $this;
130 * 133 *
131 * @return string|null 134 * @return string|null
132 */ 135 */
133 public function getEncoding() 136 public function getEncoding()
134 { 137 {
135 if (!array_key_exists('encoding', $this->data)) { 138 if (! array_key_exists('encoding', $this->data)) {
136 return 'UTF-8'; 139 return 'UTF-8';
137 } 140 }
138 return $this->data['encoding']; 141 return $this->data['encoding'];
139 } 142 }
140 143
145 * @throws Exception\InvalidArgumentException 148 * @throws Exception\InvalidArgumentException
146 * @return Entry 149 * @return Entry
147 */ 150 */
148 public function setCopyright($copyright) 151 public function setCopyright($copyright)
149 { 152 {
150 if (empty($copyright) || !is_string($copyright)) { 153 if (empty($copyright) || ! is_string($copyright)) {
151 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string'); 154 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
152 } 155 }
153 $this->data['copyright'] = $copyright; 156 $this->data['copyright'] = $copyright;
154 157
155 return $this; 158 return $this;
162 * @throws Exception\InvalidArgumentException 165 * @throws Exception\InvalidArgumentException
163 * @return Entry 166 * @return Entry
164 */ 167 */
165 public function setContent($content) 168 public function setContent($content)
166 { 169 {
167 if (empty($content) || !is_string($content)) { 170 if (empty($content) || ! is_string($content)) {
168 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string'); 171 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
169 } 172 }
170 $this->data['content'] = $content; 173 $this->data['content'] = $content;
171 174
172 return $this; 175 return $this;
183 { 186 {
184 if ($date === null) { 187 if ($date === null) {
185 $date = new DateTime(); 188 $date = new DateTime();
186 } elseif (is_int($date)) { 189 } elseif (is_int($date)) {
187 $date = new DateTime('@' . $date); 190 $date = new DateTime('@' . $date);
188 } elseif (!$date instanceof DateTime) { 191 } elseif (! $date instanceof DateTime) {
189 throw new Exception\InvalidArgumentException('Invalid DateTime object or UNIX Timestamp passed as parameter'); 192 throw new Exception\InvalidArgumentException(
193 'Invalid DateTime object or UNIX Timestamp passed as parameter'
194 );
190 } 195 }
191 $this->data['dateCreated'] = $date; 196 $this->data['dateCreated'] = $date;
192 197
193 return $this; 198 return $this;
194 } 199 }
204 { 209 {
205 if ($date === null) { 210 if ($date === null) {
206 $date = new DateTime(); 211 $date = new DateTime();
207 } elseif (is_int($date)) { 212 } elseif (is_int($date)) {
208 $date = new DateTime('@' . $date); 213 $date = new DateTime('@' . $date);
209 } elseif (!$date instanceof DateTime) { 214 } elseif (! $date instanceof DateTime) {
210 throw new Exception\InvalidArgumentException('Invalid DateTime object or UNIX Timestamp passed as parameter'); 215 throw new Exception\InvalidArgumentException(
216 'Invalid DateTime object or UNIX Timestamp passed as parameter'
217 );
211 } 218 }
212 $this->data['dateModified'] = $date; 219 $this->data['dateModified'] = $date;
213 220
214 return $this; 221 return $this;
215 } 222 }
221 * @throws Exception\InvalidArgumentException 228 * @throws Exception\InvalidArgumentException
222 * @return Entry 229 * @return Entry
223 */ 230 */
224 public function setDescription($description) 231 public function setDescription($description)
225 { 232 {
226 if (empty($description) || !is_string($description)) { 233 if (empty($description) || ! is_string($description)) {
227 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string'); 234 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
228 } 235 }
229 $this->data['description'] = $description; 236 $this->data['description'] = $description;
230 237
231 return $this; 238 return $this;
238 * @throws Exception\InvalidArgumentException 245 * @throws Exception\InvalidArgumentException
239 * @return Entry 246 * @return Entry
240 */ 247 */
241 public function setId($id) 248 public function setId($id)
242 { 249 {
243 if (empty($id) || !is_string($id)) { 250 if (empty($id) || ! is_string($id)) {
244 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string'); 251 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
245 } 252 }
246 $this->data['id'] = $id; 253 $this->data['id'] = $id;
247 254
248 return $this; 255 return $this;
255 * @throws Exception\InvalidArgumentException 262 * @throws Exception\InvalidArgumentException
256 * @return Entry 263 * @return Entry
257 */ 264 */
258 public function setLink($link) 265 public function setLink($link)
259 { 266 {
260 if (empty($link) || !is_string($link) || !Uri::factory($link)->isValid()) { 267 if (empty($link) || ! is_string($link) || ! Uri::factory($link)->isValid()) {
261 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string and valid URI/IRI'); 268 throw new Exception\InvalidArgumentException(
269 'Invalid parameter: parameter must be a non-empty string and valid URI/IRI'
270 );
262 } 271 }
263 $this->data['link'] = $link; 272 $this->data['link'] = $link;
264 273
265 return $this; 274 return $this;
266 } 275 }
272 * @throws Exception\InvalidArgumentException 281 * @throws Exception\InvalidArgumentException
273 * @return Entry 282 * @return Entry
274 */ 283 */
275 public function setCommentCount($count) 284 public function setCommentCount($count)
276 { 285 {
277 if (!is_numeric($count) || (int) $count != $count || (int) $count < 0) { 286 if (! is_numeric($count) || (int) $count != $count || (int) $count < 0) {
278 throw new Exception\InvalidArgumentException('Invalid parameter: "count" must be a positive integer number or zero'); 287 throw new Exception\InvalidArgumentException(
288 'Invalid parameter: "count" must be a positive integer number or zero'
289 );
279 } 290 }
280 $this->data['commentCount'] = (int) $count; 291 $this->data['commentCount'] = (int) $count;
281 292
282 return $this; 293 return $this;
283 } 294 }
289 * @throws Exception\InvalidArgumentException 300 * @throws Exception\InvalidArgumentException
290 * @return Entry 301 * @return Entry
291 */ 302 */
292 public function setCommentLink($link) 303 public function setCommentLink($link)
293 { 304 {
294 if (empty($link) || !is_string($link) || !Uri::factory($link)->isValid()) { 305 if (empty($link) || ! is_string($link) || ! Uri::factory($link)->isValid()) {
295 throw new Exception\InvalidArgumentException('Invalid parameter: "link" must be a non-empty string and valid URI/IRI'); 306 throw new Exception\InvalidArgumentException(
307 'Invalid parameter: "link" must be a non-empty string and valid URI/IRI'
308 );
296 } 309 }
297 $this->data['commentLink'] = $link; 310 $this->data['commentLink'] = $link;
298 311
299 return $this; 312 return $this;
300 } 313 }
306 * @throws Exception\InvalidArgumentException 319 * @throws Exception\InvalidArgumentException
307 * @return Entry 320 * @return Entry
308 */ 321 */
309 public function setCommentFeedLink(array $link) 322 public function setCommentFeedLink(array $link)
310 { 323 {
311 if (!isset($link['uri']) || !is_string($link['uri']) || !Uri::factory($link['uri'])->isValid()) { 324 if (! isset($link['uri']) || ! is_string($link['uri']) || ! Uri::factory($link['uri'])->isValid()) {
312 throw new Exception\InvalidArgumentException('Invalid parameter: "link" must be a non-empty string and valid URI/IRI'); 325 throw new Exception\InvalidArgumentException(
313 } 326 'Invalid parameter: "link" must be a non-empty string and valid URI/IRI'
314 if (!isset($link['type']) || !in_array($link['type'], ['atom', 'rss', 'rdf'])) { 327 );
328 }
329 if (! isset($link['type']) || ! in_array($link['type'], ['atom', 'rss', 'rdf'])) {
315 throw new Exception\InvalidArgumentException('Invalid parameter: "type" must be one' 330 throw new Exception\InvalidArgumentException('Invalid parameter: "type" must be one'
316 . ' of "atom", "rss" or "rdf"'); 331 . ' of "atom", "rss" or "rdf"');
317 } 332 }
318 if (!isset($this->data['commentFeedLinks'])) { 333 if (! isset($this->data['commentFeedLinks'])) {
319 $this->data['commentFeedLinks'] = []; 334 $this->data['commentFeedLinks'] = [];
320 } 335 }
321 $this->data['commentFeedLinks'][] = $link; 336 $this->data['commentFeedLinks'][] = $link;
322 337
323 return $this; 338 return $this;
347 * @throws Exception\InvalidArgumentException 362 * @throws Exception\InvalidArgumentException
348 * @return Entry 363 * @return Entry
349 */ 364 */
350 public function setTitle($title) 365 public function setTitle($title)
351 { 366 {
352 if (empty($title) || !is_string($title)) { 367 if (empty($title) || ! is_string($title)) {
353 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string'); 368 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
354 } 369 }
355 $this->data['title'] = $title; 370 $this->data['title'] = $title;
356 371
357 return $this; 372 return $this;
362 * 377 *
363 * @return array 378 * @return array
364 */ 379 */
365 public function getAuthors() 380 public function getAuthors()
366 { 381 {
367 if (!array_key_exists('authors', $this->data)) { 382 if (! array_key_exists('authors', $this->data)) {
368 return; 383 return;
369 } 384 }
370 return $this->data['authors']; 385 return $this->data['authors'];
371 } 386 }
372 387
375 * 390 *
376 * @return string 391 * @return string
377 */ 392 */
378 public function getContent() 393 public function getContent()
379 { 394 {
380 if (!array_key_exists('content', $this->data)) { 395 if (! array_key_exists('content', $this->data)) {
381 return; 396 return;
382 } 397 }
383 return $this->data['content']; 398 return $this->data['content'];
384 } 399 }
385 400
388 * 403 *
389 * @return string 404 * @return string
390 */ 405 */
391 public function getCopyright() 406 public function getCopyright()
392 { 407 {
393 if (!array_key_exists('copyright', $this->data)) { 408 if (! array_key_exists('copyright', $this->data)) {
394 return; 409 return;
395 } 410 }
396 return $this->data['copyright']; 411 return $this->data['copyright'];
397 } 412 }
398 413
401 * 416 *
402 * @return string 417 * @return string
403 */ 418 */
404 public function getDateCreated() 419 public function getDateCreated()
405 { 420 {
406 if (!array_key_exists('dateCreated', $this->data)) { 421 if (! array_key_exists('dateCreated', $this->data)) {
407 return; 422 return;
408 } 423 }
409 return $this->data['dateCreated']; 424 return $this->data['dateCreated'];
410 } 425 }
411 426
414 * 429 *
415 * @return string 430 * @return string
416 */ 431 */
417 public function getDateModified() 432 public function getDateModified()
418 { 433 {
419 if (!array_key_exists('dateModified', $this->data)) { 434 if (! array_key_exists('dateModified', $this->data)) {
420 return; 435 return;
421 } 436 }
422 return $this->data['dateModified']; 437 return $this->data['dateModified'];
423 } 438 }
424 439
427 * 442 *
428 * @return string 443 * @return string
429 */ 444 */
430 public function getDescription() 445 public function getDescription()
431 { 446 {
432 if (!array_key_exists('description', $this->data)) { 447 if (! array_key_exists('description', $this->data)) {
433 return; 448 return;
434 } 449 }
435 return $this->data['description']; 450 return $this->data['description'];
436 } 451 }
437 452
440 * 455 *
441 * @return string 456 * @return string
442 */ 457 */
443 public function getId() 458 public function getId()
444 { 459 {
445 if (!array_key_exists('id', $this->data)) { 460 if (! array_key_exists('id', $this->data)) {
446 return; 461 return;
447 } 462 }
448 return $this->data['id']; 463 return $this->data['id'];
449 } 464 }
450 465
453 * 468 *
454 * @return string|null 469 * @return string|null
455 */ 470 */
456 public function getLink() 471 public function getLink()
457 { 472 {
458 if (!array_key_exists('link', $this->data)) { 473 if (! array_key_exists('link', $this->data)) {
459 return; 474 return;
460 } 475 }
461 return $this->data['link']; 476 return $this->data['link'];
462 } 477 }
463 478
467 * 482 *
468 * @return array 483 * @return array
469 */ 484 */
470 public function getLinks() 485 public function getLinks()
471 { 486 {
472 if (!array_key_exists('links', $this->data)) { 487 if (! array_key_exists('links', $this->data)) {
473 return; 488 return;
474 } 489 }
475 return $this->data['links']; 490 return $this->data['links'];
476 } 491 }
477 492
480 * 495 *
481 * @return string 496 * @return string
482 */ 497 */
483 public function getTitle() 498 public function getTitle()
484 { 499 {
485 if (!array_key_exists('title', $this->data)) { 500 if (! array_key_exists('title', $this->data)) {
486 return; 501 return;
487 } 502 }
488 return $this->data['title']; 503 return $this->data['title'];
489 } 504 }
490 505
493 * 508 *
494 * @return int 509 * @return int
495 */ 510 */
496 public function getCommentCount() 511 public function getCommentCount()
497 { 512 {
498 if (!array_key_exists('commentCount', $this->data)) { 513 if (! array_key_exists('commentCount', $this->data)) {
499 return; 514 return;
500 } 515 }
501 return $this->data['commentCount']; 516 return $this->data['commentCount'];
502 } 517 }
503 518
506 * 521 *
507 * @return string 522 * @return string
508 */ 523 */
509 public function getCommentLink() 524 public function getCommentLink()
510 { 525 {
511 if (!array_key_exists('commentLink', $this->data)) { 526 if (! array_key_exists('commentLink', $this->data)) {
512 return; 527 return;
513 } 528 }
514 return $this->data['commentLink']; 529 return $this->data['commentLink'];
515 } 530 }
516 531
520 * 535 *
521 * @return string 536 * @return string
522 */ 537 */
523 public function getCommentFeedLinks() 538 public function getCommentFeedLinks()
524 { 539 {
525 if (!array_key_exists('commentFeedLinks', $this->data)) { 540 if (! array_key_exists('commentFeedLinks', $this->data)) {
526 return; 541 return;
527 } 542 }
528 return $this->data['commentFeedLinks']; 543 return $this->data['commentFeedLinks'];
529 } 544 }
530 545
535 * @throws Exception\InvalidArgumentException 550 * @throws Exception\InvalidArgumentException
536 * @return Entry 551 * @return Entry
537 */ 552 */
538 public function addCategory(array $category) 553 public function addCategory(array $category)
539 { 554 {
540 if (!isset($category['term'])) { 555 if (! isset($category['term'])) {
541 throw new Exception\InvalidArgumentException('Each category must be an array and ' 556 throw new Exception\InvalidArgumentException('Each category must be an array and '
542 . 'contain at least a "term" element containing the machine ' 557 . 'contain at least a "term" element containing the machine '
543 . ' readable category name'); 558 . ' readable category name');
544 } 559 }
545 if (isset($category['scheme'])) { 560 if (isset($category['scheme'])) {
546 if (empty($category['scheme']) 561 if (empty($category['scheme'])
547 || !is_string($category['scheme']) 562 || ! is_string($category['scheme'])
548 || !Uri::factory($category['scheme'])->isValid() 563 || ! Uri::factory($category['scheme'])->isValid()
549 ) { 564 ) {
550 throw new Exception\InvalidArgumentException('The Atom scheme or RSS domain of' 565 throw new Exception\InvalidArgumentException('The Atom scheme or RSS domain of'
551 . ' a category must be a valid URI'); 566 . ' a category must be a valid URI');
552 } 567 }
553 } 568 }
554 if (!isset($this->data['categories'])) { 569 if (! isset($this->data['categories'])) {
555 $this->data['categories'] = []; 570 $this->data['categories'] = [];
556 } 571 }
557 $this->data['categories'][] = $category; 572 $this->data['categories'][] = $category;
558 573
559 return $this; 574 return $this;
579 * 594 *
580 * @return string|null 595 * @return string|null
581 */ 596 */
582 public function getCategories() 597 public function getCategories()
583 { 598 {
584 if (!array_key_exists('categories', $this->data)) { 599 if (! array_key_exists('categories', $this->data)) {
585 return; 600 return;
586 } 601 }
587 return $this->data['categories']; 602 return $this->data['categories'];
588 } 603 }
589 604
597 * @throws Exception\InvalidArgumentException 612 * @throws Exception\InvalidArgumentException
598 * @return Entry 613 * @return Entry
599 */ 614 */
600 public function setEnclosure(array $enclosure) 615 public function setEnclosure(array $enclosure)
601 { 616 {
602 if (!isset($enclosure['uri'])) { 617 if (! isset($enclosure['uri'])) {
603 throw new Exception\InvalidArgumentException('Enclosure "uri" is not set'); 618 throw new Exception\InvalidArgumentException('Enclosure "uri" is not set');
604 } 619 }
605 if (!Uri::factory($enclosure['uri'])->isValid()) { 620 if (! Uri::factory($enclosure['uri'])->isValid()) {
606 throw new Exception\InvalidArgumentException('Enclosure "uri" is not a valid URI/IRI'); 621 throw new Exception\InvalidArgumentException('Enclosure "uri" is not a valid URI/IRI');
607 } 622 }
608 $this->data['enclosure'] = $enclosure; 623 $this->data['enclosure'] = $enclosure;
609 624
610 return $this; 625 return $this;
615 * 630 *
616 * @return array 631 * @return array
617 */ 632 */
618 public function getEnclosure() 633 public function getEnclosure()
619 { 634 {
620 if (!array_key_exists('enclosure', $this->data)) { 635 if (! array_key_exists('enclosure', $this->data)) {
621 return; 636 return;
622 } 637 }
623 return $this->data['enclosure']; 638 return $this->data['enclosure'];
624 } 639 }
625 640
750 /** 765 /**
751 * Load extensions from Zend\Feed\Writer\Writer 766 * Load extensions from Zend\Feed\Writer\Writer
752 * 767 *
753 * @return void 768 * @return void
754 */ 769 */
770 // @codingStandardsIgnoreStart
755 protected function _loadExtensions() 771 protected function _loadExtensions()
756 { 772 {
773 // @codingStandardsIgnoreEnd
757 $all = Writer::getExtensions(); 774 $all = Writer::getExtensions();
758 $manager = Writer::getExtensionManager(); 775 $manager = Writer::getExtensionManager();
759 $exts = $all['entry']; 776 $exts = $all['entry'];
760 foreach ($exts as $ext) { 777 foreach ($exts as $ext) {
761 $this->extensions[$ext] = $manager->get($ext); 778 $this->extensions[$ext] = $manager->get($ext);