Example #1
0
 /**
  * Adds files returned by an iterator.
  *
  * The base directory path is used to trim convert absolute paths into
  * relative file inside the archive. The path `/path/to/my/file.php`
  * would then become `my/file.php` if `/path/to/` is provided as the
  * base path. It is important to note that the trailing slash in the base
  * directory path is necessary.
  *
  * @param Iterator $iterator The iterator.
  * @param string   $base     The base directory path.
  *
  * @return array An associative array mapping archive paths to file system paths.
  */
 public function buildFromIterator($iterator, $base = null)
 {
     if (null === $this->dispatcher) {
         return parent::buildFromIterator($iterator, $base);
     }
     $event = new PreBuildFromIteratorEvent($this, $iterator, $base);
     $this->dispatcher->dispatch(Events::PRE_BUILD_FROM_ITERATOR, $event);
     $map = array();
     if (!$event->isSkipped()) {
         $map = parent::buildFromIterator($event->getIterator(), $event->getBase());
         $event = new PostBuildFromIteratorEvent($this, $event->getIterator(), $event->getBase());
         $this->dispatcher->dispatch(Events::POST_BUILD_FROM_ITERATOR, $event);
     }
     return $map;
 }
Example #2
0
 /**
  * Logs when all of the items from an iterator are added.
  *
  * @param PostBuildFromIteratorEvent $event The event arguments.
  */
 public function onPostBuildFromIterator(PostBuildFromIteratorEvent $event)
 {
     $iterator = $event->getIterator();
     // @codeCoverageIgnoreStart
     if ($iterator instanceof LoggerIterator) {
         $class = get_class($iterator->getInnerIterator());
     } else {
         $class = get_class($iterator);
     }
     // @codeCoverageIgnoreEnd
     $base = explode('\\', $class);
     $base = array_pop($base);
     $this->logger->info(sprintf('The items from the "%s" iterator have been added.', $base), array('base' => $event->getBase(), 'class' => $class));
 }