pax_global_header00006660000000000000000000000064133465446460014531gustar00rootroot0000000000000052 comment=050bedf145a257b1ff02746c31894800e5122946 php-file-iterator-2.0.2/000077500000000000000000000000001334654464600150655ustar00rootroot00000000000000php-file-iterator-2.0.2/.gitattributes000066400000000000000000000000171334654464600177560ustar00rootroot00000000000000*.php diff=php php-file-iterator-2.0.2/.github/000077500000000000000000000000001334654464600164255ustar00rootroot00000000000000php-file-iterator-2.0.2/.github/stale.yml000066400000000000000000000026771334654464600202740ustar00rootroot00000000000000# Configuration for probot-stale - https://github.com/probot/stale # Number of days of inactivity before an Issue or Pull Request becomes stale daysUntilStale: 60 # Number of days of inactivity before a stale Issue or Pull Request is closed. # Set to false to disable. If disabled, issues still need to be closed manually, but will remain marked as stale. daysUntilClose: 7 # Issues or Pull Requests with these labels will never be considered stale. Set to `[]` to disable exemptLabels: - enhancement # Set to true to ignore issues in a project (defaults to false) exemptProjects: false # Set to true to ignore issues in a milestone (defaults to false) exemptMilestones: false # Label to use when marking as stale staleLabel: stale # Comment to post when marking as stale. Set to `false` to disable markComment: > This issue has been automatically marked as stale because it has not had activity within the last 60 days. It will be closed after 7 days if no further activity occurs. Thank you for your contributions. # Comment to post when removing the stale label. # unmarkComment: > # Your comment here. # Comment to post when closing a stale Issue or Pull Request. closeComment: > This issue has been automatically closed because it has not had activity since it was marked as stale. Thank you for your contributions. # Limit the number of actions per hour, from 1-30. Default is 30 limitPerRun: 30 # Limit to only `issues` or `pulls` only: issues php-file-iterator-2.0.2/.gitignore000066400000000000000000000000671334654464600170600ustar00rootroot00000000000000/.idea /vendor/ /.php_cs /.php_cs.cache /composer.lock php-file-iterator-2.0.2/.php_cs.dist000066400000000000000000000147441334654464600173160ustar00rootroot00000000000000 For the full copyright and license information, please view the LICENSE file that was distributed with this source code. EOF; return PhpCsFixer\Config::create() ->setRiskyAllowed(true) ->setRules( [ 'array_syntax' => ['syntax' => 'short'], 'binary_operator_spaces' => [ 'operators' => [ '=' => 'align', '=>' => 'align', ], ], 'blank_line_after_namespace' => true, 'blank_line_before_statement' => [ 'statements' => [ 'break', 'continue', 'declare', 'do', 'for', 'foreach', 'if', 'include', 'include_once', 'require', 'require_once', 'return', 'switch', 'throw', 'try', 'while', 'yield', ], ], 'braces' => true, 'cast_spaces' => true, 'class_attributes_separation' => ['elements' => ['method']], 'compact_nullable_typehint' => true, 'concat_space' => ['spacing' => 'one'], 'declare_equal_normalize' => ['space' => 'none'], 'dir_constant' => true, 'elseif' => true, 'encoding' => true, 'full_opening_tag' => true, 'function_declaration' => true, 'header_comment' => ['header' => $header, 'separate' => 'none'], 'indentation_type' => true, 'line_ending' => true, 'list_syntax' => ['syntax' => 'short'], 'lowercase_cast' => true, 'lowercase_constants' => true, 'lowercase_keywords' => true, 'magic_constant_casing' => true, 'method_argument_space' => ['ensure_fully_multiline' => true], 'modernize_types_casting' => true, 'native_function_casing' => true, 'native_function_invocation' => true, 'no_alias_functions' => true, 'no_blank_lines_after_class_opening' => true, 'no_blank_lines_after_phpdoc' => true, 'no_closing_tag' => true, 'no_empty_comment' => true, 'no_empty_phpdoc' => true, 'no_empty_statement' => true, 'no_extra_blank_lines' => true, 'no_homoglyph_names' => true, 'no_leading_import_slash' => true, 'no_leading_namespace_whitespace' => true, 'no_mixed_echo_print' => ['use' => 'print'], 'no_null_property_initialization' => true, 'no_short_bool_cast' => true, 'no_short_echo_tag' => true, 'no_singleline_whitespace_before_semicolons' => true, 'no_spaces_after_function_name' => true, 'no_spaces_inside_parenthesis' => true, 'no_superfluous_elseif' => true, 'no_trailing_comma_in_list_call' => true, 'no_trailing_comma_in_singleline_array' => true, 'no_trailing_whitespace' => true, 'no_trailing_whitespace_in_comment' => true, 'no_unneeded_control_parentheses' => true, 'no_unneeded_curly_braces' => true, 'no_unneeded_final_method' => true, 'no_unreachable_default_argument_value' => true, 'no_unused_imports' => true, 'no_useless_else' => true, 'no_whitespace_before_comma_in_array' => true, 'no_whitespace_in_blank_line' => true, 'non_printable_character' => true, 'normalize_index_brace' => true, 'object_operator_without_whitespace' => true, 'ordered_class_elements' => [ 'order' => [ 'use_trait', 'constant_public', 'constant_protected', 'constant_private', 'property_public_static', 'property_protected_static', 'property_private_static', 'property_public', 'property_protected', 'property_private', 'method_public_static', 'construct', 'destruct', 'magic', 'phpunit', 'method_public', 'method_protected', 'method_private', 'method_protected_static', 'method_private_static', ], ], 'ordered_imports' => true, 'phpdoc_add_missing_param_annotation' => true, 'phpdoc_align' => true, 'phpdoc_annotation_without_dot' => true, 'phpdoc_indent' => true, 'phpdoc_no_access' => true, 'phpdoc_no_empty_return' => true, 'phpdoc_no_package' => true, 'phpdoc_order' => true, 'phpdoc_return_self_reference' => true, 'phpdoc_scalar' => true, 'phpdoc_separation' => true, 'phpdoc_single_line_var_spacing' => true, 'phpdoc_to_comment' => true, 'phpdoc_trim' => true, 'phpdoc_types' => true, 'phpdoc_types_order' => true, 'phpdoc_var_without_name' => true, 'pow_to_exponentiation' => true, 'protected_to_private' => true, 'return_type_declaration' => ['space_before' => 'none'], 'self_accessor' => true, 'short_scalar_cast' => true, 'simplified_null_return' => true, 'single_blank_line_at_eof' => true, 'single_import_per_statement' => true, 'single_line_after_imports' => true, 'single_quote' => true, 'standardize_not_equals' => true, 'ternary_to_null_coalescing' => true, 'trim_array_spaces' => true, 'unary_operator_spaces' => true, 'visibility_required' => true, 'void_return' => true, 'whitespace_after_comma_in_array' => true, ] ) ->setFinder( PhpCsFixer\Finder::create() ->files() ->in(__DIR__ . '/src') ->in(__DIR__ . '/tests') ->notName('*.phpt') ); php-file-iterator-2.0.2/.travis.yml000066400000000000000000000012401334654464600171730ustar00rootroot00000000000000language: php sudo: false php: - 7.1 - 7.2 - master env: matrix: - DEPENDENCIES="high" - DEPENDENCIES="low" global: - DEFAULT_COMPOSER_FLAGS="--no-interaction --no-ansi --no-progress --no-suggest" before_install: - composer self-update - composer clear-cache install: - if [[ "$DEPENDENCIES" = 'high' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS; fi - if [[ "$DEPENDENCIES" = 'low' ]]; then travis_retry composer update $DEFAULT_COMPOSER_FLAGS --prefer-lowest; fi script: - ./vendor/bin/phpunit --coverage-clover=coverage.xml after_success: - bash <(curl -s https://codecov.io/bash) notifications: email: false php-file-iterator-2.0.2/ChangeLog.md000066400000000000000000000044201334654464600172360ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [2.0.2] - 2018-09-13 ### Fixed * 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 * Fixed [#46](https://github.com/sebastianbergmann/php-file-iterator/issues/46): Regression with hidden parent directory ## [2.0.0] - 2018-05-28 ### Fixed * 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 * 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 * 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 * 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 * [Added support for wildcards (glob) in exclude](https://github.com/sebastianbergmann/php-file-iterator/pull/23) [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...master [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 php-file-iterator-2.0.2/LICENSE000066400000000000000000000030201334654464600160650ustar00rootroot00000000000000php-file-iterator Copyright (c) 2009-2018, 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: * Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. * 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. * Neither the name of Sebastian Bergmann nor the names of his 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 OWNER 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. php-file-iterator-2.0.2/README.md000066400000000000000000000010731334654464600163450ustar00rootroot00000000000000[![Build Status](https://travis-ci.org/sebastianbergmann/php-file-iterator.svg?branch=master)](https://travis-ci.org/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 php-file-iterator-2.0.2/composer.json000066400000000000000000000015631334654464600176140ustar00rootroot00000000000000{ "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" }, "require": { "php": "^7.1" }, "require-dev": { "phpunit/phpunit": "^7.1" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "2.0.x-dev" } } } php-file-iterator-2.0.2/phpunit.xml000066400000000000000000000013631334654464600173010ustar00rootroot00000000000000 tests src php-file-iterator-2.0.2/src/000077500000000000000000000000001334654464600156545ustar00rootroot00000000000000php-file-iterator-2.0.2/src/Facade.php000066400000000000000000000047701334654464600175400ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\FileIterator; class Facade { /** * @param array|string $paths * @param array|string $suffixes * @param array|string $prefixes * @param array $exclude * @param bool $commonPath * * @return array */ public function getFilesAsArray($paths, $suffixes = '', $prefixes = '', array $exclude = [], bool $commonPath = false): array { if (\is_string($paths)) { $paths = [$paths]; } $factory = new Factory; $iterator = $factory->getFileIterator($paths, $suffixes, $prefixes, $exclude); $files = []; foreach ($iterator as $file) { $file = $file->getRealPath(); if ($file) { $files[] = $file; } } foreach ($paths as $path) { if (\is_file($path)) { $files[] = \realpath($path); } } $files = \array_unique($files); \sort($files); if ($commonPath) { return [ 'commonPath' => $this->getCommonPath($files), 'files' => $files ]; } return $files; } protected function getCommonPath(array $files): string { $count = \count($files); if ($count === 0) { return ''; } if ($count === 1) { return \dirname($files[0]) . DIRECTORY_SEPARATOR; } $_files = []; foreach ($files as $file) { $_files[] = $_fileParts = \explode(DIRECTORY_SEPARATOR, $file); if (empty($_fileParts[0])) { $_fileParts[0] = DIRECTORY_SEPARATOR; } } $common = ''; $done = false; $j = 0; $count--; while (!$done) { for ($i = 0; $i < $count; $i++) { if ($_files[$i][$j] != $_files[$i + 1][$j]) { $done = true; break; } } if (!$done) { $common .= $_files[0][$j]; if ($j > 0) { $common .= DIRECTORY_SEPARATOR; } } $j++; } return DIRECTORY_SEPARATOR . $common; } } php-file-iterator-2.0.2/src/Factory.php000066400000000000000000000043531334654464600200010ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\FileIterator; class Factory { /** * @param array|string $paths * @param array|string $suffixes * @param array|string $prefixes * @param array $exclude * * @return \AppendIterator */ public function getFileIterator($paths, $suffixes = '', $prefixes = '', array $exclude = []): \AppendIterator { if (\is_string($paths)) { $paths = [$paths]; } $paths = $this->getPathsAfterResolvingWildcards($paths); $exclude = $this->getPathsAfterResolvingWildcards($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 \RecursiveDirectoryIterator($path, \RecursiveDirectoryIterator::FOLLOW_SYMLINKS | \RecursiveDirectoryIterator::SKIP_DOTS) ), $suffixes, $prefixes, $exclude ) ); } } return $iterator; } protected function getPathsAfterResolvingWildcards(array $paths): array { $_paths = []; foreach ($paths as $path) { if ($locals = \glob($path, GLOB_ONLYDIR)) { $_paths = \array_merge($_paths, \array_map('\realpath', $locals)); } else { $_paths[] = \realpath($path); } } return \array_filter($_paths); } } php-file-iterator-2.0.2/src/Iterator.php000066400000000000000000000054211334654464600201600ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\FileIterator; class Iterator extends \FilterIterator { const PREFIX = 0; const SUFFIX = 1; /** * @var string */ private $basePath; /** * @var array */ private $suffixes = []; /** * @var array */ private $prefixes = []; /** * @var array */ private $exclude = []; /** * @param string $basePath * @param \Iterator $iterator * @param array $suffixes * @param array $prefixes * @param array $exclude */ public function __construct(string $basePath, \Iterator $iterator, array $suffixes = [], array $prefixes = [], array $exclude = []) { $this->basePath = \realpath($basePath); $this->prefixes = $prefixes; $this->suffixes = $suffixes; $this->exclude = \array_filter(\array_map('realpath', $exclude)); parent::__construct($iterator); } public function accept() { $current = $this->getInnerIterator()->current(); $filename = $current->getFilename(); $realPath = $current->getRealPath(); 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($this->basePath, '', $path))) { return false; } foreach ($this->exclude as $exclude) { if (\strpos($path, $exclude) === 0) { 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); } private function acceptSubString(string $filename, array $subStrings, int $type): bool { if (empty($subStrings)) { return true; } $matched = false; foreach ($subStrings as $string) { if (($type === self::PREFIX && \strpos($filename, $string) === 0) || ($type === self::SUFFIX && \substr($filename, -1 * \strlen($string)) === $string)) { $matched = true; break; } } return $matched; } } php-file-iterator-2.0.2/tests/000077500000000000000000000000001334654464600162275ustar00rootroot00000000000000php-file-iterator-2.0.2/tests/FactoryTest.php000066400000000000000000000023121334654464600212050ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ namespace SebastianBergmann\FileIterator; use PHPUnit\Framework\TestCase; /** * @covers \SebastianBergmann\FileIterator\Factory */ class FactoryTest extends TestCase { /** * @var string */ private $root; /** * @var Factory */ private $factory; protected function setUp(): void { $this->root = __DIR__; $this->factory = new Factory; } public function testFindFilesInTestDirectory(): void { $iterator = $this->factory->getFileIterator($this->root, 'Test.php'); $files = \iterator_to_array($iterator); $this->assertGreaterThanOrEqual(1, \count($files)); } public function testFindFilesWithExcludedNonExistingSubdirectory(): void { $iterator = $this->factory->getFileIterator($this->root, 'Test.php', '', [$this->root . '/nonExistingDir']); $files = \iterator_to_array($iterator); $this->assertGreaterThanOrEqual(1, \count($files)); } }