upgraded dependencies
This commit is contained in:
@@ -18,14 +18,16 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
* to remove files.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class CustomFilterIterator extends \FilterIterator
|
||||
{
|
||||
private $filters = [];
|
||||
|
||||
/**
|
||||
* @param \Iterator $iterator The Iterator to filter
|
||||
* @param callable[] $filters An array of PHP callbacks
|
||||
* @param \Iterator<string, \SplFileInfo> $iterator The Iterator to filter
|
||||
* @param callable[] $filters An array of PHP callbacks
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
@@ -44,7 +46,7 @@ class CustomFilterIterator extends \FilterIterator
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool true if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
|
@@ -17,14 +17,16 @@ use Symfony\Component\Finder\Comparator\DateComparator;
|
||||
* DateRangeFilterIterator filters out files that are not in the given date range (last modified dates).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class DateRangeFilterIterator extends \FilterIterator
|
||||
{
|
||||
private $comparators = [];
|
||||
|
||||
/**
|
||||
* @param \Iterator $iterator The Iterator to filter
|
||||
* @param DateComparator[] $comparators An array of DateComparator instances
|
||||
* @param \Iterator<string, \SplFileInfo> $iterator
|
||||
* @param DateComparator[] $comparators
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $comparators)
|
||||
{
|
||||
@@ -36,7 +38,7 @@ class DateRangeFilterIterator extends \FilterIterator
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool true if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
|
@@ -15,15 +15,20 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
* DepthRangeFilterIterator limits the directory depth.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @template-covariant TKey
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @extends \FilterIterator<TKey, TValue>
|
||||
*/
|
||||
class DepthRangeFilterIterator extends \FilterIterator
|
||||
{
|
||||
private $minDepth = 0;
|
||||
|
||||
/**
|
||||
* @param \RecursiveIteratorIterator $iterator The Iterator to filter
|
||||
* @param int $minDepth The min depth
|
||||
* @param int $maxDepth The max depth
|
||||
* @param \RecursiveIteratorIterator<\RecursiveIterator<TKey, TValue>> $iterator The Iterator to filter
|
||||
* @param int $minDepth The min depth
|
||||
* @param int $maxDepth The max depth
|
||||
*/
|
||||
public function __construct(\RecursiveIteratorIterator $iterator, int $minDepth = 0, int $maxDepth = \PHP_INT_MAX)
|
||||
{
|
||||
@@ -36,7 +41,7 @@ class DepthRangeFilterIterator extends \FilterIterator
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool true if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
|
@@ -15,6 +15,9 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
* ExcludeDirectoryFilterIterator filters out directories.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
* @implements \RecursiveIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class ExcludeDirectoryFilterIterator extends \FilterIterator implements \RecursiveIterator
|
||||
{
|
||||
@@ -50,7 +53,7 @@ class ExcludeDirectoryFilterIterator extends \FilterIterator implements \Recursi
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool True if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
|
@@ -15,6 +15,8 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
* FileTypeFilterIterator only keeps files, directories, or both.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class FileTypeFilterIterator extends \FilterIterator
|
||||
{
|
||||
@@ -37,7 +39,7 @@ class FileTypeFilterIterator extends \FilterIterator
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool true if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
|
@@ -16,13 +16,15 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
|
||||
*
|
||||
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class FilecontentFilterIterator extends MultiplePcreFilterIterator
|
||||
{
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool true if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
@@ -50,9 +52,9 @@ class FilecontentFilterIterator extends MultiplePcreFilterIterator
|
||||
*
|
||||
* @param string $str Pattern: string or regexp
|
||||
*
|
||||
* @return string regexp corresponding to a given string or regexp
|
||||
* @return string
|
||||
*/
|
||||
protected function toRegex($str)
|
||||
protected function toRegex(string $str)
|
||||
{
|
||||
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
|
||||
}
|
||||
|
@@ -17,13 +17,15 @@ use Symfony\Component\Finder\Glob;
|
||||
* FilenameFilterIterator filters files by patterns (a regexp, a glob, or a string).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class FilenameFilterIterator extends MultiplePcreFilterIterator
|
||||
{
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool true if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
@@ -39,9 +41,9 @@ class FilenameFilterIterator extends MultiplePcreFilterIterator
|
||||
*
|
||||
* @param string $str Pattern: glob or regexp
|
||||
*
|
||||
* @return string regexp corresponding to a given glob or regexp
|
||||
* @return string
|
||||
*/
|
||||
protected function toRegex($str)
|
||||
protected function toRegex(string $str)
|
||||
{
|
||||
return $this->isRegex($str) ? $str : Glob::toRegex($str);
|
||||
}
|
||||
|
@@ -15,6 +15,11 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
* MultiplePcreFilterIterator filters files using patterns (regexps, globs or strings).
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @template-covariant TKey
|
||||
* @template-covariant TValue
|
||||
*
|
||||
* @extends \FilterIterator<TKey, TValue>
|
||||
*/
|
||||
abstract class MultiplePcreFilterIterator extends \FilterIterator
|
||||
{
|
||||
@@ -23,8 +28,8 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
|
||||
|
||||
/**
|
||||
* @param \Iterator $iterator The Iterator to filter
|
||||
* @param array $matchPatterns An array of patterns that need to match
|
||||
* @param array $noMatchPatterns An array of patterns that need to not match
|
||||
* @param string[] $matchPatterns An array of patterns that need to match
|
||||
* @param string[] $noMatchPatterns An array of patterns that need to not match
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $matchPatterns, array $noMatchPatterns)
|
||||
{
|
||||
@@ -46,11 +51,9 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
|
||||
* Such case can be handled by child classes before calling the method if they want to
|
||||
* apply a different behavior.
|
||||
*
|
||||
* @param string $string The string to be matched against filters
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function isAccepted($string)
|
||||
protected function isAccepted(string $string)
|
||||
{
|
||||
// should at least not match one rule to exclude
|
||||
foreach ($this->noMatchRegexps as $regex) {
|
||||
@@ -77,11 +80,9 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
|
||||
/**
|
||||
* Checks whether the string is a regex.
|
||||
*
|
||||
* @param string $str
|
||||
*
|
||||
* @return bool Whether the given string is a regex
|
||||
* @return bool
|
||||
*/
|
||||
protected function isRegex($str)
|
||||
protected function isRegex(string $str)
|
||||
{
|
||||
$availableModifiers = 'imsxuADU';
|
||||
|
||||
@@ -110,9 +111,7 @@ abstract class MultiplePcreFilterIterator extends \FilterIterator
|
||||
/**
|
||||
* Converts string into regexp.
|
||||
*
|
||||
* @param string $str Pattern
|
||||
*
|
||||
* @return string regexp corresponding to a given string
|
||||
* @return string
|
||||
*/
|
||||
abstract protected function toRegex($str);
|
||||
abstract protected function toRegex(string $str);
|
||||
}
|
||||
|
@@ -16,13 +16,15 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
* @author Włodzimierz Gajda <gajdaw@gajdaw.pl>
|
||||
*
|
||||
* @extends MultiplePcreFilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class PathFilterIterator extends MultiplePcreFilterIterator
|
||||
{
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool true if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
@@ -48,9 +50,9 @@ class PathFilterIterator extends MultiplePcreFilterIterator
|
||||
*
|
||||
* @param string $str Pattern: regexp or dirname
|
||||
*
|
||||
* @return string regexp corresponding to a given string or regexp
|
||||
* @return string
|
||||
*/
|
||||
protected function toRegex($str)
|
||||
protected function toRegex(string $str)
|
||||
{
|
||||
return $this->isRegex($str) ? $str : '/'.preg_quote($str, '/').'/';
|
||||
}
|
||||
|
@@ -56,7 +56,7 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
/**
|
||||
* Return an instance of SplFileInfo with support for relative paths.
|
||||
*
|
||||
* @return SplFileInfo File information
|
||||
* @return SplFileInfo
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function current()
|
||||
@@ -79,7 +79,31 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RecursiveIterator
|
||||
* @param bool $allowLinks
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function hasChildren($allowLinks = false)
|
||||
{
|
||||
$hasChildren = parent::hasChildren($allowLinks);
|
||||
|
||||
if (!$hasChildren || !$this->ignoreUnreadableDirs) {
|
||||
return $hasChildren;
|
||||
}
|
||||
|
||||
try {
|
||||
parent::getChildren();
|
||||
|
||||
return true;
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
// If directory is unreadable and finder is set to ignore it, skip children
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \RecursiveDirectoryIterator
|
||||
*
|
||||
* @throws AccessDeniedException
|
||||
*/
|
||||
@@ -100,12 +124,7 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
|
||||
return $children;
|
||||
} catch (\UnexpectedValueException $e) {
|
||||
if ($this->ignoreUnreadableDirs) {
|
||||
// If directory is unreadable and finder is set to ignore it, a fake empty content is returned.
|
||||
return new \RecursiveArrayIterator([]);
|
||||
} else {
|
||||
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
throw new AccessDeniedException($e->getMessage(), $e->getCode(), $e);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -127,7 +146,7 @@ class RecursiveDirectoryIterator extends \RecursiveDirectoryIterator
|
||||
/**
|
||||
* Checks if the stream is rewindable.
|
||||
*
|
||||
* @return bool true when the stream is rewindable, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
public function isRewindable()
|
||||
{
|
||||
|
@@ -17,14 +17,16 @@ use Symfony\Component\Finder\Comparator\NumberComparator;
|
||||
* SizeRangeFilterIterator filters out files that are not in the given size range.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @extends \FilterIterator<string, \SplFileInfo>
|
||||
*/
|
||||
class SizeRangeFilterIterator extends \FilterIterator
|
||||
{
|
||||
private $comparators = [];
|
||||
|
||||
/**
|
||||
* @param \Iterator $iterator The Iterator to filter
|
||||
* @param NumberComparator[] $comparators An array of NumberComparator instances
|
||||
* @param \Iterator<string, \SplFileInfo> $iterator
|
||||
* @param NumberComparator[] $comparators
|
||||
*/
|
||||
public function __construct(\Iterator $iterator, array $comparators)
|
||||
{
|
||||
@@ -36,7 +38,7 @@ class SizeRangeFilterIterator extends \FilterIterator
|
||||
/**
|
||||
* Filters the iterator values.
|
||||
*
|
||||
* @return bool true if the value should be kept, false otherwise
|
||||
* @return bool
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function accept()
|
||||
|
@@ -15,6 +15,8 @@ namespace Symfony\Component\Finder\Iterator;
|
||||
* SortableIterator applies a sort on a given Iterator.
|
||||
*
|
||||
* @author Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* @implements \IteratorAggregate<string, \SplFileInfo>
|
||||
*/
|
||||
class SortableIterator implements \IteratorAggregate
|
||||
{
|
||||
@@ -30,7 +32,8 @@ class SortableIterator implements \IteratorAggregate
|
||||
private $sort;
|
||||
|
||||
/**
|
||||
* @param int|callable $sort The sort type (SORT_BY_NAME, SORT_BY_TYPE, or a PHP callback)
|
||||
* @param \Traversable<string, \SplFileInfo> $iterator
|
||||
* @param int|callable $sort The sort type (SORT_BY_NAME, SORT_BY_TYPE, or a PHP callback)
|
||||
*
|
||||
* @throws \InvalidArgumentException
|
||||
*/
|
||||
@@ -40,15 +43,15 @@ class SortableIterator implements \IteratorAggregate
|
||||
$order = $reverseOrder ? -1 : 1;
|
||||
|
||||
if (self::SORT_BY_NAME === $sort) {
|
||||
$this->sort = static function ($a, $b) use ($order) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||
};
|
||||
} elseif (self::SORT_BY_NAME_NATURAL === $sort) {
|
||||
$this->sort = static function ($a, $b) use ($order) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * strnatcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||
};
|
||||
} elseif (self::SORT_BY_TYPE === $sort) {
|
||||
$this->sort = static function ($a, $b) use ($order) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
if ($a->isDir() && $b->isFile()) {
|
||||
return -$order;
|
||||
} elseif ($a->isFile() && $b->isDir()) {
|
||||
@@ -58,28 +61,28 @@ class SortableIterator implements \IteratorAggregate
|
||||
return $order * strcmp($a->getRealPath() ?: $a->getPathname(), $b->getRealPath() ?: $b->getPathname());
|
||||
};
|
||||
} elseif (self::SORT_BY_ACCESSED_TIME === $sort) {
|
||||
$this->sort = static function ($a, $b) use ($order) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * ($a->getATime() - $b->getATime());
|
||||
};
|
||||
} elseif (self::SORT_BY_CHANGED_TIME === $sort) {
|
||||
$this->sort = static function ($a, $b) use ($order) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * ($a->getCTime() - $b->getCTime());
|
||||
};
|
||||
} elseif (self::SORT_BY_MODIFIED_TIME === $sort) {
|
||||
$this->sort = static function ($a, $b) use ($order) {
|
||||
$this->sort = static function (\SplFileInfo $a, \SplFileInfo $b) use ($order) {
|
||||
return $order * ($a->getMTime() - $b->getMTime());
|
||||
};
|
||||
} elseif (self::SORT_BY_NONE === $sort) {
|
||||
$this->sort = $order;
|
||||
} elseif (\is_callable($sort)) {
|
||||
$this->sort = $reverseOrder ? static function ($a, $b) use ($sort) { return -$sort($a, $b); } : $sort;
|
||||
$this->sort = $reverseOrder ? static function (\SplFileInfo $a, \SplFileInfo $b) use ($sort) { return -$sort($a, $b); } : $sort;
|
||||
} else {
|
||||
throw new \InvalidArgumentException('The SortableIterator takes a PHP callable or a valid built-in sort algorithm as an argument.');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \Traversable
|
||||
* @return \Traversable<string, \SplFileInfo>
|
||||
*/
|
||||
#[\ReturnTypeWillChange]
|
||||
public function getIterator()
|
||||
|
151
vendor/symfony/finder/Iterator/VcsIgnoredFilterIterator.php
vendored
Normal file
151
vendor/symfony/finder/Iterator/VcsIgnoredFilterIterator.php
vendored
Normal file
@@ -0,0 +1,151 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* This file is part of the Symfony package.
|
||||
*
|
||||
* (c) Fabien Potencier <fabien@symfony.com>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
|
||||
namespace Symfony\Component\Finder\Iterator;
|
||||
|
||||
use Symfony\Component\Finder\Gitignore;
|
||||
|
||||
final class VcsIgnoredFilterIterator extends \FilterIterator
|
||||
{
|
||||
/**
|
||||
* @var string
|
||||
*/
|
||||
private $baseDir;
|
||||
|
||||
/**
|
||||
* @var array<string, array{0: string, 1: string}|null>
|
||||
*/
|
||||
private $gitignoreFilesCache = [];
|
||||
|
||||
/**
|
||||
* @var array<string, bool>
|
||||
*/
|
||||
private $ignoredPathsCache = [];
|
||||
|
||||
public function __construct(\Iterator $iterator, string $baseDir)
|
||||
{
|
||||
$this->baseDir = $this->normalizePath($baseDir);
|
||||
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
|
||||
public function accept(): bool
|
||||
{
|
||||
$file = $this->current();
|
||||
|
||||
$fileRealPath = $this->normalizePath($file->getRealPath());
|
||||
|
||||
return !$this->isIgnored($fileRealPath);
|
||||
}
|
||||
|
||||
private function isIgnored(string $fileRealPath): bool
|
||||
{
|
||||
if (is_dir($fileRealPath) && !str_ends_with($fileRealPath, '/')) {
|
||||
$fileRealPath .= '/';
|
||||
}
|
||||
|
||||
if (isset($this->ignoredPathsCache[$fileRealPath])) {
|
||||
return $this->ignoredPathsCache[$fileRealPath];
|
||||
}
|
||||
|
||||
$ignored = false;
|
||||
|
||||
foreach ($this->parentsDirectoryDownward($fileRealPath) as $parentDirectory) {
|
||||
if ($this->isIgnored($parentDirectory)) {
|
||||
// rules in ignored directories are ignored, no need to check further.
|
||||
break;
|
||||
}
|
||||
|
||||
$fileRelativePath = substr($fileRealPath, \strlen($parentDirectory) + 1);
|
||||
|
||||
if (null === $regexps = $this->readGitignoreFile("{$parentDirectory}/.gitignore")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
[$exclusionRegex, $inclusionRegex] = $regexps;
|
||||
|
||||
if (preg_match($exclusionRegex, $fileRelativePath)) {
|
||||
$ignored = true;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
if (preg_match($inclusionRegex, $fileRelativePath)) {
|
||||
$ignored = false;
|
||||
}
|
||||
}
|
||||
|
||||
return $this->ignoredPathsCache[$fileRealPath] = $ignored;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<string>
|
||||
*/
|
||||
private function parentsDirectoryDownward(string $fileRealPath): array
|
||||
{
|
||||
$parentDirectories = [];
|
||||
|
||||
$parentDirectory = $fileRealPath;
|
||||
|
||||
while (true) {
|
||||
$newParentDirectory = \dirname($parentDirectory);
|
||||
|
||||
// dirname('/') = '/'
|
||||
if ($newParentDirectory === $parentDirectory) {
|
||||
break;
|
||||
}
|
||||
|
||||
$parentDirectory = $newParentDirectory;
|
||||
|
||||
if (0 !== strpos($parentDirectory, $this->baseDir)) {
|
||||
break;
|
||||
}
|
||||
|
||||
$parentDirectories[] = $parentDirectory;
|
||||
}
|
||||
|
||||
return array_reverse($parentDirectories);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{0: string, 1: string}|null
|
||||
*/
|
||||
private function readGitignoreFile(string $path): ?array
|
||||
{
|
||||
if (\array_key_exists($path, $this->gitignoreFilesCache)) {
|
||||
return $this->gitignoreFilesCache[$path];
|
||||
}
|
||||
|
||||
if (!file_exists($path)) {
|
||||
return $this->gitignoreFilesCache[$path] = null;
|
||||
}
|
||||
|
||||
if (!is_file($path) || !is_readable($path)) {
|
||||
throw new \RuntimeException("The \"ignoreVCSIgnored\" option cannot be used by the Finder as the \"{$path}\" file is not readable.");
|
||||
}
|
||||
|
||||
$gitignoreFileContent = file_get_contents($path);
|
||||
|
||||
return $this->gitignoreFilesCache[$path] = [
|
||||
Gitignore::toRegex($gitignoreFileContent),
|
||||
Gitignore::toRegexMatchingNegatedPatterns($gitignoreFileContent),
|
||||
];
|
||||
}
|
||||
|
||||
private function normalizePath(string $path): string
|
||||
{
|
||||
if ('\\' === \DIRECTORY_SEPARATOR) {
|
||||
return str_replace('\\', '/', $path);
|
||||
}
|
||||
|
||||
return $path;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user