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 * Façade implementation that uses File_Iterator_Factory to create a
13 * File_Iterator that operates on an AppendIterator that contains an
14 * RecursiveDirectoryIterator for each given path. The list of unique
15 * files is returned as an array.
17 * @since Class available since Release 1.3.0
19 class File_Iterator_Facade
22 * @param array|string $paths
23 * @param array|string $suffixes
24 * @param array|string $prefixes
25 * @param array $exclude
26 * @param bool $commonPath
29 public function getFilesAsArray($paths, $suffixes = '', $prefixes = '', array $exclude = array(), $commonPath = FALSE)
31 if (is_string($paths)) {
32 $paths = array($paths);
35 $factory = new File_Iterator_Factory;
36 $iterator = $factory->getFileIterator(
37 $paths, $suffixes, $prefixes, $exclude
42 foreach ($iterator as $file) {
43 $file = $file->getRealPath();
50 foreach ($paths as $path) {
52 $files[] = realpath($path);
56 $files = array_unique($files);
61 'commonPath' => $this->getCommonPath($files),
70 * Returns the common path of a set of files.
75 protected function getCommonPath(array $files)
77 $count = count($files);
84 return dirname($files[0]) . DIRECTORY_SEPARATOR;
89 foreach ($files as $file) {
90 $_files[] = $_fileParts = explode(DIRECTORY_SEPARATOR, $file);
92 if (empty($_fileParts[0])) {
93 $_fileParts[0] = DIRECTORY_SEPARATOR;
103 for ($i = 0; $i < $count; $i++) {
104 if ($_files[$i][$j] != $_files[$i+1][$j]) {
111 $common .= $_files[0][$j];
114 $common .= DIRECTORY_SEPARATOR;
121 return DIRECTORY_SEPARATOR . $common;