本文整理汇总了PHP中Symfony\Component\Finder\Finder::filter方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::filter方法的具体用法?PHP Finder::filter怎么用?PHP Finder::filter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::filter方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln('Sync our local folder with the S3 Bucket...');
$sync = $this->getApplication()->make('operations.s3-sync');
$sync->sync();
$output->writeln('Getting the list of files to be processed...');
$finder = new Finder();
$finder->files('*.json')->in($this->directories['files_dir'])->sort(function ($a, $b) {
return strnatcmp($a->getRealPath(), $b->getRealPath());
});
if (file_exists($this->directories['last_read_file'])) {
$lastFile = file_get_contents($this->directories['last_read_file']);
$finder->filter(function ($file) use($lastFile) {
if (0 >= strnatcmp($file->getFilename(), $lastFile)) {
return false;
}
return true;
});
}
$importer = $this->getApplication()->make('operations.file-importer');
foreach ($finder as $file) {
$output->writeln('Processing the events from ' . $file->getFilename() . '...');
$importer->from($file);
file_put_contents($this->directories['last_read_file'], $file->getFilename());
}
}
示例2: filter
/**
* {@inheritDoc}
*
* @param callable $callable
*
* @return self
*
* @throws \InvalidArgumentException When the $callable isn't a callable
*/
public function filter($callable)
{
if (!is_callable($callable)) {
throw new \InvalidArgumentException('The filter should be a PHP callable');
}
parent::filter(function (\SplFileInfo $file) use($callable) {
return call_user_func_array($callable, array($file));
});
return $this;
}
示例3: getFinderObject
protected function getFinderObject($isLibrary, $dirs)
{
foreach ($dirs as $id => $dir) {
$dirs[$id] = $this->getPath($dir);
}
$finder = new Finder();
$finder->files()->name("*.php")->in($dirs);
if ($isLibrary) {
$relative = true;
$include = false;
$finder->filter(function ($file) {
return preg_match("/test/i", $file) ? false : true;
});
}
return $finder;
}
示例4: getConfigFinder
/**
* @param array $directoriesWhiteList
* @return Finder
*/
protected function getConfigFinder(array $directoriesWhiteList = array())
{
$configDirectories = $this->getConfigDirectories($directoriesWhiteList);
// prepare finder
$finder = new Finder();
$finder->in($configDirectories)->name($this->getConfigFilePattern());
if ($directoriesWhiteList) {
$finder->filter(function ($file) use($directoriesWhiteList) {
foreach ($directoriesWhiteList as $allowedDirectory) {
if ($allowedDirectory && strpos($file, realpath($allowedDirectory) . DIRECTORY_SEPARATOR) === 0) {
return true;
}
}
return false;
});
}
return $finder;
}
示例5: get_files
/**
* Returns a Finder instance for the files that will be included in the
* backup.
*
* By default we ignore unreadable files and directories as well as, common
* version control folders / files, "Dot" files and anything matching the
* exclude rules.
*
* @uses Finder
* @return Finder The Finder iterator of all files to be included
*/
public function get_files()
{
$finder = new Finder();
$finder->followLinks(true);
$finder->ignoreDotFiles(false);
$finder->ignoreVCS(true);
$finder->ignoreUnreadableDirs(true);
// Skip unreadable files too
$finder->filter(function (\SplFileInfo $file) {
if (!$file->isReadable()) {
return false;
}
});
// Finder expects exclude rules to be in a regex format
$exclude_rules = $this->excludes->get_excludes_for_regex();
// Skips folders/files that match default exclude patterns
foreach ($exclude_rules as $exclude) {
$finder->notPath($exclude);
}
return $finder->in(Path::get_root());
}
示例6: scanRecursive
/**
* Scans the directory for files and directories recursively.
*
* @param mixed $filter Array of methods to arguments for `Finder`,
* \Closure instance for filter, strings 'directories' or 'files',
* regular expression, or glob string.
*
* @return array Array of `File` and `Directory` objects.
*
* @see Finder
*
* @replaces #scanRecursive
*/
public function scanRecursive($filter = null)
{
$this->tossIfDeleted();
$objects = array();
$finder = new Finder();
$finder->in($this->directory)->ignoreDotFiles(false)->ignoreVCS(false);
if ($filter) {
if (is_array($filter)) {
foreach ($filter as $method => $arg) {
if (!isset(static::$allowedFinderMethodsForFilter[$method])) {
continue;
}
$finder->{$method}($arg);
}
} else {
if ($filter instanceof \Closure) {
$finder->filter($filter);
} else {
if ($filter === 'directories') {
$finder->directories();
} else {
if ($filter === 'files') {
$finder->files();
} else {
$finder->name($filter);
}
}
}
}
}
foreach ($finder as $file) {
$objects[] = static::$fs->createObject($file);
}
return $objects;
}
示例7: readDir
/**
* Returns directory contents
*
* @param string $dir
* @param mixed $names
* @param mixed $notNames
* @param boolean $dirs
* @param boolean $files
* @param integer $sort
* @return array
*/
public static function readDir($dir, $names = '*', $notNames = false, $dirs = true, $files = true, $sort = SORT_DESC)
{
$found = array();
$finder = new Finder();
$dir = str_replace('/', DIRECTORY_SEPARATOR, $dir);
if ($dirs && !$files) {
$finder->directories();
} elseif (!$dirs && $files) {
$finder->files();
}
foreach ((array) $names as $name) {
$finder->name($name);
}
if ($notNames !== false) {
$regExps = array();
foreach ((array) $notNames as $notName) {
$regExps[] = Glob::toRegex($notName, false, false);
}
$finder->filter(function (\SplFileInfo $fileinfo) use($dir, $regExps) {
$localName = str_replace(array($dir . DIRECTORY_SEPARATOR, DIRECTORY_SEPARATOR), array(NULL, '/'), $fileinfo->getRealpath());
foreach ($regExps as $regExp) {
if (preg_match($regExp, $localName)) {
return false;
}
}
return true;
});
}
foreach ($finder->in($dir) as $path) {
$found[] = realpath($path->getRealpath());
}
return self::sortByDepth($found, $sort);
}
示例8: filter
/**
* @return Finder
*/
public function filter(Closure $closure)
{
return parent::filter($closure);
}