Example #1
0
 /**
  * Apply path on config instance.
  */
 private function resolveConfigPath()
 {
     if ($this->isStdIn) {
         $this->config->finder(new \ArrayIterator(array(new StdinFileInfo())));
         return;
     }
     $isIntersectionPathMode = self::PATH_MODE_INTERSECTION === $this->options['path-mode'];
     $paths = array_filter(array_map(function ($path) {
         return realpath($path);
     }, $this->path));
     if (empty($paths)) {
         if ($isIntersectionPathMode) {
             $this->config->finder(new \ArrayIterator(array()));
         }
         return;
     }
     $pathsByType = array('file' => array(), 'dir' => array());
     foreach ($paths as $path) {
         $isFile = is_file($path);
         if (is_file($path)) {
             $pathsByType['file'][] = $path;
         } else {
             $pathsByType['dir'][] = $path . DIRECTORY_SEPARATOR;
         }
     }
     $currentFinder = $this->config->getFinder();
     $nestedFinder = null;
     $iterator = null;
     try {
         $nestedFinder = $currentFinder instanceof \IteratorAggregate ? $currentFinder->getIterator() : $currentFinder;
     } catch (\Exception $e) {
     }
     if ($isIntersectionPathMode) {
         if (null === $nestedFinder) {
             throw new InvalidConfigurationException('Cannot create intersection with not-fully defined Finder in configuration file.');
         }
         $iterator = new \CallbackFilterIterator($nestedFinder, function (\SplFileInfo $current) use($pathsByType) {
             $currentRealPath = $current->getRealPath();
             if (in_array($currentRealPath, $pathsByType['file'], true)) {
                 return true;
             }
             foreach ($pathsByType['dir'] as $path) {
                 if (0 === strpos($currentRealPath, $path)) {
                     return true;
                 }
             }
             return false;
         });
     } elseif ($currentFinder instanceof SymfonyFinder && null === $nestedFinder) {
         // finder from configuration Symfony finder and it is not fully defined, we may fulfill it
         $iterator = $currentFinder->in($pathsByType['dir'])->append($pathsByType['file']);
     } else {
         $iterator = Finder::create()->in($pathsByType['dir'])->append($pathsByType['file']);
     }
     $this->config->finder($iterator);
 }
 /**
  * Apply path on config instance.
  */
 private function resolveConfigPath()
 {
     if (is_file($this->path)) {
         $this->config->finder(new \ArrayIterator(array(new \SplFileInfo($this->path))));
     } elseif ($this->isStdIn) {
         $this->config->finder(new \ArrayIterator(array(new StdinFileInfo())));
     } elseif (null !== $this->path) {
         $this->config->setDir($this->path);
     }
 }