Exemplo n.º 1
0
 /**
  * @inheritdoc
  */
 protected function setUp()
 {
     $this->modifier = new CallbackTransformer(function () {
     });
     $this->reader = new XmlReader(new StringResource('<foo><bar>Baz</bar></foo>'));
     $this->reader->setNodeCallback('foo');
 }
Exemplo n.º 2
0
 /**
  * @param ResourceInterface $resource
  *
  * @return array
  */
 protected function breakup(ResourceInterface $resource)
 {
     $originalFile = $resource->getFile();
     $baseFile = $originalFile->getPathname();
     $this->reader->setResources(new ResourceCollection([$resource]));
     $partCount = 0;
     $started = false;
     while ($this->reader->valid()) {
         if ($this->reader->key() % $this->size === 0) {
             if ($this->reader->key() > 0) {
                 $this->endPart();
             }
             $file = sprintf('%s.part%s', $baseFile, ++$partCount);
             $this->startPart($file);
             $started = true;
         }
         $this->writer->write($this->reader->current());
         $this->writer->flush();
         $this->reader->next();
     }
     if ($started) {
         $this->endPart();
     }
     return $this->getPartFiles($resource);
 }
Exemplo n.º 3
0
 /**
  * @return ParameterBag|null
  */
 public function getNextItem()
 {
     while ($item = $this->reader->read()) {
         try {
             $this->eventDispatcher->dispatch(FeedEvents::ITEM_PRE_MODIFICATION, new ItemModificationEvent($item));
             $item = $this->modify($item);
             $this->eventDispatcher->dispatch(FeedEvents::ITEM_POST_MODIFICATION, new ItemModificationEvent($item));
             return $item;
         } catch (FilterException $e) {
             $this->eventDispatcher->dispatch(FeedEvents::ITEM_FILTERED, new ItemNotModifiedEvent($item, $e->getMessage()));
         } catch (ValidationException $e) {
             $this->eventDispatcher->dispatch(FeedEvents::ITEM_INVALID, new InvalidItemEvent($item, $e->getMessage()));
         } catch (ModificationException $e) {
             if ($e->getPrevious()) {
                 $e = $e->getPrevious();
             }
             $this->eventDispatcher->dispatch(FeedEvents::ITEM_FAILED, new ItemNotModifiedEvent($item, $e->getMessage()));
         }
     }
     return null;
 }
Exemplo n.º 4
0
 /**
  * @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;
 }