本文整理汇总了PHP中Symfony\Component\Finder\Finder::ignoreDotFiles方法的典型用法代码示例。如果您正苦于以下问题:PHP Finder::ignoreDotFiles方法的具体用法?PHP Finder::ignoreDotFiles怎么用?PHP Finder::ignoreDotFiles使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\Finder\Finder
的用法示例。
在下文中一共展示了Finder::ignoreDotFiles方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: getSpool
/**
* @return Finder
*/
protected function getSpool()
{
$filesystem = new Filesystem();
$finder = new Finder();
if ($filesystem->exists($this->spoolDir)) {
$spool = $finder->ignoreDotFiles(true)->in($this->spoolDir)->files();
return $spool;
}
throw new \RuntimeException("Spool not found or empty: " . $this->spoolDir);
}
示例2: getFinder
/**
*
* @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;
}
示例3: testClear
public function testClear()
{
file_put_contents($this->app['config']['root_dir'] . '/app/cache/.dummykeep', 'test');
// 'doctrine', 'profiler', 'twig' ディレクトリを削除
Cache::clear($this->app, false);
$finder = new Finder();
$iterator = $finder->ignoreDotFiles(false)->in($this->app['config']['root_dir'] . '/app/cache')->files();
foreach ($iterator as $fileinfo) {
$this->assertStringEndsWith('keep', $fileinfo->getPathname(), 'keep しか存在しないはず');
}
$this->assertTrue($this->root->hasChild('app/cache/.gitkeep'), '.gitkeep は存在するはず');
$this->assertTrue($this->root->hasChild('app/cache/.dummykeep'), '.dummykeep は存在するはず');
}
示例4: 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());
}
示例5: cleanCustom
/**
* @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
}
}
}
示例6: testIgnoreDotFiles
public function testIgnoreDotFiles()
{
$finder = new Finder();
$this->assertSame($finder, $finder->ignoreDotFiles(false)->ignoreVCS(false));
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
$finder = new Finder();
$finder->ignoreDotFiles(false)->ignoreDotFiles(false)->ignoreVCS(false);
$this->assertIterator($this->toAbsolute(array('.git', '.bar', '.foo', '.foo/.bar', 'foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
$finder = new Finder();
$this->assertSame($finder, $finder->ignoreDotFiles(true)->ignoreVCS(false));
$this->assertIterator($this->toAbsolute(array('foo', 'foo/bar.tmp', 'test.php', 'test.py', 'toto')), $finder->in(self::$tmpDir)->getIterator());
}
示例7: recursive_filesize_scanner
/**
* Recursively scans a directory to calculate the total filesize
*
* Locks should be set by the caller with `set_transient( 'hmbkp_directory_filesizes_running', true, HOUR_IN_SECONDS );`
*
* @return array $directory_sizes An array of directory paths => filesize sum of all files in directory
*/
public function recursive_filesize_scanner()
{
/**
* Raise the `memory_limit` and `max_execution time`
*
* Respects the WP_MAX_MEMORY_LIMIT Constant and the `admin_memory_limit`
* filter.
*/
@ini_set('memory_limit', apply_filters('admin_memory_limit', WP_MAX_MEMORY_LIMIT));
@set_time_limit(0);
// Use the cached array directory sizes if available
$directory_sizes = $this->get_cached_filesizes();
// If we do have it in cache then let's use it and also clear the lock
if (is_array($directory_sizes)) {
delete_transient('hmbkp_directory_filesizes_running');
return $directory_sizes;
}
// If we don't have it cached then we'll need to re-calculate
$finder = new Finder();
$finder->followLinks();
$finder->ignoreDotFiles(false);
$finder->ignoreUnreadableDirs(true);
$files = $finder->in(Path::get_root());
foreach ($files as $file) {
if ($file->isReadable()) {
$directory_sizes[wp_normalize_path($file->getRealpath())] = $file->getSize();
} else {
$directory_sizes[wp_normalize_path($file->getRealpath())] = 0;
}
}
file_put_contents(PATH::get_path() . '/.files', gzcompress(json_encode($directory_sizes)));
// Remove the lock
delete_transient('hmbkp_directory_filesizes_running');
return $directory_sizes;
}
示例8: __construct
/**
* LegacyRouteLoader constructor.
*
* @param string $legacyPath
*
* @throws \InvalidArgumentException
*/
public function __construct($legacyPath, Finder $finder = null)
{
$this->finder = $finder ?: new Finder();
$this->finder->ignoreDotFiles(true)->files()->name('*.php')->in($legacyPath);
}
示例9: getFinder
/**
*
* @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;
}
示例10: includeDotFiles
/**
* @param bool $includeDotFiles
* @return $this
*/
public function includeDotFiles($includeDotFiles = true)
{
$this->finder->ignoreDotFiles(!$includeDotFiles);
return $this;
}
示例11: loadFiles
/**
* Load all files from the extension.
*/
private function loadFiles()
{
$finder = new Finder();
$iterator = $finder->ignoreDotFiles(false)->files()->sortByName()->ignoreVCS(true)->exclude('vendor')->exclude('tests')->exclude('travis')->in($this->directory);
$loader = new FileLoader($this->output, $this->debug, $this->basedir, $this->directory);
foreach ($iterator as $file) {
/** @var \Symfony\Component\Finder\SplFileInfo $file */
if (!$file->getRealPath()) {
$this->output->write("<info>Finder found a file, but it does not seem to be readable or does not actually exist.</info>");
continue;
}
$loadedFile = $loader->loadFile($file->getRealPath());
if ($loadedFile != null) {
$this->files[] = $loadedFile;
$this->dirList[] = $file->getRealPath();
} else {
$this->output->addMessage(Output::FATAL, "Unable to load file: " . $file->getRealPath());
}
}
}
示例12: listDirectory
/**
* @param DirectoryPath $relativeDirectoryPath
*
* @return DirectoryListing
*/
public function listDirectory(DirectoryPath $relativeDirectoryPath)
{
$repositoryPath = $this->gitRepository->getRepositoryPath();
/* @var PageFile[] $pages */
$pages = array();
/* @var Directory[] $subDirectories */
$subDirectories = array();
/* @var \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File[] $otherFiles */
$otherFiles = array();
$finder = new Finder();
$finder->in($this->gitRepository->getAbsolutePathString($relativeDirectoryPath));
$finder->depth(0);
foreach ($finder->files() as $file) {
/* @var \Symfony\Component\Finder\SplFileInfo $file */
if ($file->getExtension() == "md") {
$pages[] = $this->createPageFile($repositoryPath, $relativeDirectoryPath, $file);
} else {
if ($file->getExtension() != 'lock') {
$otherFile = new \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File($repositoryPath->toAbsoluteFileString(), $relativeDirectoryPath->toRelativeFileString(), $file->getRelativePathName());
$otherFiles[] = $otherFile;
}
}
}
$finder = new Finder();
$finder->in($this->gitRepository->getAbsolutePathString($relativeDirectoryPath));
$finder->depth(0);
$finder->ignoreDotFiles(true);
foreach ($finder->directories() as $directory) {
/* @var \Symfony\Component\Finder\SplFileInfo $directory */
$subDirectory = new Directory($repositoryPath->toAbsoluteFileString(), $relativeDirectoryPath->toRelativeFileString(), $directory->getRelativePathName() . DIRECTORY_SEPARATOR);
$subDirectories[] = $subDirectory;
}
usort($pages, function (PageFile $a, PageFile $b) {
return strcmp($a->getTitle(), $b->getTitle());
});
usort($subDirectories, function (Directory $a, Directory $b) {
return strcmp($a->getFilename(), $b->getFilename());
});
usort($otherFiles, function (\Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File $a, \Net\Dontdrinkandroot\Gitki\BaseBundle\Model\FileInfo\File $b) {
return strcmp($a->getFilename(), $b->getFilename());
});
return new DirectoryListing($relativeDirectoryPath, $pages, $subDirectories, $otherFiles);
}
示例13: scanFolders
private function scanFolders($path, $parent)
{
$finder = new Finder();
$finder->in($path);
$finder->directories();
$finder->ignoreDotFiles(true);
$finder->depth(0);
$finder->sortByName();
foreach ($finder as $entity) {
/* @var $entity SplFileInfo */
$name = $entity->getFilename();
// Skip items starting with underscore
if (preg_match('~^_~', $name)) {
continue;
}
// Skip items starting with dot
if (preg_match('~^\\.~', $name)) {
continue;
}
$this->scanFiles($entity->getPathname(), $parent);
}
}
示例14: ignoreDotFiles
/**
* @return Finder
*/
public function ignoreDotFiles($ignoreDotFiles)
{
return parent::ignoreDotFiles($ignoreDotFiles);
}
示例15: list_directory_by_total_filesize
/**
* Return the single depth list of files and subdirectories in $directory ordered by total filesize
*
* Will schedule background threads to recursively calculate the filesize of subdirectories.
* The total filesize of each directory and subdirectory is cached in a transient for 1 week.
*
* @param string $directory The directory to scan
*
* @return array returns an array of files ordered by filesize
*/
public function list_directory_by_total_filesize($directory)
{
$files = $files_with_no_size = $empty_files = $files_with_size = $unreadable_files = array();
if (!is_dir($directory)) {
return $files;
}
$found = array();
if (!empty($this->files)) {
return $this->files;
}
$default_excludes = $this->backup->default_excludes();
$finder = new Finder();
$finder->ignoreDotFiles(false);
$finder->ignoreUnreadableDirs();
$finder->followLinks();
$finder->depth('== 0');
foreach ($default_excludes as $exclude) {
$finder->notPath($exclude);
}
foreach ($finder->in($directory) as $entry) {
$files[] = $entry;
// Get the total filesize for each file and directory
$filesize = $this->filesize($entry);
if ($filesize) {
// If there is already a file with exactly the same filesize then let's keep increasing the filesize of this one until we don't have a clash
while (array_key_exists($filesize, $files_with_size)) {
$filesize++;
}
$files_with_size[$filesize] = $entry;
} elseif (0 === $filesize) {
$empty_files[] = $entry;
} else {
$files_with_no_size[] = $entry;
}
}
// Add 0 byte files / directories to the bottom
$files = $files_with_size + array_merge($empty_files, $unreadable_files);
// Add directories that are still calculating to the top
if ($files_with_no_size) {
// We have to loop as merging or concatenating the array would re-flow the keys which we don't want because the filesize is stored in the key
foreach ($files_with_no_size as $entry) {
array_unshift($files, $entry);
}
}
return $files;
}