Mercurial > hg > isophonics-drupal-site
comparison vendor/zendframework/zend-feed/src/Writer/FeedFactory.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 |
comparison
equal
deleted
inserted
replaced
11:bfffd8d7479a | 12:7a779792577d |
---|---|
20 * @throws Exception\InvalidArgumentException | 20 * @throws Exception\InvalidArgumentException |
21 * @return Feed | 21 * @return Feed |
22 */ | 22 */ |
23 public static function factory($data) | 23 public static function factory($data) |
24 { | 24 { |
25 if (!is_array($data) && !$data instanceof Traversable) { | 25 if (! is_array($data) && ! $data instanceof Traversable) { |
26 throw new Exception\InvalidArgumentException(sprintf( | 26 throw new Exception\InvalidArgumentException(sprintf( |
27 '%s expects an array or Traversable argument; received "%s"', | 27 '%s expects an array or Traversable argument; received "%s"', |
28 __METHOD__, | 28 __METHOD__, |
29 (is_object($data) ? get_class($data) : gettype($data)) | 29 (is_object($data) ? get_class($data) : gettype($data)) |
30 )); | 30 )); |
37 $key = static::convertKey($key); | 37 $key = static::convertKey($key); |
38 $method = 'set' . $key; | 38 $method = 'set' . $key; |
39 if (method_exists($feed, $method)) { | 39 if (method_exists($feed, $method)) { |
40 switch ($method) { | 40 switch ($method) { |
41 case 'setfeedlink': | 41 case 'setfeedlink': |
42 if (!is_array($value)) { | 42 if (! is_array($value)) { |
43 // Need an array | 43 // Need an array |
44 break; | 44 break; |
45 } | 45 } |
46 if (!array_key_exists('link', $value) || !array_key_exists('type', $value)) { | 46 if (! array_key_exists('link', $value) || ! array_key_exists('type', $value)) { |
47 // Need both keys to set this correctly | 47 // Need both keys to set this correctly |
48 break; | 48 break; |
49 } | 49 } |
50 $feed->setFeedLink($value['link'], $value['type']); | 50 $feed->setFeedLink($value['link'], $value['type']); |
51 break; | 51 break; |
86 * @throws Exception\InvalidArgumentException | 86 * @throws Exception\InvalidArgumentException |
87 * @return void | 87 * @return void |
88 */ | 88 */ |
89 protected static function createEntries($entries, Feed $feed) | 89 protected static function createEntries($entries, Feed $feed) |
90 { | 90 { |
91 if (!is_array($entries) && !$entries instanceof Traversable) { | 91 if (! is_array($entries) && ! $entries instanceof Traversable) { |
92 throw new Exception\InvalidArgumentException(sprintf( | 92 throw new Exception\InvalidArgumentException(sprintf( |
93 '%s::factory expects the "entries" value to be an array or Traversable; received "%s"', | 93 '%s::factory expects the "entries" value to be an array or Traversable; received "%s"', |
94 get_called_class(), | 94 get_called_class(), |
95 (is_object($entries) ? get_class($entries) : gettype($entries)) | 95 (is_object($entries) ? get_class($entries) : gettype($entries)) |
96 )); | 96 )); |
97 } | 97 } |
98 | 98 |
99 foreach ($entries as $data) { | 99 foreach ($entries as $data) { |
100 if (!is_array($data) && !$data instanceof Traversable && !$data instanceof Entry) { | 100 if (! is_array($data) && ! $data instanceof Traversable && ! $data instanceof Entry) { |
101 throw new Exception\InvalidArgumentException(sprintf( | 101 throw new Exception\InvalidArgumentException(sprintf( |
102 '%s expects an array, Traversable, or Zend\Feed\Writer\Entry argument; received "%s"', | 102 '%s expects an array, Traversable, or Zend\Feed\Writer\Entry argument; received "%s"', |
103 __METHOD__, | 103 __METHOD__, |
104 (is_object($data) ? get_class($data) : gettype($data)) | 104 (is_object($data) ? get_class($data) : gettype($data)) |
105 )); | 105 )); |
114 // Use case 2: iterate item and populate entry | 114 // Use case 2: iterate item and populate entry |
115 $entry = $feed->createEntry(); | 115 $entry = $feed->createEntry(); |
116 foreach ($data as $key => $value) { | 116 foreach ($data as $key => $value) { |
117 $key = static::convertKey($key); | 117 $key = static::convertKey($key); |
118 $method = 'set' . $key; | 118 $method = 'set' . $key; |
119 if (!method_exists($entry, $method)) { | 119 if (! method_exists($entry, $method)) { |
120 continue; | 120 continue; |
121 } | 121 } |
122 $entry->$method($value); | 122 $entry->$method($value); |
123 } | 123 } |
124 $feed->addEntry($entry); | 124 $feed->addEntry($entry); |