pax_global_header00006660000000000000000000000064132070142100014500gustar00rootroot0000000000000052 comment=730b01bc3e867237eaac355e06a36b85dd93a8b4 php-file-iterator-1.4.5/000077500000000000000000000000001320701421000150425ustar00rootroot00000000000000php-file-iterator-1.4.5/.gitattributes000066400000000000000000000000171320701421000177330ustar00rootroot00000000000000*.php diff=php php-file-iterator-1.4.5/.gitignore000066400000000000000000000001421320701421000170270ustar00rootroot00000000000000build/api build/code-browser build/coverage build/logs build/pdepend cache.properties phpunit.xml php-file-iterator-1.4.5/ChangeLog.md000066400000000000000000000025251320701421000172170ustar00rootroot00000000000000# Change Log All notable changes to this project will be documented in this file. This project adheres to [Semantic Versioning](http://semver.org/). ## [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) [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-1.4.5/LICENSE000066400000000000000000000030141320701421000160450ustar00rootroot00000000000000File_Iterator Copyright (c) 2009-2015, 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-1.4.5/README.md000066400000000000000000000006341320701421000163240ustar00rootroot00000000000000# 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-1.4.5/composer.json000066400000000000000000000015561320701421000175730ustar00rootroot00000000000000{ "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": "sb@sebastian-bergmann.de", "role": "lead" } ], "support": { "issues": "https://github.com/sebastianbergmann/php-file-iterator/issues", "irc": "irc://irc.freenode.net/phpunit" }, "require": { "php": ">=5.3.3" }, "autoload": { "classmap": [ "src/" ] }, "extra": { "branch-alias": { "dev-master": "1.4.x-dev" } } } php-file-iterator-1.4.5/src/000077500000000000000000000000001320701421000156315ustar00rootroot00000000000000php-file-iterator-1.4.5/src/Facade.php000066400000000000000000000056731320701421000175200ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Façade implementation that uses File_Iterator_Factory to create a * File_Iterator that operates on an AppendIterator that contains an * RecursiveDirectoryIterator for each given path. The list of unique * files is returned as an array. * * @since Class available since Release 1.3.0 */ class File_Iterator_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 = array(), $commonPath = FALSE) { if (is_string($paths)) { $paths = array($paths); } $factory = new File_Iterator_Factory; $iterator = $factory->getFileIterator( $paths, $suffixes, $prefixes, $exclude ); $files = array(); 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 array( 'commonPath' => $this->getCommonPath($files), 'files' => $files ); } else { return $files; } } /** * Returns the common path of a set of files. * * @param array $files * @return string */ protected function getCommonPath(array $files) { $count = count($files); if ($count == 0) { return ''; } if ($count == 1) { return dirname($files[0]) . DIRECTORY_SEPARATOR; } $_files = array(); 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-1.4.5/src/Factory.php000066400000000000000000000046471320701421000177640ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * Factory Method implementation that creates a File_Iterator that operates on * an AppendIterator that contains an RecursiveDirectoryIterator for each given * path. * * @since Class available since Release 1.1.0 */ class File_Iterator_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 = array()) { if (is_string($paths)) { $paths = array($paths); } $paths = $this->getPathsAfterResolvingWildcards($paths); $exclude = $this->getPathsAfterResolvingWildcards($exclude); if (is_string($prefixes)) { if ($prefixes != '') { $prefixes = array($prefixes); } else { $prefixes = array(); } } if (is_string($suffixes)) { if ($suffixes != '') { $suffixes = array($suffixes); } else { $suffixes = array(); } } $iterator = new AppendIterator; foreach ($paths as $path) { if (is_dir($path)) { $iterator->append( new File_Iterator( new RecursiveIteratorIterator( new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS) ), $suffixes, $prefixes, $exclude, $path ) ); } } return $iterator; } /** * @param array $paths * @return array */ protected function getPathsAfterResolvingWildcards(array $paths) { $_paths = array(); foreach ($paths as $path) { if ($locals = glob($path, GLOB_ONLYDIR)) { $_paths = array_merge($_paths, array_map('realpath', $locals)); } else { $_paths[] = realpath($path); } } return $_paths; } } php-file-iterator-1.4.5/src/Iterator.php000066400000000000000000000075421320701421000201430ustar00rootroot00000000000000 * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * FilterIterator implementation that filters files based on prefix(es) and/or * suffix(es). Hidden files and files from hidden directories are also filtered. * * @since Class available since Release 1.0.0 */ class File_Iterator extends FilterIterator { const PREFIX = 0; const SUFFIX = 1; /** * @var array */ protected $suffixes = array(); /** * @var array */ protected $prefixes = array(); /** * @var array */ protected $exclude = array(); /** * @var string */ protected $basepath; /** * @param Iterator $iterator * @param array $suffixes * @param array $prefixes * @param array $exclude * @param string $basepath */ public function __construct(Iterator $iterator, array $suffixes = array(), array $prefixes = array(), array $exclude = array(), $basepath = NULL) { $exclude = array_filter(array_map('realpath', $exclude)); if ($basepath !== NULL) { $basepath = realpath($basepath); } if ($basepath === FALSE) { $basepath = NULL; } else { foreach ($exclude as &$_exclude) { $_exclude = str_replace($basepath, '', $_exclude); } } $this->prefixes = $prefixes; $this->suffixes = $suffixes; $this->exclude = $exclude; $this->basepath = $basepath; parent::__construct($iterator); } /** * @return bool */ public function accept() { $current = $this->getInnerIterator()->current(); $filename = $current->getFilename(); $realpath = $current->getRealPath(); if ($this->basepath !== NULL) { $realpath = str_replace($this->basepath, '', $realpath); } // Filter files in hidden directories. if (preg_match('=/\.[^/]*/=', $realpath)) { return FALSE; } return $this->acceptPath($realpath) && $this->acceptPrefix($filename) && $this->acceptSuffix($filename); } /** * @param string $path * @return bool * @since Method available since Release 1.1.0 */ protected function acceptPath($path) { foreach ($this->exclude as $exclude) { if (strpos($path, $exclude) === 0) { return FALSE; } } return TRUE; } /** * @param string $filename * @return bool * @since Method available since Release 1.1.0 */ protected function acceptPrefix($filename) { return $this->acceptSubString($filename, $this->prefixes, self::PREFIX); } /** * @param string $filename * @return bool * @since Method available since Release 1.1.0 */ protected function acceptSuffix($filename) { return $this->acceptSubString($filename, $this->suffixes, self::SUFFIX); } /** * @param string $filename * @param array $subStrings * @param int $type * @return bool * @since Method available since Release 1.1.0 */ protected function acceptSubString($filename, array $subStrings, $type) { 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; } }