/** * @param array $filters * @return $this */ public function withFilters(array $filters) { if (!empty($filters)) { foreach ($filters as $currentFilter) { if (!strpos($currentFilter, ':')) { throw new \InvalidArgumentException(sprintf('The filter "%s" is not a valid filter. A valid filter has the format <name>:<value>.', $currentFilter)); } $currentFilterElements = explode(':', $currentFilter, 2); switch (trim($currentFilterElements[0])) { case 'exclude': $this->finder->exclude($currentFilterElements[1]); break; case 'name': $this->finder->name($currentFilterElements[1]); break; case 'notName': $this->finder->notName($currentFilterElements[1]); break; case 'path': $this->finder->path($currentFilterElements[1]); break; case 'size': $this->finder->size($currentFilterElements[1]); } } } return $this; }
/** * @param InputInterface $input * @param OutputInterface $output * @return int|null|void * @throws \RuntimeException */ protected function execute(InputInterface $input, OutputInterface $output) { $commandConfig = $this->getCommandConfig(); $this->detectMagento($output); $finder = new Finder(); $finder->files()->followLinks(true)->in($this->getApplication()->getMagentoRootFolder() . DIRECTORY_SEPARATOR . 'media'); if ($input->getOption('strip')) { $finder->exclude($commandConfig['strip']['folders']); } $filename = (string) $input->getArgument('filename'); if (is_dir($filename)) { // support for dot dir $filename = realpath($filename); $filename .= '/'; } if (empty($filename) || is_dir($filename)) { $filename .= 'media_' . date('Ymd_his') . '.zip'; } $zip = new \ZipArchive(); $zip->open($filename, \ZIPARCHIVE::CREATE); $zip->addEmptyDir('media'); $lastFolder = ''; foreach ($finder as $file) { /* @var $file SplFileInfo */ $currentFolder = pathinfo($file->getRelativePathname(), PATHINFO_DIRNAME); if ($currentFolder != $lastFolder) { $output->writeln(sprintf('<info>Compress directory:</info> <comment>media/%s</comment>', $currentFolder)); } $zip->addFile($file->getPathname(), 'media' . DIRECTORY_SEPARATOR . $file->getRelativePathname()); $lastFolder = $currentFolder; } $zip->close(); }
/** * @return array */ public function findFiles() { $files = array(); $finder = new Finder(); $iterate = false; $finder->ignoreUnreadableDirs(); foreach ($this->items as $item) { if (!is_file($item)) { $finder->in($item); $iterate = true; } else { $files[] = realpath($item); } } foreach ($this->excludes as $exclude) { $finder->exclude($exclude); } foreach ($this->names as $name) { $finder->name($name); } foreach ($this->notNames as $notName) { $finder->notName($notName); } foreach ($this->regularExpressionsExcludes as $regularExpressionExclude) { $finder->notPath($regularExpressionExclude); } if ($iterate) { foreach ($finder as $file) { $files[] = $file->getRealpath(); } } return $files; }
/** * * @param string $path * @return \Symfony\Component\Finder\Finder */ protected function getFinder($path) { $finder = new Finder(); $finder->ignoreDotFiles(TRUE); $finder->depth(0); $finder->exclude($this->excludeDirs); if (!is_dir($path)) { return $finder; } $finder->in($path); return $finder; }
protected function doExecute(InputInterface $input, OutputInterface $output) { $finder = new Finder(); $in = $this->container['cache.paths']->getArrayCopy(); $finder->exclude('.git')->exclude('.svn')->in($in); $this->container['filesystem']->remove($finder); if ($this->container['phraseanet.configuration-tester']->isInstalled()) { $this->getService('phraseanet.cache-service')->flushAll(); } $output->write('Finished !', true); return 0; }
protected function doExecute(InputInterface $input, OutputInterface $output) { $finder = new Finder(); $finder->exclude('.git')->exclude('.svn')->in([$this->container['root.path'] . '/tmp/cache_minify/', $this->container['root.path'] . '/tmp/cache_twig/', $this->container['root.path'] . '/tmp/translations/', $this->container['root.path'] . '/tmp/cache/profiler/', $this->container['root.path'] . '/tmp/doctrine/', $this->container['root.path'] . '/tmp/serializer/']); $filesystem = new Filesystem(); $filesystem->remove($finder); if ($this->container['phraseanet.configuration-tester']->isInstalled()) { $this->getService('phraseanet.cache-service')->flushAll(); } $output->write('Finished !', true); return 0; }
/** * Clear all the compiled assets. * * @param bool $clean * @return void */ public function clearAssets($clear = false) { if ($clear) { $path = $this->locationGenerator->getPublicPath($this->cachePath); $finder = new Finder(); $finder->in($path); $finder->exclude(array('.gitignore')); $files = array(); foreach ($finder->files() as $file) { $files[] = $path . DIRECTORY_SEPARATOR . $file->getRelativePathname(); } with(new Filesystem())->remove($files); } }
/** * @param $directory * @param $source */ private function extractThemeGenerators($directory, $source) { $finder = new Finder(); $finder->files()->name('*Generator.php')->in($directory)->depth('< 2'); $finder->exclude('Exclude'); if (!$this->develop) { $finder->exclude('Develop'); } foreach ($finder as $file) { $className = sprintf('Drupal\\%s\\Generator\\%s', $source, str_replace(['/', '.php'], ['\\', ''], $file->getRelativePathname())); include $file->getPathname(); } }
/** * Executes the current command. * * @param InputInterface $input An InputInterface instance * @param OutputInterface $output An OutputInterface instance * * @return null|int null or 0 if everything went fine, or an error code */ protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln(''); $output->writeln('<comment>Creating package</comment>'); $this->validate($input, $output); try { //get all params $rutaPhar = $input->getOption('output'); $alias = $input->getOption('alias') . '.phar'; $rutaPhar = rtrim($rutaPhar, '/') . '/' . $alias; $src = $input->getOption('src'); $stub = $input->getOption('stub'); $stubweb = $input->getOption('stubweb'); $replace = $input->getOption('replace'); $exclude = $input->getOption('exclude'); if (true === $replace && is_file($rutaPhar)) { \Phar::unlinkArchive($rutaPhar); } //create and setup Stup object $oStub = new Stub(); if (null !== $stub) { $oStub->setStubCli($stub); } if (null !== $stubweb) { $oStub->setStubWeb($stubweb); } $oStub->setDirTmp($src); $oStub->createDefaultStub(); //create Finder object $finder = new Finder(); $finder->files()->in($src); foreach ($exclude as $dirToExclude) { $finder->exclude($dirToExclude); } //inicialize progressbar $progress = new ProgressBar($output, count($finder)); //create phar object $phar = new \Phar($rutaPhar, 0, $alias); $phar->startBuffering(); //create default stubs $phar->setStub($phar->createDefaultStub($oStub->getStubCli(), $oStub->getStubWeb())); $progress->setBarCharacter('<comment>=</comment>'); $progress->setProgressCharacter('<comment>></comment>'); //add all files in the phar object $progress->start(); foreach ($finder as $file) { $alias = ltrim(str_replace($src, '', $file->getPathname()), '/'); $phar->addFile($file, $alias); $progress->advance(); } $progress->finish(); $phar->stopBuffering(); $oStub->deleteTmpStubs(); $output->writeln(''); $output->writeln(''); $output->writeln("<info>Phar created in: </info>" . $rutaPhar); } catch (\Exception $e) { $output->writeln('<error>' . $e->getMessage() . "</error>"); exit(1); } }
/** * Get suite files with tests. * * @return \ArrayObject */ public function getFiles() { if ($this->files === null) { $files = new \ArrayObject(); foreach ($this->config['source'] as $source) { $finder = new Finder(); $finder->ignoreUnreadableDirs()->files(); $finder->in($source['in'])->name($source['name']); if (!empty($source['notName'])) { foreach ($source['notName'] as $name) { $finder->notName($name); } } if (!empty($source['exclude'])) { $finder->exclude($source['exclude']); } /** @var \SplFileInfo $file */ foreach ($finder as $file) { $realPath = $file->getRealPath(); if (!$files->offsetExists($realPath) && substr($file->getFilename(), -8) === 'Test.php') { $files[$realPath] = $file; } } } $this->files = $files; } return $this->files; }
public function index() { /* |-------------------------------------------------------------------------- | Paramers |-------------------------------------------------------------------------- | | Match overrides Extension. Exclusion applies in both cases. | */ $match = $this->fetchParam('match', false); $exclude = $this->fetchParam('exclude', false); $extension = $this->fetchParam('extension', false); $in = $this->fetchParam('in', false); $not_in = $this->fetchParam('not_in', false); $file_size = $this->fetchParam('file_size', false); $file_date = $this->fetchParam('file_date', false); $depth = $this->fetchParam('depth', false); if ($file_size) { $file_size = Helper::explodeOptions($file_size); } if ($extension) { $extension = Helper::explodeOptions($extension); } /* |-------------------------------------------------------------------------- | Finder |-------------------------------------------------------------------------- | | Get_Files implements most of the Symfony Finder component as a clean | tag wrapper mapped to matched filenames. | */ $finder = new Finder(); $finder->in($in); // Finder doesn't respect multiple glob options, // so this will need to wait until later. // // $match = str_replace('{{', '{', $match); // $match = str_replace('}}', '}', $match); /* |-------------------------------------------------------------------------- | Name |-------------------------------------------------------------------------- | | Match is the "native" Finder name() method, which is supposed to | implement string, glob, and regex. The glob support is only partial, | so "extension" is a looped *single* glob rule iterator. | */ if ($match) { $finder->name($match); } elseif ($extension) { foreach ($extension as $ext) { $finder->name("*.{$ext}"); } } /* |-------------------------------------------------------------------------- | Exclude |-------------------------------------------------------------------------- | | Exclude directories from matching. Remapped to "not in" to allow more | intuitive differentiation between filename and directory matching. | */ if ($not_in) { $finder->exclude($not_in); } /* |-------------------------------------------------------------------------- | Not Name |-------------------------------------------------------------------------- | | Exclude files matching a given pattern: string, regex, or glob. | */ if ($exclude) { $finder->notName($exclude); } /* |-------------------------------------------------------------------------- | File Size |-------------------------------------------------------------------------- | | Restrict files by size. Can be chained and allows comparison operators. | */ if ($file_size) { foreach ($file_size as $size) { $finder->size($size); } } /* |-------------------------------------------------------------------------- | File Date |-------------------------------------------------------------------------- | | Restrict files by last modified date. Can use comparison operators, and | since/after is aliased to >, and until/before to <. | */ if ($file_date) { $finder->date($file_date); } /* |-------------------------------------------------------------------------- | Depth |-------------------------------------------------------------------------- | | Recursively traverse directories, starting at 0. | */ if ($depth) { $finder->depth($depth); } $matches = $finder->files(); /* |-------------------------------------------------------------------------- | Return and Parse |-------------------------------------------------------------------------- | | This tag returns the matched filenames mapped to {{ file }}. | */ $files = array(); foreach ($matches as $file) { $files[] = array('file' => '/' . $in . '/' . $file->getRelativePathname()); // $files[] = YAML::parse($file->getContents()); } return Parse::tagLoop($this->content, $files); }
/** * @param \DOMNode $node * @return \Iterator|null */ protected function _parseIterator(DOMNode $node) { $finder = new Finder(); $finder->files(); foreach ($node->childNodes as $option) { if ($option->nodeType === XML_ELEMENT_NODE) { $nodeName = strtolower($option->nodeName); $value = $option->nodeValue; switch ($nodeName) { case 'name': $finder->name($value); break; case 'notname': $finder->notName($value); break; case 'path': $finder->in($value); break; case 'size': $finder->size($value); break; case 'exclude': $finder->exclude($value); break; } } } return $finder->getIterator(); }
/** * @return Finder */ public function exclude($dirs) { return parent::exclude($dirs); }
protected function prepareFinder($directories, $excludes, array $names = null) { $finder = new Finder(); $finder->files(); if (!is_null($names) && count($names) > 0) { foreach ($names as $name) { $finder->name($name); } } else { $finder->name('*.php'); } if ($directories) { foreach ($directories as $directory) { $finder->in($directory); } } else { $finder->in('.'); } if (isset($excludes)) { foreach ($excludes as $exclude) { $finder->exclude($exclude); } } return $finder; }
/** * * @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; }
/** * Create a Finder object for use in searching a particular directory * location. * * @param string $directory The location to search * @param string $depth The depth limitation * * @return Finder */ protected function createFinder($directory, $depth) { $finder = new Finder(); $finder->files()->name($this->searchPattern)->in($directory)->depth($depth); foreach ($this->excludeList as $item) { $finder->exclude($item); } return $finder; }
/** * Scans directory structure for wireframes using configuration from * config.yml. Uses the `path` component to fill in various missing details * for display purposes. * * @return A structured array of routes this application can understand. */ private function templateScan() { // store routes here $routes = []; // get a finder $files = new Finder(); $files->files()->in(BASE_DIR . '/templates'); // configure finder foreach ($this->config['scan_options']['exclude_dir'] as $dir) { $files->exclude($dir); } foreach ($this->config['scan_options']['include_name'] as $name) { $files->name($name); } foreach ($this->config['scan_options']['exclude_name'] as $name) { $files->notName($name); } // create routes from files foreach ($files as $file) { $path = '/' . str_replace('.html.twig', '', $file->getRelativePathname()); $routes[$path] = ['path' => $path, 'template' => $file->getRelativePathname(), 'description' => $path]; } return $routes; }
/** * Apply configuration to finder * * @param Finder $finder */ public function apply(Finder $finder) { $finder->exclude($this->excludeDirs); foreach ($this->excludePaths as $pattern) { $finder->notPath($pattern); } foreach ($this->excludeFiles as $pattern) { $finder->notName($pattern); } $finder->in($this->includeDirs); foreach ($this->includePaths as $pattern) { $finder->path($pattern); } foreach ($this->includeFiles as $pattern) { $finder->name($pattern); } }
protected function phase3_copy_files() { $site = $this->site; $finder = new Finder(); $finder->files()->name('*')->useBestAdapter()->in($this->site['source'])->exclude($this->site['category_dir'])->exclude($this->site['tag_dir'])->ignoreDotFiles(1)->ignoreVCS(1)->ignoreUnreadableDirs(1)->sortByName(); foreach ($site['include'] as $fn) { $finder->notName($fn); } foreach ($site['exclude'] as $fn) { $finder->exclude($fn); } foreach ($site['notname'] as $fn) { $finder->notName($fn); } foreach ($finder as $file) { $realpath = $file->getRealPath(); $targetpath = str_replace($this->site['source'], $this->site['destination'], $realpath); @mkdir(dirname($targetpath), 0755, 1); copy($realpath, $targetpath); } }
/** * @return array */ public function findFiles() { $files = array(); $finder = new Finder(); $iterate = FALSE; foreach ($this->items as $item) { if (!is_file($item)) { $finder->in($item); $iterate = TRUE; } else { $files[] = realpath($item); } } foreach ($this->excludes as $exclude) { $finder->exclude($exclude); } foreach ($this->names as $name) { $finder->name($name); } if ($iterate) { foreach ($finder as $file) { $files[] = $file->getRealpath(); } } return $files; }
/** * Builds a ResourceWatcher instance. * * @param string $sourceDir Source path. * @param string $destinationDir Destination path. * * @return \Yosymfony\ResourceWatcher\ResourceWatcher */ protected function buildResourceWatcher($sourceDir, $destinationDir) { $fs = new Filesystem(); $relativeDestination = rtrim($fs->makePathRelative($destinationDir, $sourceDir), '/'); $finder = new Finder(); $finder->files()->name('*.*')->in($sourceDir); if (false === strpos($relativeDestination, '..')) { $finder->exclude($relativeDestination); } $rc = new ResourceCacheMemory(); $rw = new ResourceWatcher($rc); $rw->setFinder($finder); return $rw; }
/** * @param InputInterface $input * @return Finder */ public function createFinder(InputInterface $input) { $finder = new Finder(); $finder->files(); foreach ($input->getArgument('directory') as $dir) { $finder->in($dir); } foreach ($input->getOption('not-dir') as $ignoreDir) { $finder->exclude($ignoreDir); } foreach ($input->getOption('file-name') as $pattern) { $finder->name($pattern); } foreach ($input->getOption('not-file-name') as $pattern) { $finder->notName($pattern); } foreach ($input->getOption('contains') as $pattern) { $finder->contains($pattern); } foreach ($input->getOption('not-contains') as $pattern) { $finder->notContains($pattern); } foreach ($input->getOption('path') as $pattern) { $finder->path($pattern); } foreach ($input->getOption('not-path') as $pattern) { $finder->notPath($pattern); } if ($size = $input->getOption('size')) { $finder->size($size); } if ($modified = $input->getOption('modified')) { $finder->date($modified); } if ($depth = $input->getOption('depth')) { $finder->depth($depth); } return $finder; }
/** * @param $directory * @param $source * @param $type * @return array */ private function extractCommands($directory, $source, $type) { $finder = new Finder(); $finder->files()->name('*Command.php')->in($directory)->depth('< 2'); $finder->exclude('Exclude'); if (!$this->develop) { $finder->exclude('Develop'); } $commands = []; foreach ($finder as $file) { $className = sprintf('Drupal\\%s\\Command\\%s', $source, str_replace(['/', '.php'], ['\\', ''], $file->getRelativePathname())); if ($type != 'module') { include $file->getPathname(); } $command = $this->validateCommand($className, $source, $type); if ($command) { $commands[] = $command; } } return $commands; }
public function index() { /* |-------------------------------------------------------------------------- | Paramers |-------------------------------------------------------------------------- | | Match overrides Extension. Exclusion applies in both cases. | */ $match = $this->fetchParam('match', false); $exclude = $this->fetchParam('exclude', false); $extension = $this->fetchParam(array('extension', 'type'), false); $in = $this->fetchParam(array('in', 'folder', 'from'), false); $not_in = $this->fetchParam('not_in', false); $file_size = $this->fetchParam('file_size', false); $file_date = $this->fetchParam('file_date', false); $depth = $this->fetchParam('depth', false); $sort_by = $this->fetchParam(array('sort_by', 'order_by'), false); $sort_dir = $this->fetchParam(array('sort_dir', 'sort_direction'), 'asc'); $limit = $this->fetchParam('limit', false); if ($in) { $in = Helper::explodeOptions($in); } if ($not_in) { $not_in = Helper::explodeOptions($not_in); } if ($file_size) { $file_size = Helper::explodeOptions($file_size); } if ($extension) { $extension = Helper::explodeOptions($extension); } /* |-------------------------------------------------------------------------- | Finder |-------------------------------------------------------------------------- | | Get_Files implements most of the Symfony Finder component as a clean | tag wrapper mapped to matched filenames. | */ $finder = new Finder(); if ($in) { foreach ($in as $location) { $finder->in(Path::fromAsset($location)); } } /* |-------------------------------------------------------------------------- | Name |-------------------------------------------------------------------------- | | Match is the "native" Finder name() method, which is supposed to | implement string, glob, and regex. The glob support is only partial, | so "extension" is a looped *single* glob rule iterator. | */ if ($match) { $finder->name($match); } elseif ($extension) { foreach ($extension as $ext) { $finder->name("*.{$ext}"); } } /* |-------------------------------------------------------------------------- | Exclude |-------------------------------------------------------------------------- | | Exclude directories from matching. Remapped to "not in" to allow more | intuitive differentiation between filename and directory matching. | */ if ($not_in) { foreach ($not_in as $location) { $finder->exclude($location); } } /* |-------------------------------------------------------------------------- | Not Name |-------------------------------------------------------------------------- | | Exclude files matching a given pattern: string, regex, or glob. | By default we don't allow looking for PHP files. Be smart. | */ if ($this->fetchParam('allow_php', false) !== TRUE) { $finder->notName("*.php"); } if ($exclude) { $finder->notName($exclude); } /* |-------------------------------------------------------------------------- | File Size |-------------------------------------------------------------------------- | | Restrict files by size. Can be chained and allows comparison operators. | */ if ($file_size) { foreach ($file_size as $size) { $finder->size($size); } } /* |-------------------------------------------------------------------------- | File Date |-------------------------------------------------------------------------- | | Restrict files by last modified date. Can use comparison operators, and | since/after is aliased to >, and until/before to <. | */ if ($file_date) { $finder->date($file_date); } /* |-------------------------------------------------------------------------- | Depth |-------------------------------------------------------------------------- | | Recursively traverse directories, starting at 0. | */ if ($depth) { $finder->depth($depth); } /* |-------------------------------------------------------------------------- | Sort By |-------------------------------------------------------------------------- | | Sort by name, file, or type | */ if ($sort_by) { if ($sort_by === 'file' || $sort_by === 'name') { $finder->sortByName(); } elseif ($sort_by === 'type') { $finder->sortByType(); } } /* |-------------------------------------------------------------------------- | Assemble File Array |-------------------------------------------------------------------------- | | Select the important bits of data on the list of files. | */ $matches = $finder->files()->followLinks(); $files = array(); foreach ($matches as $file) { $files[] = array('extension' => $file->getExtension(), 'filename' => $file->getFilename(), 'file' => Path::toAsset($file->getPathname()), 'name' => Path::toAsset($file->getPathname()), 'size' => File::getHumanSize($file->getSize()), 'size_bytes' => $file->getSize(), 'size_kilobytes' => number_format($file->getSize() / 1024, 2), 'size_megabytes' => number_format($file->getSize() / 1048576, 2), 'size_gigabytes' => number_format($file->getSize() / 1073741824, 2), 'is_image' => File::isImage($file->getPathname())); } /* |-------------------------------------------------------------------------- | Sort Direction |-------------------------------------------------------------------------- | | Set the sort direction, defaulting to "asc" (ascending) | */ if ($sort_dir === 'desc') { $files = array_reverse($files); } /* |-------------------------------------------------------------------------- | Randomizing |-------------------------------------------------------------------------- | | You can't sort randomly using Symfony finder, so we'll do it manually. | */ if ($sort_by === 'random') { shuffle($files); } /* |-------------------------------------------------------------------------- | Limit Files |-------------------------------------------------------------------------- | | Limit the number of files returned. Needs to be run after sort_dir to | ensure consistency. | */ if ($limit) { $files = array_slice($files, 0, $limit); } return Parse::tagLoop($this->content, $files, true, $this->context); }