You are here

protected static function FeedFactory::createEntries in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/zendframework/zend-feed/src/Writer/FeedFactory.php \Zend\Feed\Writer\FeedFactory::createEntries()

Create and attach entries to a feed

Parameters

array|Traversable $entries:

Feed $feed:

Return value

void

Throws

Exception\InvalidArgumentException

1 call to FeedFactory::createEntries()
FeedFactory::factory in vendor/zendframework/zend-feed/src/Writer/FeedFactory.php
Create and return a Feed based on data provided.

File

vendor/zendframework/zend-feed/src/Writer/FeedFactory.php, line 89

Class

FeedFactory

Namespace

Zend\Feed\Writer

Code

protected static function createEntries($entries, Feed $feed) {
  if (!is_array($entries) && !$entries instanceof Traversable) {
    throw new Exception\InvalidArgumentException(sprintf('%s::factory expects the "entries" value to be an array or Traversable; received "%s"', get_called_class(), is_object($entries) ? get_class($entries) : gettype($entries)));
  }
  foreach ($entries as $data) {
    if (!is_array($data) && !$data instanceof Traversable && !$data instanceof Entry) {
      throw new Exception\InvalidArgumentException(sprintf('%s expects an array, Traversable, or Zend\\Feed\\Writer\\Entry argument; received "%s"', __METHOD__, is_object($data) ? get_class($data) : gettype($data)));
    }

    // Use case 1: Entry item
    if ($data instanceof Entry) {
      $feed
        ->addEntry($data);
      continue;
    }

    // Use case 2: iterate item and populate entry
    $entry = $feed
      ->createEntry();
    foreach ($data as $key => $value) {
      $key = static::convertKey($key);
      $method = 'set' . $key;
      if (!method_exists($entry, $method)) {
        continue;
      }
      $entry
        ->{$method}($value);
    }
    $feed
      ->addEntry($entry);
  }
}