3 * This file is part of the File_Iterator package.
5 * (c) Sebastian Bergmann <sebastian@phpunit.de>
7 * For the full copyright and license information, please view the LICENSE
8 * file that was distributed with this source code.
12 * Factory Method implementation that creates a File_Iterator that operates on
13 * an AppendIterator that contains an RecursiveDirectoryIterator for each given
16 * @since Class available since Release 1.1.0
18 class File_Iterator_Factory
21 * @param array|string $paths
22 * @param array|string $suffixes
23 * @param array|string $prefixes
24 * @param array $exclude
25 * @return AppendIterator
27 public function getFileIterator($paths, $suffixes = '', $prefixes = '', array $exclude = array())
29 if (is_string($paths)) {
30 $paths = array($paths);
33 $paths = $this->getPathsAfterResolvingWildcards($paths);
34 $exclude = $this->getPathsAfterResolvingWildcards($exclude);
36 if (is_string($prefixes)) {
37 if ($prefixes != '') {
38 $prefixes = array($prefixes);
44 if (is_string($suffixes)) {
45 if ($suffixes != '') {
46 $suffixes = array($suffixes);
52 $iterator = new AppendIterator;
54 foreach ($paths as $path) {
58 new RecursiveIteratorIterator(
59 new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::FOLLOW_SYMLINKS)
77 protected function getPathsAfterResolvingWildcards(array $paths)
81 foreach ($paths as $path) {
82 if ($locals = glob($path, GLOB_ONLYDIR)) {
83 $_paths = array_merge($_paths, $locals);