annotate vendor/zendframework/zend-feed/src/Writer/Entry.php @ 2:5311817fb629

Theme updates
author Chris Cannam
date Tue, 10 Jul 2018 13:19:18 +0000
parents c75dbcec494b
children a9cd425dd02b
rev   line source
Chris@0 1 <?php
Chris@0 2 /**
Chris@0 3 * Zend Framework (http://framework.zend.com/)
Chris@0 4 *
Chris@0 5 * @link http://github.com/zendframework/zf2 for the canonical source repository
Chris@0 6 * @copyright Copyright (c) 2005-2015 Zend Technologies USA Inc. (http://www.zend.com)
Chris@0 7 * @license http://framework.zend.com/license/new-bsd New BSD License
Chris@0 8 */
Chris@0 9
Chris@0 10 namespace Zend\Feed\Writer;
Chris@0 11
Chris@0 12 use DateTime;
Chris@0 13 use Zend\Feed\Uri;
Chris@0 14
Chris@0 15 /**
Chris@0 16 */
Chris@0 17 class Entry
Chris@0 18 {
Chris@0 19 /**
Chris@0 20 * Internal array containing all data associated with this entry or item.
Chris@0 21 *
Chris@0 22 * @var array
Chris@0 23 */
Chris@0 24 protected $data = [];
Chris@0 25
Chris@0 26 /**
Chris@0 27 * Registered extensions
Chris@0 28 *
Chris@0 29 * @var array
Chris@0 30 */
Chris@0 31 protected $extensions = [];
Chris@0 32
Chris@0 33 /**
Chris@0 34 * Holds the value "atom" or "rss" depending on the feed type set when
Chris@0 35 * when last exported.
Chris@0 36 *
Chris@0 37 * @var string
Chris@0 38 */
Chris@0 39 protected $type = null;
Chris@0 40
Chris@0 41 /**
Chris@0 42 * Constructor: Primarily triggers the registration of core extensions and
Chris@0 43 * loads those appropriate to this data container.
Chris@0 44 *
Chris@0 45 */
Chris@0 46 public function __construct()
Chris@0 47 {
Chris@0 48 Writer::registerCoreExtensions();
Chris@0 49 $this->_loadExtensions();
Chris@0 50 }
Chris@0 51
Chris@0 52 /**
Chris@0 53 * Set a single author
Chris@0 54 *
Chris@0 55 * The following option keys are supported:
Chris@0 56 * 'name' => (string) The name
Chris@0 57 * 'email' => (string) An optional email
Chris@0 58 * 'uri' => (string) An optional and valid URI
Chris@0 59 *
Chris@0 60 * @param array $author
Chris@0 61 * @throws Exception\InvalidArgumentException If any value of $author not follow the format.
Chris@0 62 * @return Entry
Chris@0 63 */
Chris@0 64 public function addAuthor(array $author)
Chris@0 65 {
Chris@0 66 // Check array values
Chris@2 67 if (! array_key_exists('name', $author)
Chris@0 68 || empty($author['name'])
Chris@2 69 || ! is_string($author['name'])
Chris@0 70 ) {
Chris@0 71 throw new Exception\InvalidArgumentException(
Chris@2 72 'Invalid parameter: author array must include a "name" key with a non-empty string value'
Chris@2 73 );
Chris@0 74 }
Chris@0 75
Chris@0 76 if (isset($author['email'])) {
Chris@2 77 if (empty($author['email']) || ! is_string($author['email'])) {
Chris@0 78 throw new Exception\InvalidArgumentException(
Chris@2 79 'Invalid parameter: "email" array value must be a non-empty string'
Chris@2 80 );
Chris@0 81 }
Chris@0 82 }
Chris@0 83 if (isset($author['uri'])) {
Chris@2 84 if (empty($author['uri']) || ! is_string($author['uri']) ||
Chris@2 85 ! Uri::factory($author['uri'])->isValid()
Chris@0 86 ) {
Chris@0 87 throw new Exception\InvalidArgumentException(
Chris@2 88 'Invalid parameter: "uri" array value must be a non-empty string and valid URI/IRI'
Chris@2 89 );
Chris@0 90 }
Chris@0 91 }
Chris@0 92
Chris@0 93 $this->data['authors'][] = $author;
Chris@0 94
Chris@0 95 return $this;
Chris@0 96 }
Chris@0 97
Chris@0 98 /**
Chris@0 99 * Set an array with feed authors
Chris@0 100 *
Chris@0 101 * @see addAuthor
Chris@0 102 * @param array $authors
Chris@0 103 * @return Entry
Chris@0 104 */
Chris@0 105 public function addAuthors(array $authors)
Chris@0 106 {
Chris@0 107 foreach ($authors as $author) {
Chris@0 108 $this->addAuthor($author);
Chris@0 109 }
Chris@0 110
Chris@0 111 return $this;
Chris@0 112 }
Chris@0 113
Chris@0 114 /**
Chris@0 115 * Set the feed character encoding
Chris@0 116 *
Chris@0 117 * @param string $encoding
Chris@0 118 * @throws Exception\InvalidArgumentException
Chris@0 119 * @return Entry
Chris@0 120 */
Chris@0 121 public function setEncoding($encoding)
Chris@0 122 {
Chris@2 123 if (empty($encoding) || ! is_string($encoding)) {
Chris@0 124 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
Chris@0 125 }
Chris@0 126 $this->data['encoding'] = $encoding;
Chris@0 127
Chris@0 128 return $this;
Chris@0 129 }
Chris@0 130
Chris@0 131 /**
Chris@0 132 * Get the feed character encoding
Chris@0 133 *
Chris@0 134 * @return string|null
Chris@0 135 */
Chris@0 136 public function getEncoding()
Chris@0 137 {
Chris@2 138 if (! array_key_exists('encoding', $this->data)) {
Chris@0 139 return 'UTF-8';
Chris@0 140 }
Chris@0 141 return $this->data['encoding'];
Chris@0 142 }
Chris@0 143
Chris@0 144 /**
Chris@0 145 * Set the copyright entry
Chris@0 146 *
Chris@0 147 * @param string $copyright
Chris@0 148 * @throws Exception\InvalidArgumentException
Chris@0 149 * @return Entry
Chris@0 150 */
Chris@0 151 public function setCopyright($copyright)
Chris@0 152 {
Chris@2 153 if (empty($copyright) || ! is_string($copyright)) {
Chris@0 154 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
Chris@0 155 }
Chris@0 156 $this->data['copyright'] = $copyright;
Chris@0 157
Chris@0 158 return $this;
Chris@0 159 }
Chris@0 160
Chris@0 161 /**
Chris@0 162 * Set the entry's content
Chris@0 163 *
Chris@0 164 * @param string $content
Chris@0 165 * @throws Exception\InvalidArgumentException
Chris@0 166 * @return Entry
Chris@0 167 */
Chris@0 168 public function setContent($content)
Chris@0 169 {
Chris@2 170 if (empty($content) || ! is_string($content)) {
Chris@0 171 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
Chris@0 172 }
Chris@0 173 $this->data['content'] = $content;
Chris@0 174
Chris@0 175 return $this;
Chris@0 176 }
Chris@0 177
Chris@0 178 /**
Chris@0 179 * Set the feed creation date
Chris@0 180 *
Chris@0 181 * @param null|int|DateTime $date
Chris@0 182 * @throws Exception\InvalidArgumentException
Chris@0 183 * @return Entry
Chris@0 184 */
Chris@0 185 public function setDateCreated($date = null)
Chris@0 186 {
Chris@0 187 if ($date === null) {
Chris@0 188 $date = new DateTime();
Chris@0 189 } elseif (is_int($date)) {
Chris@0 190 $date = new DateTime('@' . $date);
Chris@2 191 } elseif (! $date instanceof DateTime) {
Chris@2 192 throw new Exception\InvalidArgumentException(
Chris@2 193 'Invalid DateTime object or UNIX Timestamp passed as parameter'
Chris@2 194 );
Chris@0 195 }
Chris@0 196 $this->data['dateCreated'] = $date;
Chris@0 197
Chris@0 198 return $this;
Chris@0 199 }
Chris@0 200
Chris@0 201 /**
Chris@0 202 * Set the feed modification date
Chris@0 203 *
Chris@0 204 * @param null|int|DateTime $date
Chris@0 205 * @throws Exception\InvalidArgumentException
Chris@0 206 * @return Entry
Chris@0 207 */
Chris@0 208 public function setDateModified($date = null)
Chris@0 209 {
Chris@0 210 if ($date === null) {
Chris@0 211 $date = new DateTime();
Chris@0 212 } elseif (is_int($date)) {
Chris@0 213 $date = new DateTime('@' . $date);
Chris@2 214 } elseif (! $date instanceof DateTime) {
Chris@2 215 throw new Exception\InvalidArgumentException(
Chris@2 216 'Invalid DateTime object or UNIX Timestamp passed as parameter'
Chris@2 217 );
Chris@0 218 }
Chris@0 219 $this->data['dateModified'] = $date;
Chris@0 220
Chris@0 221 return $this;
Chris@0 222 }
Chris@0 223
Chris@0 224 /**
Chris@0 225 * Set the feed description
Chris@0 226 *
Chris@0 227 * @param string $description
Chris@0 228 * @throws Exception\InvalidArgumentException
Chris@0 229 * @return Entry
Chris@0 230 */
Chris@0 231 public function setDescription($description)
Chris@0 232 {
Chris@2 233 if (empty($description) || ! is_string($description)) {
Chris@0 234 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
Chris@0 235 }
Chris@0 236 $this->data['description'] = $description;
Chris@0 237
Chris@0 238 return $this;
Chris@0 239 }
Chris@0 240
Chris@0 241 /**
Chris@0 242 * Set the feed ID
Chris@0 243 *
Chris@0 244 * @param string $id
Chris@0 245 * @throws Exception\InvalidArgumentException
Chris@0 246 * @return Entry
Chris@0 247 */
Chris@0 248 public function setId($id)
Chris@0 249 {
Chris@2 250 if (empty($id) || ! is_string($id)) {
Chris@0 251 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
Chris@0 252 }
Chris@0 253 $this->data['id'] = $id;
Chris@0 254
Chris@0 255 return $this;
Chris@0 256 }
Chris@0 257
Chris@0 258 /**
Chris@0 259 * Set a link to the HTML source of this entry
Chris@0 260 *
Chris@0 261 * @param string $link
Chris@0 262 * @throws Exception\InvalidArgumentException
Chris@0 263 * @return Entry
Chris@0 264 */
Chris@0 265 public function setLink($link)
Chris@0 266 {
Chris@2 267 if (empty($link) || ! is_string($link) || ! Uri::factory($link)->isValid()) {
Chris@2 268 throw new Exception\InvalidArgumentException(
Chris@2 269 'Invalid parameter: parameter must be a non-empty string and valid URI/IRI'
Chris@2 270 );
Chris@0 271 }
Chris@0 272 $this->data['link'] = $link;
Chris@0 273
Chris@0 274 return $this;
Chris@0 275 }
Chris@0 276
Chris@0 277 /**
Chris@0 278 * Set the number of comments associated with this entry
Chris@0 279 *
Chris@0 280 * @param int $count
Chris@0 281 * @throws Exception\InvalidArgumentException
Chris@0 282 * @return Entry
Chris@0 283 */
Chris@0 284 public function setCommentCount($count)
Chris@0 285 {
Chris@2 286 if (! is_numeric($count) || (int) $count != $count || (int) $count < 0) {
Chris@2 287 throw new Exception\InvalidArgumentException(
Chris@2 288 'Invalid parameter: "count" must be a positive integer number or zero'
Chris@2 289 );
Chris@0 290 }
Chris@0 291 $this->data['commentCount'] = (int) $count;
Chris@0 292
Chris@0 293 return $this;
Chris@0 294 }
Chris@0 295
Chris@0 296 /**
Chris@0 297 * Set a link to a HTML page containing comments associated with this entry
Chris@0 298 *
Chris@0 299 * @param string $link
Chris@0 300 * @throws Exception\InvalidArgumentException
Chris@0 301 * @return Entry
Chris@0 302 */
Chris@0 303 public function setCommentLink($link)
Chris@0 304 {
Chris@2 305 if (empty($link) || ! is_string($link) || ! Uri::factory($link)->isValid()) {
Chris@2 306 throw new Exception\InvalidArgumentException(
Chris@2 307 'Invalid parameter: "link" must be a non-empty string and valid URI/IRI'
Chris@2 308 );
Chris@0 309 }
Chris@0 310 $this->data['commentLink'] = $link;
Chris@0 311
Chris@0 312 return $this;
Chris@0 313 }
Chris@0 314
Chris@0 315 /**
Chris@0 316 * Set a link to an XML feed for any comments associated with this entry
Chris@0 317 *
Chris@0 318 * @param array $link
Chris@0 319 * @throws Exception\InvalidArgumentException
Chris@0 320 * @return Entry
Chris@0 321 */
Chris@0 322 public function setCommentFeedLink(array $link)
Chris@0 323 {
Chris@2 324 if (! isset($link['uri']) || ! is_string($link['uri']) || ! Uri::factory($link['uri'])->isValid()) {
Chris@2 325 throw new Exception\InvalidArgumentException(
Chris@2 326 'Invalid parameter: "link" must be a non-empty string and valid URI/IRI'
Chris@2 327 );
Chris@0 328 }
Chris@2 329 if (! isset($link['type']) || ! in_array($link['type'], ['atom', 'rss', 'rdf'])) {
Chris@0 330 throw new Exception\InvalidArgumentException('Invalid parameter: "type" must be one'
Chris@0 331 . ' of "atom", "rss" or "rdf"');
Chris@0 332 }
Chris@2 333 if (! isset($this->data['commentFeedLinks'])) {
Chris@0 334 $this->data['commentFeedLinks'] = [];
Chris@0 335 }
Chris@0 336 $this->data['commentFeedLinks'][] = $link;
Chris@0 337
Chris@0 338 return $this;
Chris@0 339 }
Chris@0 340
Chris@0 341 /**
Chris@0 342 * Set a links to an XML feed for any comments associated with this entry.
Chris@0 343 * Each link is an array with keys "uri" and "type", where type is one of:
Chris@0 344 * "atom", "rss" or "rdf".
Chris@0 345 *
Chris@0 346 * @param array $links
Chris@0 347 * @return Entry
Chris@0 348 */
Chris@0 349 public function setCommentFeedLinks(array $links)
Chris@0 350 {
Chris@0 351 foreach ($links as $link) {
Chris@0 352 $this->setCommentFeedLink($link);
Chris@0 353 }
Chris@0 354
Chris@0 355 return $this;
Chris@0 356 }
Chris@0 357
Chris@0 358 /**
Chris@0 359 * Set the feed title
Chris@0 360 *
Chris@0 361 * @param string $title
Chris@0 362 * @throws Exception\InvalidArgumentException
Chris@0 363 * @return Entry
Chris@0 364 */
Chris@0 365 public function setTitle($title)
Chris@0 366 {
Chris@2 367 if ((empty($title) && ! is_numeric($title)) || ! is_string($title)) {
Chris@0 368 throw new Exception\InvalidArgumentException('Invalid parameter: parameter must be a non-empty string');
Chris@0 369 }
Chris@0 370 $this->data['title'] = $title;
Chris@0 371
Chris@0 372 return $this;
Chris@0 373 }
Chris@0 374
Chris@0 375 /**
Chris@0 376 * Get an array with feed authors
Chris@0 377 *
Chris@0 378 * @return array
Chris@0 379 */
Chris@0 380 public function getAuthors()
Chris@0 381 {
Chris@2 382 if (! array_key_exists('authors', $this->data)) {
Chris@0 383 return;
Chris@0 384 }
Chris@0 385 return $this->data['authors'];
Chris@0 386 }
Chris@0 387
Chris@0 388 /**
Chris@0 389 * Get the entry content
Chris@0 390 *
Chris@0 391 * @return string
Chris@0 392 */
Chris@0 393 public function getContent()
Chris@0 394 {
Chris@2 395 if (! array_key_exists('content', $this->data)) {
Chris@0 396 return;
Chris@0 397 }
Chris@0 398 return $this->data['content'];
Chris@0 399 }
Chris@0 400
Chris@0 401 /**
Chris@0 402 * Get the entry copyright information
Chris@0 403 *
Chris@0 404 * @return string
Chris@0 405 */
Chris@0 406 public function getCopyright()
Chris@0 407 {
Chris@2 408 if (! array_key_exists('copyright', $this->data)) {
Chris@0 409 return;
Chris@0 410 }
Chris@0 411 return $this->data['copyright'];
Chris@0 412 }
Chris@0 413
Chris@0 414 /**
Chris@0 415 * Get the entry creation date
Chris@0 416 *
Chris@0 417 * @return string
Chris@0 418 */
Chris@0 419 public function getDateCreated()
Chris@0 420 {
Chris@2 421 if (! array_key_exists('dateCreated', $this->data)) {
Chris@0 422 return;
Chris@0 423 }
Chris@0 424 return $this->data['dateCreated'];
Chris@0 425 }
Chris@0 426
Chris@0 427 /**
Chris@0 428 * Get the entry modification date
Chris@0 429 *
Chris@0 430 * @return string
Chris@0 431 */
Chris@0 432 public function getDateModified()
Chris@0 433 {
Chris@2 434 if (! array_key_exists('dateModified', $this->data)) {
Chris@0 435 return;
Chris@0 436 }
Chris@0 437 return $this->data['dateModified'];
Chris@0 438 }
Chris@0 439
Chris@0 440 /**
Chris@0 441 * Get the entry description
Chris@0 442 *
Chris@0 443 * @return string
Chris@0 444 */
Chris@0 445 public function getDescription()
Chris@0 446 {
Chris@2 447 if (! array_key_exists('description', $this->data)) {
Chris@0 448 return;
Chris@0 449 }
Chris@0 450 return $this->data['description'];
Chris@0 451 }
Chris@0 452
Chris@0 453 /**
Chris@0 454 * Get the entry ID
Chris@0 455 *
Chris@0 456 * @return string
Chris@0 457 */
Chris@0 458 public function getId()
Chris@0 459 {
Chris@2 460 if (! array_key_exists('id', $this->data)) {
Chris@0 461 return;
Chris@0 462 }
Chris@0 463 return $this->data['id'];
Chris@0 464 }
Chris@0 465
Chris@0 466 /**
Chris@0 467 * Get a link to the HTML source
Chris@0 468 *
Chris@0 469 * @return string|null
Chris@0 470 */
Chris@0 471 public function getLink()
Chris@0 472 {
Chris@2 473 if (! array_key_exists('link', $this->data)) {
Chris@0 474 return;
Chris@0 475 }
Chris@0 476 return $this->data['link'];
Chris@0 477 }
Chris@0 478
Chris@0 479
Chris@0 480 /**
Chris@0 481 * Get all links
Chris@0 482 *
Chris@0 483 * @return array
Chris@0 484 */
Chris@0 485 public function getLinks()
Chris@0 486 {
Chris@2 487 if (! array_key_exists('links', $this->data)) {
Chris@0 488 return;
Chris@0 489 }
Chris@0 490 return $this->data['links'];
Chris@0 491 }
Chris@0 492
Chris@0 493 /**
Chris@0 494 * Get the entry title
Chris@0 495 *
Chris@0 496 * @return string
Chris@0 497 */
Chris@0 498 public function getTitle()
Chris@0 499 {
Chris@2 500 if (! array_key_exists('title', $this->data)) {
Chris@0 501 return;
Chris@0 502 }
Chris@0 503 return $this->data['title'];
Chris@0 504 }
Chris@0 505
Chris@0 506 /**
Chris@0 507 * Get the number of comments/replies for current entry
Chris@0 508 *
Chris@0 509 * @return int
Chris@0 510 */
Chris@0 511 public function getCommentCount()
Chris@0 512 {
Chris@2 513 if (! array_key_exists('commentCount', $this->data)) {
Chris@0 514 return;
Chris@0 515 }
Chris@0 516 return $this->data['commentCount'];
Chris@0 517 }
Chris@0 518
Chris@0 519 /**
Chris@0 520 * Returns a URI pointing to the HTML page where comments can be made on this entry
Chris@0 521 *
Chris@0 522 * @return string
Chris@0 523 */
Chris@0 524 public function getCommentLink()
Chris@0 525 {
Chris@2 526 if (! array_key_exists('commentLink', $this->data)) {
Chris@0 527 return;
Chris@0 528 }
Chris@0 529 return $this->data['commentLink'];
Chris@0 530 }
Chris@0 531
Chris@0 532 /**
Chris@0 533 * Returns an array of URIs pointing to a feed of all comments for this entry
Chris@0 534 * where the array keys indicate the feed type (atom, rss or rdf).
Chris@0 535 *
Chris@0 536 * @return string
Chris@0 537 */
Chris@0 538 public function getCommentFeedLinks()
Chris@0 539 {
Chris@2 540 if (! array_key_exists('commentFeedLinks', $this->data)) {
Chris@0 541 return;
Chris@0 542 }
Chris@0 543 return $this->data['commentFeedLinks'];
Chris@0 544 }
Chris@0 545
Chris@0 546 /**
Chris@0 547 * Add an entry category
Chris@0 548 *
Chris@0 549 * @param array $category
Chris@0 550 * @throws Exception\InvalidArgumentException
Chris@0 551 * @return Entry
Chris@0 552 */
Chris@0 553 public function addCategory(array $category)
Chris@0 554 {
Chris@2 555 if (! isset($category['term'])) {
Chris@0 556 throw new Exception\InvalidArgumentException('Each category must be an array and '
Chris@0 557 . 'contain at least a "term" element containing the machine '
Chris@0 558 . ' readable category name');
Chris@0 559 }
Chris@0 560 if (isset($category['scheme'])) {
Chris@0 561 if (empty($category['scheme'])
Chris@2 562 || ! is_string($category['scheme'])
Chris@2 563 || ! Uri::factory($category['scheme'])->isValid()
Chris@0 564 ) {
Chris@0 565 throw new Exception\InvalidArgumentException('The Atom scheme or RSS domain of'
Chris@0 566 . ' a category must be a valid URI');
Chris@0 567 }
Chris@0 568 }
Chris@2 569 if (! isset($this->data['categories'])) {
Chris@0 570 $this->data['categories'] = [];
Chris@0 571 }
Chris@0 572 $this->data['categories'][] = $category;
Chris@0 573
Chris@0 574 return $this;
Chris@0 575 }
Chris@0 576
Chris@0 577 /**
Chris@0 578 * Set an array of entry categories
Chris@0 579 *
Chris@0 580 * @param array $categories
Chris@0 581 * @return Entry
Chris@0 582 */
Chris@0 583 public function addCategories(array $categories)
Chris@0 584 {
Chris@0 585 foreach ($categories as $category) {
Chris@0 586 $this->addCategory($category);
Chris@0 587 }
Chris@0 588
Chris@0 589 return $this;
Chris@0 590 }
Chris@0 591
Chris@0 592 /**
Chris@0 593 * Get the entry categories
Chris@0 594 *
Chris@0 595 * @return string|null
Chris@0 596 */
Chris@0 597 public function getCategories()
Chris@0 598 {
Chris@2 599 if (! array_key_exists('categories', $this->data)) {
Chris@0 600 return;
Chris@0 601 }
Chris@0 602 return $this->data['categories'];
Chris@0 603 }
Chris@0 604
Chris@0 605 /**
Chris@0 606 * Adds an enclosure to the entry. The array parameter may contain the
Chris@0 607 * keys 'uri', 'type' and 'length'. Only 'uri' is required for Atom, though the
Chris@0 608 * others must also be provided or RSS rendering (where they are required)
Chris@0 609 * will throw an Exception.
Chris@0 610 *
Chris@0 611 * @param array $enclosure
Chris@0 612 * @throws Exception\InvalidArgumentException
Chris@0 613 * @return Entry
Chris@0 614 */
Chris@0 615 public function setEnclosure(array $enclosure)
Chris@0 616 {
Chris@2 617 if (! isset($enclosure['uri'])) {
Chris@0 618 throw new Exception\InvalidArgumentException('Enclosure "uri" is not set');
Chris@0 619 }
Chris@2 620 if (! Uri::factory($enclosure['uri'])->isValid()) {
Chris@0 621 throw new Exception\InvalidArgumentException('Enclosure "uri" is not a valid URI/IRI');
Chris@0 622 }
Chris@0 623 $this->data['enclosure'] = $enclosure;
Chris@0 624
Chris@0 625 return $this;
Chris@0 626 }
Chris@0 627
Chris@0 628 /**
Chris@0 629 * Retrieve an array of all enclosures to be added to entry.
Chris@0 630 *
Chris@0 631 * @return array
Chris@0 632 */
Chris@0 633 public function getEnclosure()
Chris@0 634 {
Chris@2 635 if (! array_key_exists('enclosure', $this->data)) {
Chris@0 636 return;
Chris@0 637 }
Chris@0 638 return $this->data['enclosure'];
Chris@0 639 }
Chris@0 640
Chris@0 641 /**
Chris@0 642 * Unset a specific data point
Chris@0 643 *
Chris@0 644 * @param string $name
Chris@0 645 * @return Entry
Chris@0 646 */
Chris@0 647 public function remove($name)
Chris@0 648 {
Chris@0 649 if (isset($this->data[$name])) {
Chris@0 650 unset($this->data[$name]);
Chris@0 651 }
Chris@0 652
Chris@0 653 return $this;
Chris@0 654 }
Chris@0 655
Chris@0 656 /**
Chris@0 657 * Get registered extensions
Chris@0 658 *
Chris@0 659 * @return array
Chris@0 660 */
Chris@0 661 public function getExtensions()
Chris@0 662 {
Chris@0 663 return $this->extensions;
Chris@0 664 }
Chris@0 665
Chris@0 666 /**
Chris@0 667 * Return an Extension object with the matching name (postfixed with _Entry)
Chris@0 668 *
Chris@0 669 * @param string $name
Chris@0 670 * @return object
Chris@0 671 */
Chris@0 672 public function getExtension($name)
Chris@0 673 {
Chris@0 674 if (array_key_exists($name . '\\Entry', $this->extensions)) {
Chris@0 675 return $this->extensions[$name . '\\Entry'];
Chris@0 676 }
Chris@0 677 return;
Chris@0 678 }
Chris@0 679
Chris@0 680 /**
Chris@0 681 * Set the current feed type being exported to "rss" or "atom". This allows
Chris@0 682 * other objects to gracefully choose whether to execute or not, depending
Chris@0 683 * on their appropriateness for the current type, e.g. renderers.
Chris@0 684 *
Chris@0 685 * @param string $type
Chris@0 686 * @return Entry
Chris@0 687 */
Chris@0 688 public function setType($type)
Chris@0 689 {
Chris@0 690 $this->type = $type;
Chris@0 691 return $this;
Chris@0 692 }
Chris@0 693
Chris@0 694 /**
Chris@0 695 * Retrieve the current or last feed type exported.
Chris@0 696 *
Chris@0 697 * @return string Value will be "rss" or "atom"
Chris@0 698 */
Chris@0 699 public function getType()
Chris@0 700 {
Chris@0 701 return $this->type;
Chris@0 702 }
Chris@0 703
Chris@0 704 /**
Chris@0 705 * Method overloading: call given method on first extension implementing it
Chris@0 706 *
Chris@0 707 * @param string $method
Chris@0 708 * @param array $args
Chris@0 709 * @return mixed
Chris@0 710 * @throws Exception\BadMethodCallException if no extensions implements the method
Chris@0 711 */
Chris@0 712 public function __call($method, $args)
Chris@0 713 {
Chris@0 714 foreach ($this->extensions as $extension) {
Chris@0 715 try {
Chris@0 716 return call_user_func_array([$extension, $method], $args);
Chris@0 717 } catch (\BadMethodCallException $e) {
Chris@0 718 }
Chris@0 719 }
Chris@0 720 throw new Exception\BadMethodCallException('Method: ' . $method
Chris@0 721 . ' does not exist and could not be located on a registered Extension');
Chris@0 722 }
Chris@0 723
Chris@0 724 /**
Chris@0 725 * Creates a new Zend\Feed\Writer\Source data container for use. This is NOT
Chris@0 726 * added to the current feed automatically, but is necessary to create a
Chris@0 727 * container with some initial values preset based on the current feed data.
Chris@0 728 *
Chris@0 729 * @return Source
Chris@0 730 */
Chris@0 731 public function createSource()
Chris@0 732 {
Chris@0 733 $source = new Source;
Chris@0 734 if ($this->getEncoding()) {
Chris@0 735 $source->setEncoding($this->getEncoding());
Chris@0 736 }
Chris@0 737 $source->setType($this->getType());
Chris@0 738 return $source;
Chris@0 739 }
Chris@0 740
Chris@0 741 /**
Chris@0 742 * Appends a Zend\Feed\Writer\Entry object representing a new entry/item
Chris@0 743 * the feed data container's internal group of entries.
Chris@0 744 *
Chris@0 745 * @param Source $source
Chris@0 746 * @return Entry
Chris@0 747 */
Chris@0 748 public function setSource(Source $source)
Chris@0 749 {
Chris@0 750 $this->data['source'] = $source;
Chris@0 751 return $this;
Chris@0 752 }
Chris@0 753
Chris@0 754 /**
Chris@0 755 * @return Source
Chris@0 756 */
Chris@0 757 public function getSource()
Chris@0 758 {
Chris@0 759 if (isset($this->data['source'])) {
Chris@0 760 return $this->data['source'];
Chris@0 761 }
Chris@0 762 return;
Chris@0 763 }
Chris@0 764
Chris@0 765 /**
Chris@0 766 * Load extensions from Zend\Feed\Writer\Writer
Chris@0 767 *
Chris@0 768 * @return void
Chris@0 769 */
Chris@2 770 // @codingStandardsIgnoreStart
Chris@0 771 protected function _loadExtensions()
Chris@0 772 {
Chris@2 773 // @codingStandardsIgnoreEnd
Chris@0 774 $all = Writer::getExtensions();
Chris@0 775 $manager = Writer::getExtensionManager();
Chris@0 776 $exts = $all['entry'];
Chris@0 777 foreach ($exts as $ext) {
Chris@0 778 $this->extensions[$ext] = $manager->get($ext);
Chris@0 779 $this->extensions[$ext]->setEncoding($this->getEncoding());
Chris@0 780 }
Chris@0 781 }
Chris@0 782 }