/** * @param Feed $feed */ protected function inspect(Feed $feed) { while ($item = $feed->getNextItem()) { foreach ($item->all() as $key => $value) { if (!array_key_exists($key, $this->data)) { $this->data[$key] = []; } $hash = md5(serialize($value)); if (!array_key_exists($hash, $this->data[$key])) { $this->data[$key][$hash] = 0; } ++$this->data[$key][$hash]; if (!array_key_exists($hash, $this->values)) { $this->values[$hash] = $value; } } } }
/** * Returns the next item in the feed, or null if no more items are left. * Use this when iterating over the feed. * * @param Feed $feed * * @return FeedItemBag|null */ protected function getNextItem(Feed $feed) { try { return $feed->getNextItem(); } catch (\Exception $exception) { $this->handleException($exception); } return null; }
public function testChangeContinueOnModificationException() { $feed = new Feed($this->reader); $feed->getEventDispatcher()->addListener(FeedEvents::ITEM_MODIFICATION_FAILED, function (FailedItemModificationEvent $e) { $e->setContinue(false); }); $feed->addModifier(new CallbackTransformer(function () { throw new ModificationException(); }), 1, true); $this->assertNull($feed->getNextItem(), 'The modification should have not continued'); }
/** * @param ReaderInterface $reader * @param EventDispatcherInterface $dispatcher * @param string $itemName * * @return Feed */ protected function createFeed(ReaderInterface $reader, EventDispatcherInterface $dispatcher, $itemName) { if ($reader instanceof XmlReader) { $reader->setNodeCallback($itemName); } $feed = new Feed($reader, $dispatcher); /** @var ModifierInterface $modifier */ foreach ($this->modifiers as $position => list($modifier, $continue)) { $feed->addModifier($modifier, $position, $continue); } return $feed; }