Beispiel #1
0
 /**
  * {@inheritdoc}
  */
 public function start()
 {
     $dispatcher = $this->getDispatcher();
     $sourceEvent = new SourcePipelineEvent();
     $sourceEvent->setContext($this->getContext());
     $dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_SOURCE), $sourceEvent);
     $this->setContext($sourceEvent->getContext());
     $sources = $sourceEvent->getSources();
     $outputs = [];
     $startEvent = new StartPipelineEvent();
     $startEvent->setContext($this->getContext());
     $startEvent->setItemCount($this->countSourceItems($sources));
     $dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_START), $startEvent);
     $this->setContext($startEvent->getContext());
     $this->progressBar && $this->progressBar->start($this->countSourceItems($sources));
     foreach ($sources as $source) {
         foreach ($source as $item) {
             $itemEvent = new ItemPipelineEvent($item);
             $itemEvent->setContext($this->getContext());
             $dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_MODIFY), $itemEvent);
             $dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_CONSUME), $itemEvent);
             $output = $itemEvent->getOutput();
             if ($output !== null) {
                 $outputs[] = $output;
             }
             $this->setContext($itemEvent->getContext());
             $this->progressBar && $this->progressBar->advance();
         }
     }
     $finishEvent = new FinishPipelineEvent();
     $finishEvent->setContext($this->getContext());
     $dispatcher->dispatch($this->getEventName(self::EVENT_SUFFIX_FINISH), $finishEvent);
     $this->progressBar && $this->progressBar->finish();
     return ['outputs' => $outputs];
 }
 /**
  * Returns diff provider.
  *
  * @param SourcePipelineEvent $event
  */
 public function onSource(SourcePipelineEvent $event)
 {
     $event->addSource($this->provider);
 }
 /**
  * Test addSource with non \Traversable.
  *
  * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage source must be of type \Traversable|array
  */
 public function testAddSourceNotTraversable()
 {
     $event = new SourcePipelineEvent();
     $event->addSource('foo');
 }
 /**
  * Gets data and adds source.
  *
  * @param SourcePipelineEvent $event
  */
 public function onSource(SourcePipelineEvent $event)
 {
     $event->addSource($this->getDocuments());
 }
 /**
  * Gives data for test.
  *
  * @param SourcePipelineEvent $event
  */
 public function onSource(SourcePipelineEvent $event)
 {
     $event->addSource(json_decode(file_get_contents(__DIR__ . '/dummyData.json')));
 }