change gitignore
This commit is contained in:
+160
@@ -0,0 +1,160 @@
|
||||
# Change Log
|
||||
|
||||
All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [4.0.1] - 2023-02-10
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#67](https://github.com/sebastianbergmann/php-file-iterator/issues/61): Excluded directories are traversed unnecessarily
|
||||
|
||||
## [4.0.0] - 2023-02-03
|
||||
|
||||
### Removed
|
||||
|
||||
* The optional `$commonPath` parameter of `SebastianBergmann\FileIterator\Facade` as well as the functionality it controlled has been removed
|
||||
* The `SebastianBergmann\FileIterator\Factory` and `SebastianBergmann\FileIterator\Iterator` classes are now marked `@internal`
|
||||
* This component is no longer supported on PHP 7.3, PHP 7.4 and PHP 8.0
|
||||
|
||||
## [3.0.6] - 2021-12-02
|
||||
|
||||
### Changed
|
||||
|
||||
* [#73](https://github.com/sebastianbergmann/php-file-iterator/pull/73): Micro performance improvements on parsing paths
|
||||
|
||||
## [3.0.5] - 2020-09-28
|
||||
|
||||
### Changed
|
||||
|
||||
* Changed PHP version constraint in `composer.json` from `^7.3 || ^8.0` to `>=7.3`
|
||||
|
||||
## [3.0.4] - 2020-07-11
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#67](https://github.com/sebastianbergmann/php-file-iterator/issues/67): `TypeError` in `SebastianBergmann\FileIterator\Iterator::accept()`
|
||||
|
||||
## [3.0.3] - 2020-06-26
|
||||
|
||||
### Added
|
||||
|
||||
* This component is now supported on PHP 8
|
||||
|
||||
## [3.0.2] - 2020-06-15
|
||||
|
||||
### Changed
|
||||
|
||||
* Tests etc. are now ignored for archive exports
|
||||
|
||||
## [3.0.1] - 2020-04-18
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#64](https://github.com/sebastianbergmann/php-file-iterator/issues/64): Release tarball contains Composer PHAR
|
||||
|
||||
## [3.0.0] - 2020-02-07
|
||||
|
||||
### Removed
|
||||
|
||||
* This component is no longer supported on PHP 7.1 and PHP 7.2
|
||||
|
||||
## [2.0.5] - 2021-12-02
|
||||
|
||||
### Changed
|
||||
|
||||
* [#73](https://github.com/sebastianbergmann/php-file-iterator/pull/73): Micro performance improvements on parsing paths
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#74](https://github.com/sebastianbergmann/php-file-iterator/pull/74): Document return type of `SebastianBergmann\FileIterator\Iterator::accept()` so that Symfony's `DebugClassLoader` does not trigger a deprecation warning
|
||||
|
||||
## [2.0.4] - 2021-07-19
|
||||
|
||||
### Changed
|
||||
|
||||
* Added `ReturnTypeWillChange` attribute to `SebastianBergmann\FileIterator\Iterator::accept()` because the return type of `\FilterIterator::accept()` will change in PHP 8.1
|
||||
|
||||
## [2.0.3] - 2020-11-30
|
||||
|
||||
### Changed
|
||||
|
||||
* Changed PHP version constraint in `composer.json` from `^7.1` to `>=7.1`
|
||||
|
||||
## [2.0.2] - 2018-09-13
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#48](https://github.com/sebastianbergmann/php-file-iterator/issues/48): Excluding an array that contains false ends up excluding the current working directory
|
||||
|
||||
## [2.0.1] - 2018-06-11
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#46](https://github.com/sebastianbergmann/php-file-iterator/issues/46): Regression with hidden parent directory
|
||||
|
||||
## [2.0.0] - 2018-05-28
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#30](https://github.com/sebastianbergmann/php-file-iterator/issues/30): Exclude is not considered if it is a parent of the base path
|
||||
|
||||
### Changed
|
||||
|
||||
* This component now uses namespaces
|
||||
|
||||
### Removed
|
||||
|
||||
* This component is no longer supported on PHP 5.3, PHP 5.4, PHP 5.5, PHP 5.6, and PHP 7.0
|
||||
|
||||
## [1.4.5] - 2017-11-27
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#37](https://github.com/sebastianbergmann/php-file-iterator/issues/37): Regression caused by fix for [#30](https://github.com/sebastianbergmann/php-file-iterator/issues/30)
|
||||
|
||||
## [1.4.4] - 2017-11-27
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#30](https://github.com/sebastianbergmann/php-file-iterator/issues/30): Exclude is not considered if it is a parent of the base path
|
||||
|
||||
## [1.4.3] - 2017-11-25
|
||||
|
||||
### Fixed
|
||||
|
||||
* [#34](https://github.com/sebastianbergmann/php-file-iterator/issues/34): Factory should use canonical directory names
|
||||
|
||||
## [1.4.2] - 2016-11-26
|
||||
|
||||
No changes
|
||||
|
||||
## [1.4.1] - 2015-07-26
|
||||
|
||||
No changes
|
||||
|
||||
## 1.4.0 - 2015-04-02
|
||||
|
||||
### Added
|
||||
|
||||
* [#23](https://github.com/sebastianbergmann/php-file-iterator/pull/23): Added support for wildcards (glob) in exclude
|
||||
|
||||
[4.0.1]: https://github.com/sebastianbergmann/php-file-iterator/compare/4.0.0...4.0.1
|
||||
[4.0.0]: https://github.com/sebastianbergmann/php-file-iterator/compare/3.0.6...4.0.0
|
||||
[3.0.6]: https://github.com/sebastianbergmann/php-file-iterator/compare/3.0.5...3.0.6
|
||||
[3.0.5]: https://github.com/sebastianbergmann/php-file-iterator/compare/3.0.4...3.0.5
|
||||
[3.0.4]: https://github.com/sebastianbergmann/php-file-iterator/compare/3.0.3...3.0.4
|
||||
[3.0.3]: https://github.com/sebastianbergmann/php-file-iterator/compare/3.0.2...3.0.3
|
||||
[3.0.2]: https://github.com/sebastianbergmann/php-file-iterator/compare/3.0.1...3.0.2
|
||||
[3.0.1]: https://github.com/sebastianbergmann/php-file-iterator/compare/3.0.0...3.0.1
|
||||
[3.0.0]: https://github.com/sebastianbergmann/php-file-iterator/compare/2.0.5...3.0.0
|
||||
[2.0.5]: https://github.com/sebastianbergmann/php-file-iterator/compare/2.0.4...2.0.5
|
||||
[2.0.4]: https://github.com/sebastianbergmann/php-file-iterator/compare/2.0.3...2.0.4
|
||||
[2.0.3]: https://github.com/sebastianbergmann/php-file-iterator/compare/2.0.2...2.0.3
|
||||
[2.0.2]: https://github.com/sebastianbergmann/php-file-iterator/compare/2.0.1...2.0.2
|
||||
[2.0.1]: https://github.com/sebastianbergmann/php-file-iterator/compare/2.0.0...2.0.1
|
||||
[2.0.0]: https://github.com/sebastianbergmann/php-file-iterator/compare/1.4.5...2.0.0
|
||||
[1.4.5]: https://github.com/sebastianbergmann/php-file-iterator/compare/1.4.4...1.4.5
|
||||
[1.4.4]: https://github.com/sebastianbergmann/php-file-iterator/compare/1.4.3...1.4.4
|
||||
[1.4.3]: https://github.com/sebastianbergmann/php-file-iterator/compare/1.4.2...1.4.3
|
||||
[1.4.2]: https://github.com/sebastianbergmann/php-file-iterator/compare/1.4.1...1.4.2
|
||||
[1.4.1]: https://github.com/sebastianbergmann/php-file-iterator/compare/1.4.0...1.4.1
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
BSD 3-Clause License
|
||||
|
||||
Copyright (c) 2009-2023, Sebastian Bergmann
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
1. Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
3. Neither the name of the copyright holder nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
+17
@@ -0,0 +1,17 @@
|
||||
[](https://packagist.org/packages/phpunit/php-file-iterator)
|
||||
[](https://github.com/sebastianbergmann/php-file-iterator/actions)
|
||||
[](https://shepherd.dev/github/sebastianbergmann/php-file-iterator)
|
||||
[](https://codecov.io/gh/sebastianbergmann/php-file-iterator)
|
||||
|
||||
# php-file-iterator
|
||||
|
||||
## Installation
|
||||
|
||||
You can add this library as a local, per-project dependency to your project using [Composer](https://getcomposer.org/):
|
||||
|
||||
composer require phpunit/php-file-iterator
|
||||
|
||||
If you only need this library during development, for instance to run your project's test suite, then you should add it as a development-time dependency:
|
||||
|
||||
composer require --dev phpunit/php-file-iterator
|
||||
|
||||
+30
@@ -0,0 +1,30 @@
|
||||
# Security Policy
|
||||
|
||||
If you believe you have found a security vulnerability in the library that is developed in this repository, please report it to us through coordinated disclosure.
|
||||
|
||||
**Please do not report security vulnerabilities through public GitHub issues, discussions, or pull requests.**
|
||||
|
||||
Instead, please send an email to `sebastian@phpunit.de`.
|
||||
|
||||
Please include as much of the information listed below as you can to help us better understand and resolve the issue:
|
||||
|
||||
* The type of issue
|
||||
* Full paths of source file(s) related to the manifestation of the issue
|
||||
* The location of the affected source code (tag/branch/commit or direct URL)
|
||||
* Any special configuration required to reproduce the issue
|
||||
* Step-by-step instructions to reproduce the issue
|
||||
* Proof-of-concept or exploit code (if possible)
|
||||
* Impact of the issue, including how an attacker might exploit the issue
|
||||
|
||||
This information will help us triage your report more quickly.
|
||||
|
||||
## Web Context
|
||||
|
||||
The library that is developed in this repository was either extracted from [PHPUnit](https://github.com/sebastianbergmann/phpunit) or developed specifically as a dependency for PHPUnit.
|
||||
|
||||
The library is developed with a focus on development environments and the command-line. No specific testing or hardening with regard to using the library in a HTTP or web context or with untrusted input data is performed. The library might also contain functionality that intentionally exposes internal application data for debugging purposes.
|
||||
|
||||
If the library is used in a web application, the application developer is responsible for filtering inputs or escaping outputs as necessary and for verifying that the used functionality is safe for use within the intended context.
|
||||
|
||||
Vulnerabilities specific to the use outside of a development context will be fixed as applicable, provided that the fix does not have an averse effect on the primary use case for development purposes.
|
||||
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
{
|
||||
"name": "phpunit/php-file-iterator",
|
||||
"description": "FilterIterator implementation that filters files based on a list of suffixes.",
|
||||
"type": "library",
|
||||
"keywords": [
|
||||
"iterator",
|
||||
"filesystem"
|
||||
],
|
||||
"homepage": "https://github.com/sebastianbergmann/php-file-iterator/",
|
||||
"license": "BSD-3-Clause",
|
||||
"authors": [
|
||||
{
|
||||
"name": "Sebastian Bergmann",
|
||||
"email": "sebastian@phpunit.de",
|
||||
"role": "lead"
|
||||
}
|
||||
],
|
||||
"support": {
|
||||
"issues": "https://github.com/sebastianbergmann/php-file-iterator/issues"
|
||||
},
|
||||
"config": {
|
||||
"platform": {
|
||||
"php": "8.1.0"
|
||||
},
|
||||
"optimize-autoloader": true,
|
||||
"sort-packages": true
|
||||
},
|
||||
"prefer-stable": true,
|
||||
"require": {
|
||||
"php": ">=8.1"
|
||||
},
|
||||
"require-dev": {
|
||||
"phpunit/phpunit": "^10.0"
|
||||
},
|
||||
"autoload": {
|
||||
"classmap": [
|
||||
"src/"
|
||||
]
|
||||
},
|
||||
"extra": {
|
||||
"branch-alias": {
|
||||
"dev-main": "4.0-dev"
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-file-iterator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\FileIterator;
|
||||
|
||||
use function assert;
|
||||
use function str_starts_with;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveFilterIterator;
|
||||
use SplFileInfo;
|
||||
|
||||
/**
|
||||
* @internal This class is not covered by the backward compatibility promise for phpunit/php-file-iterator
|
||||
*/
|
||||
final class ExcludeIterator extends RecursiveFilterIterator
|
||||
{
|
||||
/**
|
||||
* @psalm-var list<string>
|
||||
*/
|
||||
private array $exclude;
|
||||
|
||||
/**
|
||||
* @psalm-param list<string> $exclude
|
||||
*/
|
||||
public function __construct(RecursiveDirectoryIterator $iterator, array $exclude)
|
||||
{
|
||||
parent::__construct($iterator);
|
||||
|
||||
$this->exclude = $exclude;
|
||||
}
|
||||
|
||||
public function accept(): bool
|
||||
{
|
||||
$current = $this->current();
|
||||
|
||||
assert($current instanceof SplFileInfo);
|
||||
|
||||
$path = $current->getRealPath();
|
||||
|
||||
foreach ($this->exclude as $exclude) {
|
||||
if (str_starts_with($path, $exclude)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public function hasChildren(): bool
|
||||
{
|
||||
return $this->getInnerIterator()->hasChildren();
|
||||
}
|
||||
|
||||
public function getChildren(): self
|
||||
{
|
||||
return new self(
|
||||
$this->getInnerIterator()->getChildren(),
|
||||
$this->exclude
|
||||
);
|
||||
}
|
||||
|
||||
public function getInnerIterator(): RecursiveDirectoryIterator
|
||||
{
|
||||
$innerIterator = parent::getInnerIterator();
|
||||
|
||||
assert($innerIterator instanceof RecursiveDirectoryIterator);
|
||||
|
||||
return $innerIterator;
|
||||
}
|
||||
}
|
||||
+51
@@ -0,0 +1,51 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-file-iterator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\FileIterator;
|
||||
|
||||
use function array_unique;
|
||||
use function assert;
|
||||
use function sort;
|
||||
use SplFileInfo;
|
||||
|
||||
/**
|
||||
* @no-named-arguments Parameter names are not covered by the backward compatibility promise for PHPUnit
|
||||
*/
|
||||
final class Facade
|
||||
{
|
||||
/**
|
||||
* @psalm-param list<string>|string $suffixes
|
||||
* @psalm-param list<string>|string $prefixes
|
||||
* @psalm-param list<string> $exclude
|
||||
*
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
public function getFilesAsArray(string $path, array|string $suffixes = '', array|string $prefixes = '', array $exclude = []): array
|
||||
{
|
||||
$iterator = (new Factory)->getFileIterator($path, $suffixes, $prefixes, $exclude);
|
||||
|
||||
$files = [];
|
||||
|
||||
foreach ($iterator as $file) {
|
||||
assert($file instanceof SplFileInfo);
|
||||
|
||||
$file = $file->getRealPath();
|
||||
|
||||
if ($file) {
|
||||
$files[] = $file;
|
||||
}
|
||||
}
|
||||
|
||||
$files = array_unique($files);
|
||||
|
||||
sort($files);
|
||||
|
||||
return $files;
|
||||
}
|
||||
}
|
||||
+106
@@ -0,0 +1,106 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-file-iterator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\FileIterator;
|
||||
|
||||
use const GLOB_ONLYDIR;
|
||||
use function array_filter;
|
||||
use function array_map;
|
||||
use function array_merge;
|
||||
use function array_values;
|
||||
use function glob;
|
||||
use function is_dir;
|
||||
use function is_string;
|
||||
use function realpath;
|
||||
use AppendIterator;
|
||||
use FilesystemIterator;
|
||||
use RecursiveDirectoryIterator;
|
||||
use RecursiveIteratorIterator;
|
||||
|
||||
/**
|
||||
* @internal This class is not covered by the backward compatibility promise for phpunit/php-file-iterator
|
||||
*/
|
||||
final class Factory
|
||||
{
|
||||
/**
|
||||
* @psalm-param list<string>|string $paths
|
||||
* @psalm-param list<string>|string $suffixes
|
||||
* @psalm-param list<string>|string $prefixes
|
||||
* @psalm-param list<string> $exclude
|
||||
*/
|
||||
public function getFileIterator(array|string $paths, array|string $suffixes = '', array|string $prefixes = '', array $exclude = []): AppendIterator
|
||||
{
|
||||
if (is_string($paths)) {
|
||||
$paths = [$paths];
|
||||
}
|
||||
|
||||
$paths = $this->resolveWildcards($paths);
|
||||
$exclude = $this->resolveWildcards($exclude);
|
||||
|
||||
if (is_string($prefixes)) {
|
||||
if ($prefixes !== '') {
|
||||
$prefixes = [$prefixes];
|
||||
} else {
|
||||
$prefixes = [];
|
||||
}
|
||||
}
|
||||
|
||||
if (is_string($suffixes)) {
|
||||
if ($suffixes !== '') {
|
||||
$suffixes = [$suffixes];
|
||||
} else {
|
||||
$suffixes = [];
|
||||
}
|
||||
}
|
||||
|
||||
$iterator = new AppendIterator;
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if (is_dir($path)) {
|
||||
$iterator->append(
|
||||
new Iterator(
|
||||
$path,
|
||||
new RecursiveIteratorIterator(
|
||||
new ExcludeIterator(
|
||||
new RecursiveDirectoryIterator($path, FilesystemIterator::FOLLOW_SYMLINKS | FilesystemIterator::SKIP_DOTS),
|
||||
$exclude,
|
||||
),
|
||||
),
|
||||
$suffixes,
|
||||
$prefixes,
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return $iterator;
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-param list<string> $paths
|
||||
*
|
||||
* @psalm-return list<string>
|
||||
*/
|
||||
private function resolveWildcards(array $paths): array
|
||||
{
|
||||
$_paths = [[]];
|
||||
|
||||
foreach ($paths as $path) {
|
||||
if ($locals = glob($path, GLOB_ONLYDIR)) {
|
||||
$_paths[] = array_map('\realpath', $locals);
|
||||
} else {
|
||||
// @codeCoverageIgnoreStart
|
||||
$_paths[] = [realpath($path)];
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
}
|
||||
|
||||
return array_values(array_filter(array_merge(...$_paths)));
|
||||
}
|
||||
}
|
||||
+115
@@ -0,0 +1,115 @@
|
||||
<?php declare(strict_types=1);
|
||||
/*
|
||||
* This file is part of phpunit/php-file-iterator.
|
||||
*
|
||||
* (c) Sebastian Bergmann <sebastian@phpunit.de>
|
||||
*
|
||||
* For the full copyright and license information, please view the LICENSE
|
||||
* file that was distributed with this source code.
|
||||
*/
|
||||
namespace SebastianBergmann\FileIterator;
|
||||
|
||||
use function assert;
|
||||
use function preg_match;
|
||||
use function realpath;
|
||||
use function str_ends_with;
|
||||
use function str_replace;
|
||||
use function str_starts_with;
|
||||
use AppendIterator;
|
||||
use FilterIterator;
|
||||
use SplFileInfo;
|
||||
|
||||
/**
|
||||
* @template-extends FilterIterator<int, string, AppendIterator>
|
||||
*
|
||||
* @internal This class is not covered by the backward compatibility promise for phpunit/php-file-iterator
|
||||
*/
|
||||
final class Iterator extends FilterIterator
|
||||
{
|
||||
public const PREFIX = 0;
|
||||
|
||||
public const SUFFIX = 1;
|
||||
private string|false $basePath;
|
||||
|
||||
/**
|
||||
* @psalm-var list<string>
|
||||
*/
|
||||
private array $suffixes;
|
||||
|
||||
/**
|
||||
* @psalm-var list<string>
|
||||
*/
|
||||
private array $prefixes;
|
||||
|
||||
/**
|
||||
* @psalm-param list<string> $suffixes
|
||||
* @psalm-param list<string> $prefixes
|
||||
*/
|
||||
public function __construct(string $basePath, \Iterator $iterator, array $suffixes = [], array $prefixes = [])
|
||||
{
|
||||
$this->basePath = realpath($basePath);
|
||||
$this->prefixes = $prefixes;
|
||||
$this->suffixes = $suffixes;
|
||||
|
||||
parent::__construct($iterator);
|
||||
}
|
||||
|
||||
public function accept(): bool
|
||||
{
|
||||
$current = $this->getInnerIterator()->current();
|
||||
|
||||
assert($current instanceof SplFileInfo);
|
||||
|
||||
$filename = $current->getFilename();
|
||||
$realPath = $current->getRealPath();
|
||||
|
||||
if ($realPath === false) {
|
||||
// @codeCoverageIgnoreStart
|
||||
return false;
|
||||
// @codeCoverageIgnoreEnd
|
||||
}
|
||||
|
||||
return $this->acceptPath($realPath) &&
|
||||
$this->acceptPrefix($filename) &&
|
||||
$this->acceptSuffix($filename);
|
||||
}
|
||||
|
||||
private function acceptPath(string $path): bool
|
||||
{
|
||||
// Filter files in hidden directories by checking path that is relative to the base path.
|
||||
if (preg_match('=/\.[^/]*/=', str_replace((string) $this->basePath, '', $path))) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private function acceptPrefix(string $filename): bool
|
||||
{
|
||||
return $this->acceptSubString($filename, $this->prefixes, self::PREFIX);
|
||||
}
|
||||
|
||||
private function acceptSuffix(string $filename): bool
|
||||
{
|
||||
return $this->acceptSubString($filename, $this->suffixes, self::SUFFIX);
|
||||
}
|
||||
|
||||
/**
|
||||
* @psalm-param list<string> $subStrings
|
||||
*/
|
||||
private function acceptSubString(string $filename, array $subStrings, int $type): bool
|
||||
{
|
||||
if (empty($subStrings)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($subStrings as $string) {
|
||||
if (($type === self::PREFIX && str_starts_with($filename, $string)) ||
|
||||
($type === self::SUFFIX && str_ends_with($filename, $string))) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user