append() public method

The set can be another Finder, an Iterator, an IteratorAggregate, or even a plain array.
public append ( mixed $iterator ) : Finder | Symfony\Component\Finder\SplFileInfo[]
$iterator mixed
return Finder | Symfony\Component\Finder\SplFileInfo[] The finder
Exemplo n.º 1
0
 /**
  * Track a set of paths
  *
  * @param array $paths the list of directories or files to track / follow
  */
 public function __construct(array $paths)
 {
     //Filter out the files, the Finder class can not handle files in the ->in() call.
     $files = array_filter($paths, function ($possible_file) {
         return is_file($possible_file);
     });
     //Filter out the directories to be used for searching using the Filter class.
     $dirs = array_filter($paths, function ($possible_dir) {
         return is_dir($possible_dir);
     });
     $finder = new Finder();
     //Add the given 'stand-alone-files'
     $finder->append($files);
     //Add the Directores recursively
     $finder = $finder->in($dirs);
     //Filter out non readable files
     $finder = $finder->filter(function (SplFileInfo $finder) {
         return $finder->isReadable();
     });
     //Loop through all the files and save the latest modification time.
     foreach ($finder->files() as $file) {
         /*@var $file \SplFileInfo */
         if ($this->modification_time < $file->getMTime()) {
             $this->modification_time = $file->getMTime();
         }
     }
 }
Exemplo n.º 2
0
 /**
  * @param $path
  * @param $extensions
  * @return Finder
  */
 protected function getFileIterator($path, $extensions)
 {
     $fileInfo = new SplFileInfo($path);
     $finder = new Finder();
     if ($fileInfo->isFile()) {
         return $finder->append(array($fileInfo));
     }
     return $finder->files()->in($path)->name('/\\.(' . implode('|', $extensions) . ')$/i');
 }
Exemplo n.º 3
0
 public function serveMarkdown($mdFile)
 {
     $basePath = dirname($mdFile) . '/' . basename($mdFile, '.md');
     $source = new Finder();
     $source->append([$mdFile]);
     if (is_dir($basePath)) {
         $children = new Finder();
         $children->in($basePath)->name('*.md')->sortByName();
         $source->append($children);
     }
     $merger = new Merge();
     $content = $merger->mergeFiles($source, $basePath);
     $converter = new Converter();
     $html = $converter->toHtml($content);
     EventManager::dispatch('preHeader');
     header('Content-Type: text/html; charset=utf-8');
     EventManager::dispatch('html', $html);
 }
Exemplo n.º 4
0
 /**
  * Find all php files by path.
  *
  * @param string $path Path
  *
  * @return Finder Finder iterable object with all PHP found files in path
  */
 public function findPHPFilesByPath($path)
 {
     $finder = new Finder();
     if (file_exists($path) && !is_dir($path)) {
         $finder->append([0 => $path]);
     } else {
         $finder->files()->in($path)->name('*.php');
     }
     return $finder;
 }
Exemplo n.º 5
0
 /**
  * Build a Symfony Finder object that scans the given $directory.
  *
  * @param string|array|Finder $directory The directory(s) or filename(s)
  * @param null|string|array $exclude The directory(s) or filename(s) to exclude (as absolute or relative paths)
  * @throws InvalidArgumentException
  */
 public static function finder($directory, $exclude = null)
 {
     if ($directory instanceof Finder) {
         return $directory;
     } else {
         $finder = new Finder();
         $finder->sortByName();
     }
     $finder->files();
     if (is_string($directory)) {
         if (is_file($directory)) {
             // Scan a single file?
             $finder->append([$directory]);
         } else {
             // Scan a directory
             $finder->in($directory);
         }
     } elseif (is_array($directory)) {
         foreach ($directory as $path) {
             if (is_file($path)) {
                 // Scan a file?
                 $finder->append([$path]);
             } else {
                 $finder->in($path);
             }
         }
     } else {
         throw new InvalidArgumentException('Unexpected $directory value:' . gettype($directory));
     }
     if ($exclude !== null) {
         if (is_string($exclude)) {
             $finder->notPath(Util::getRelativePath($exclude, $directory));
         } elseif (is_array($exclude)) {
             foreach ($exclude as $path) {
                 $finder->notPath(Util::getRelativePath($path, $directory));
             }
         } else {
             throw new InvalidArgumentException('Unexpected $exclude value:' . gettype($exclude));
         }
     }
     return $finder;
 }
 public function getFiles()
 {
     $finder = new Finder();
     try {
         $finder->in($this->getFindPath())->files();
     } catch (\InvalidArgumentException $e) {
         //catch non-existing directory exception.
         //This can happen if getFiles is called and no file has yet been uploaded
         //push empty array into the finder so we can emulate no files found
         $finder->append(array());
     }
     return $finder;
 }
 protected function createFromArray(array $paths)
 {
     $finder = new Finder();
     $files = [];
     $dirs = [];
     foreach ($paths as $path) {
         if (is_file($path)) {
             $files[] = $path;
             continue;
         }
         $dirs[] = $path;
     }
     return $finder->append($files)->in($dirs);
 }
Exemplo n.º 8
0
 /**
  * {@inheritdoc}
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $finder = new Finder();
     $path = $input->getOption('cwd');
     if (file_exists($path) && !is_dir($path)) {
         $finder->append([0 => $path]);
     } else {
         $finder->files()->in($path)->name('*.php');
     }
     $license = $this->getLicenseText($input->getOption('package'), $input->getOption('author'));
     $t = 0;
     foreach ($finder as $file) {
         $data = file_get_contents($file->getRealpath());
         $tokens = token_get_all($data);
         $content = '';
         $need_license = true;
         for ($i = 0, $c = count($tokens); $i < $c; ++$i) {
             if (!is_array($tokens[$i])) {
                 $content .= $tokens[$i];
                 continue;
             }
             if (T_DOC_COMMENT === $tokens[$i][0] && $this->isPHPStormLicense($tokens[$i][1])) {
                 // Delete Auto Generated PHPStorm comments
                 continue;
             } else {
                 if (T_COMMENT === $tokens[$i][0] && $this->isOldLicense($tokens[$i][1])) {
                     $content .= $license;
                     $need_license = false;
                 } else {
                     $content .= $tokens[$i][1];
                 }
             }
         }
         if ($need_license) {
             $content = preg_replace('/<\\?php/', "<?php\n\n" . trim($license) . "\n\n", $data, 1);
         }
         file_put_contents($file->getRealpath(), $content);
         $output->writeln(sprintf('[Modify] <comment>%s</comment>', $file->getPathname()));
         ++$t;
     }
     $output->writeln("<info>Command finished successfully. Licensified {$t} files.</info>");
 }
Exemplo n.º 9
0
 /**
  * Copy the rest files to destination
  * 
  * @return array Filenames affected
  */
 public function copyRestToDestination()
 {
     $fs = new Filesystem();
     $result = array();
     $includedFiles = array();
     $dir = $this->getSourceDir();
     $include = $this->configuration->getRepository()->get('include');
     $exclude = $this->configuration->getRepository()->get('exclude');
     $processableExt = $this->getProcessableExtention();
     $finder = new Finder();
     $finder->in($dir)->exclude($this->getSpecialDir());
     $finder->notName($this->configuration->getConfigFilename());
     $finder->notName($this->configuration->getConfigEnvironmentFilenameWildcard());
     $finder->notName($this->fileExtToRegExpr($processableExt));
     foreach ($include as $item) {
         if (is_dir($item)) {
             $finder->in($item);
         } else {
             if (is_file($item) && !in_array(pathinfo($item, PATHINFO_EXTENSION), $processableExt)) {
                 $includedFiles[] = new SplFileInfo($this->resolvePath($item), "", pathinfo($item, PATHINFO_BASENAME));
             }
         }
     }
     foreach ($exclude as $item) {
         $finder->notPath($item);
     }
     $finder->append($includedFiles);
     foreach ($finder as $file) {
         if ($file->isDir()) {
             $this->mkDirIfNotExists($this->getDestinationDir() . '/' . $file->getRelativePath());
         } else {
             if ($file->isFile()) {
                 $result[] = $file->getRealpath();
                 $fs->copy($file->getRealpath(), $this->getDestinationDir() . '/' . $file->getRelativePathname());
             }
         }
     }
     return $result;
 }
Exemplo n.º 10
0
 private function processContentFiles()
 {
     $includedFiles = [];
     $finder = new Finder();
     $finder->in($this->composeSubPath('content'))->notName('*.meta')->files();
     foreach ($this->params['include'] as $item) {
         if (is_dir($item)) {
             $finder->in($item);
         } elseif (is_file($item)) {
             $includedFiles[] = new SplFileInfo($item, '', pathinfo($item, PATHINFO_BASENAME));
         }
     }
     $finder->append($includedFiles);
     foreach ($this->params['exclude'] as $item) {
         $finder->notPath($item);
     }
     $this->processItems($finder, Item::TYPE_ITEM);
 }
Exemplo n.º 11
0
 public function testAppendWithAnArray()
 {
     $finder = new Finder();
     $finder->files()->in(self::$tmpDir . DIRECTORY_SEPARATOR . 'foo');
     $finder->append($this->toAbsolute(array('foo', 'toto')));
     $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->getIterator());
 }
Exemplo n.º 12
0
 /**
  *
  * @return Finder
  */
 protected function getFinder()
 {
     if (null === $this->finder) {
         $finder = new Finder();
         $settings = $this->getSettings();
         foreach ($settings->getSrc() as $source) {
             if (is_dir($source)) {
                 $finder->in($source);
             }
             if (is_file($source)) {
                 $finder->append(array($source));
             }
         }
         if (true === $settings->getFollowLinks()) {
             $finder->followLinks();
         }
         $finder->ignoreDotFiles($settings->getIgnoreDotFiles());
         $finder->name($settings->getFileSuffix());
         $finder->exclude($settings->getExclude());
         if (NULL !== $settings->getDate()) {
             $finder->date($settings->getDate());
         }
         $this->setFinder($finder);
     }
     return $this->finder;
 }
Exemplo n.º 13
0
 /**
  * @return Finder
  */
 public function append($iterator)
 {
     return parent::append($iterator);
 }