/** * @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; }
public function testNotName() { $finder = new Finder(); $this->assertSame($finder, $finder->notName('*.php')); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator()); $finder = new Finder(); $finder->notName('*.php'); $finder->notName('*.py'); $this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'toto')), $finder->in(self::$tmpDir)->getIterator()); $finder = new Finder(); $finder->name('test.ph*'); $finder->name('test.py'); $finder->notName('*.php'); $finder->notName('*.py'); $this->assertIterator(array(), $finder->in(self::$tmpDir)->getIterator()); }
/** * @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; }
protected function execute(InputInterface $input, OutputInterface $output) { $output->writeln($this->getDescription() . PHP_EOL); $target = $input->getArgument('target'); $sources = $this->createArrayBy($input->getOption('source')); $excludes = $this->createArrayBy($input->getOption('exclude')); $noComments = (bool) $input->getOption('nocomments'); $this->writer->setTarget($target); $this->finder->in($sources)->exclude($excludes); if ($notName = $input->getOption('notname')) { $this->finder->notName($notName); } $output->writeln(sprintf(Message::PROGRESS_FILTER, $this->finder->count())); $classMap = $this->filter->extractClassMapFrom($this->finder->getIterator()); $output->writeln(sprintf(Message::PROGRESS_WRITE, $target)); $this->writer->minify($classMap, $noComments); $output->writeln(PHP_EOL . Message::PROGRESS_DONE . PHP_EOL); }
/** * * @param type $filepattern * @param type $dir * @param type $excludepattern * @return \Awakenweb\Beverage\Beverage */ public function add($filepattern, $dir, $excludepattern) { $finder = new Finder(); $finder->files()->ignoreUnreadableDirs()->name($filepattern); if ($excludepattern) { $finder->notName($excludepattern); } foreach ($dir as $directory) { $finder->in($directory); } foreach ($finder as $matching_file) { $basename = $matching_file->getBasename(); $this->current_state[$basename] = $matching_file->getContents(); } return $this; }
public function run() { $files = []; $this->console('<comment>Watch server running.</comment>'); do { foreach ($this->files_iterators as $fi) { $finder = new Finder(); $finder->files()->ignoreUnreadableDirs()->name($fi['filepattern']); if ($fi['excludepattern']) { $finder->notName($fi['excludepattern']); } foreach ($fi['dir'] as $directory) { $finder->in($directory); } foreach ($finder as $file) { /** * Register the file the first time it is encountered */ if (!isset($files[$file->getBasename()])) { $files[$file->getBasename()] = $file->getMTime(); } /** * Check if the file has changed */ if ($files[$file->getBasename()] !== $file->getMTime()) { $this->console('File ' . $file->getBasename() . ' has been modified'); $files[$file->getBasename()] = $file->getMTime(); try { $this->runBefore(); foreach ($fi['tasks'] as $task) { $this->console('Running ' . $task . ' task'); $task(); $this->console('Task ' . $task . ' successful'); } $this->runAfter(); } catch (\Exception $ex) { $this->console("<error>An error occured when running the tasks.</error>"); } } } unset($finder); } sleep(3); } while (1); }
private function _findFiles() { $finder = new Finder(); $finder->files(); foreach ($this->_excludePatterns as $excludePattern) { $finder->notName($excludePattern); } foreach ($this->_paths as $p) { $finder->in($p); } if ($this->_followLinks) { $finder->followLinks(); } $files = array(); foreach ($finder as $f) { $files[$f->getRealpath()] = array('mtime' => $f->getMTime(), 'perms' => $f->getPerms(), 'owner' => $f->getOwner(), 'group' => $f->getGroup()); } return $files; }
/** * {@inheritdoc} */ public function registerCommands(Application $application) { if (!is_dir($dir = $this->getPath() . '/Command')) { return; } $finder = new Finder(); $finder->files()->name('*Command.php')->in($dir); // Don't enable the generate command when SensioGeneratorBundle is not installed if (!class_exists('Sensio\\Bundle\\GeneratorBundle\\Command\\GenerateBundleCommand')) { $finder->notName('GenerateUserSysCommand.php'); } $prefix = $this->getNamespace() . '\\Command'; foreach ($finder as $file) { $ns = $prefix; if ($relativePath = $file->getRelativePath()) { $ns .= '\\' . strtr($relativePath, '/', '\\'); } $class = $ns . '\\' . $file->getBasename('.php'); $r = new \ReflectionClass($class); if ($r->isSubclassOf('Symfony\\Component\\Console\\Command\\Command') && !$r->isAbstract() && !$r->getConstructor()->getNumberOfRequiredParameters()) { $application->add($r->newInstance()); } } }
/** * @return array|\Iterator */ public function getConfigFiles() { try { $f = new Finder(); $f->name('*.xml.skeleton'); $f->name('*.yml.skeleton'); $f->notName('*.orm.xml.skeleton'); $f->notName('*.orm.yml.skeleton'); $f->notPath('doctrine/'); $f->notPath('serializer/'); $f->in($this->getMappingConfigDirectory()); return $f->getIterator(); } catch (\Exception $e) { return array(); } }
/** * @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(); }
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); }
/** * Lista carpeta y archivos segun el path ingresado, no recursivo, ordenado por tipo y nombre * * @param string $path Ruta de la carpeta o archivo * @return array|null Listado de archivos o null si no existe */ public function getAllFiles($path) { $fullpath = $this->getFullPath() . $path; if (file_exists($fullpath)) { $file = new \SplFileInfo($fullpath); if ($file->isDir()) { $r = array(); // if($path != "/") $r[] = $this->folderParent($path); $finder = new Finder(); $directories = $finder->notName('_thumbs')->notName('web.config')->notName('.htaccess')->depth(0)->sortByType(); // $directories = $directories->files()->name('*.jpg'); $directories = $directories->in($fullpath); foreach ($directories as $key => $directorie) { $namefile = $directorie->getFilename(); if ($directorie->isDir() && $this->validNameFile($namefile, false)) { $t = $this->fileInfo($directorie, $path); if ($t) { $r[] = $t; } } elseif ($directorie->isFile() && $this->validNameFile($namefile)) { $t = $this->fileInfo($directorie, $path); if ($t) { $r[] = $t; } } } return $r; } elseif ($file->isFile()) { $t = $this->fileInfo($file, $path); if ($t) { return $t; } else { $result = array("query" => "BE_GETFILEALL_NOT_LEIBLE", "params" => array()); $this->setInfo(array("msg" => $result)); if ($this->config['debug']) { $this->_log(__METHOD__ . " - Archivo no leible - {$fullpath}"); } return; } } elseif ($file->isLink()) { $result = array("query" => "BE_GETFILEALL_NOT_PERMITIDO", "params" => array()); $this->setInfo(array("msg" => $result)); if ($this->config['debug']) { $this->_log(__METHOD__ . " - path desconocido - {$fullpath}"); } return; } } else { $result = array("query" => "BE_GETFILEALL_NOT_EXISTED", "params" => array()); $this->setInfo(array("msg" => $result)); if ($this->config['debug']) { $this->_log(__METHOD__ . " - No existe el archivo - {$fullpath}"); } return; } }
/** * @param OutputInterface $output * @return void */ protected function cleanCustom(OutputInterface $output) { if (empty($this->options['custom'])) { return; } foreach ($this->options['custom'] as $options) { try { $finder = new Finder(); $finder->ignoreDotFiles(false); $finder->ignoreVCS(false); $finder->ignoreUnreadableDirs(true); $in = []; if (!is_array($options['in'])) { $options['in'] = [$options['in']]; } foreach ($options['in'] as $dir) { $in[] = $this->baseDir . $dir; } $finder->in($in); if (!empty($options['type'])) { switch ($options['type']) { case 'files': $finder->files(); break; case 'dirs': case 'directories': $finder->directories(); break; } } if (!empty($options['notName'])) { if (!is_array($options['notName'])) { $options['notName'] = [$options['notName']]; } foreach ($options['notName'] as $notName) { $finder->notName($notName); } } if (!empty($options['name'])) { if (!is_array($options['name'])) { $options['name'] = [$options['name']]; } foreach ($options['name'] as $notName) { $finder->name($notName); } } if (!empty($options['depth'])) { $finder->depth($options['depth']); } foreach ($finder as $file) { $this->files[] = $file->getRealPath(); } } catch (\Exception $e) { // ignore errors } } }
/** * Find all files to merge. * * @param string $directory * @param array $names * @param array $ignoreNames * * @return Finder */ private function findFiles($directory, array $names, array $ignoreNames) { $finder = new Finder(); $finder->files()->in($directory); foreach ($names as $name) { $finder->name($name); } foreach ($ignoreNames as $name) { $finder->notName($name); } $finder->sortByName(); return $finder; }
/** * Get a list of plugin files. * * @param Finder $finder The finder to use, can be pre-configured * * @return array Of files */ public function getFiles(Finder $finder) { $finder->files()->in($this->directory)->ignoreUnreadableDirs(); // Ignore third party libraries. foreach ($this->getThirdPartyLibraryPaths() as $libPath) { $finder->notPath($libPath); } // Extra ignores for CI. $ignores = $this->getIgnores(); if (!empty($ignores['notPaths'])) { foreach ($ignores['notPaths'] as $notPath) { $finder->notPath($notPath); } } if (!empty($ignores['notNames'])) { foreach ($ignores['notNames'] as $notName) { $finder->notName($notName); } } $files = []; foreach ($finder as $file) { /* @var \SplFileInfo $file */ $files[] = $file->getRealpath(); } return $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); }
/** * 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); } }
/** * @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; }
/** * 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 start() { $paths = $this->_paths; if ($this->_followLinks) { $paths = LinksHelper::followLinks($paths, $this->_excludePatterns); } $this->_fd = inotify_init(); $finder = new Finder(); $finder->directories(); foreach ($this->_excludePatterns as $excludePattern) { $finder->notName($excludePattern); } foreach ($paths as $p) { $finder->in($p); } $this->_watches = array(); foreach ($paths as $p) { $this->_addWatch($p); } foreach ($finder as $f) { $this->_addWatch($f->__toString()); } $this->_logger->info("Watches set up..."); $read = array($this->_fd); $write = null; $except = null; stream_select($read, $write, $except, 0); stream_set_blocking($this->_fd, 0); $events = array(); while (!$this->_stopped) { while ($inotifyEvents = inotify_read($this->_fd)) { foreach ($inotifyEvents as $details) { $file = $this->_watches[$details['wd']]; if ($details['name']) { $file .= '/' . $details['name']; } if ($details['mask'] & IN_MODIFY || $details['mask'] & IN_ATTRIB) { $events[] = new ModifyEvent($file); } if ($details['mask'] & IN_CREATE) { $events[] = new CreateEvent($file); } if ($details['mask'] & IN_DELETE) { $events[] = new DeleteEvent($file); } if ($details['mask'] & IN_MOVED_FROM) { $this->_previousMoveFromFile = $file; } if ($details['mask'] & IN_MOVED_TO) { if (!isset($this->_previousMoveFromFile)) { $this->_logger->error('MOVED_FROM event is not followed by a MOVED_TO'); } else { $events[] = new MoveEvent($this->_previousMoveFromFile, $file); unset($this->_previousMoveFromFile); } } if ($details['mask'] & IN_DELETE_SELF) { unset($this->_watches[$details['wd']]); } } } $events = $this->_compressEvents($events); if ($this->_queueSizeLimit && count($events) > $this->_queueSizeLimit) { $this->_dispatchEvent(QueueFullEvent::NAME, new QueueFullEvent($events)); $events = array(); } foreach ($events as $event) { $name = call_user_func(array(get_class($event), 'getEventName')); $this->_dispatchEvent($name, $event); } usleep(100 * 1000); } foreach ($this->_watches as $wd => $path) { inotify_rm_watch($this->_fd, (int) $wd); } fclose($this->_fd); return; }
/** * 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; }
/** * @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); } foreach ($this->notNames as $notName) { $finder->notName($notName); } if ($iterate) { foreach ($finder as $file) { $files[] = $file->getRealpath(); } } return $files; }
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 Finder */ public function notName($pattern) { return parent::notName($pattern); }