Exemple #1
0
 /**
  * Adds files using an iterator.
  *
  * @param Traversable $iterator The iterator.
  * @param string      $message  The message to announce.
  * @param boolean     $binary   Should the adding be binary-safe?
  *
  * @throws RuntimeException If a file is not readable.
  */
 private function add(Traversable $iterator = null, $message = null, $binary = false)
 {
     static $count = 0;
     if ($iterator) {
         if ($message) {
             $this->putln('?', $message);
         }
         $crate = $binary ? $this->crate->getPhar() : $this->crate;
         $baseRegex = $this->config->getBasePathRegex();
         $mapper = $this->config->getMapper();
         /** @var $file SplFileInfo */
         foreach ($iterator as $file) {
             if (0 === ++$count % 100) {
                 gc_collect_cycles();
             }
             $relative = preg_replace($baseRegex, '', $file->getPathname());
             if (null !== ($mapped = $mapper($relative))) {
                 $relative = $mapped;
             }
             if ($this->isVerbose()) {
                 if (false === $file->isReadable()) {
                     throw new RuntimeException(sprintf('The file "%s" is not readable.', $file->getPathname()));
                 }
                 $this->putln('+', $file);
                 if (null !== $mapped) {
                     $this->putln('>', $relative);
                 }
             }
             $crate->addFile($file, $relative);
         }
     }
 }
 /**
  * @depends testGetBasePath
  */
 public function testGetBasePathRegex()
 {
     $this->assertEquals('/' . preg_quote($this->config->getBasePath() . DIRECTORY_SEPARATOR, '/') . '/', $this->config->getBasePathRegex());
 }