mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Make Folder::tree use SPL Iterators.
This commit is contained in:
parent
7656feb0bb
commit
682dc5e24b
1 changed files with 25 additions and 12 deletions
|
@ -393,28 +393,41 @@ class Folder {
|
||||||
}
|
}
|
||||||
return array();
|
return array();
|
||||||
}
|
}
|
||||||
$this->_files = array();
|
$files = array();
|
||||||
$this->_directories = array($this->realpath($path));
|
$directories = array($path);
|
||||||
$directories = array();
|
$skipHidden = false;
|
||||||
|
|
||||||
if ($exceptions === false) {
|
if ($exceptions === false) {
|
||||||
$exceptions = true;
|
$skipHidden = true;
|
||||||
}
|
}
|
||||||
while (!empty($this->_directories)) {
|
if (is_array($exceptions)) {
|
||||||
$dir = array_pop($this->_directories);
|
$exceptions = array_flip($exceptions);
|
||||||
$this->_tree($dir, $exceptions);
|
|
||||||
$directories[] = $dir;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$directory = new RecursiveDirectoryIterator($path);
|
||||||
|
$iterator = new RecursiveIteratorIterator($directory, RecursiveIteratorIterator::SELF_FIRST);
|
||||||
|
} catch (UnexpectedValueException $e) {
|
||||||
|
return array();
|
||||||
|
}
|
||||||
|
foreach ($iterator as $item) {
|
||||||
|
$name = $item->getFileName();
|
||||||
|
if ($skipHidden && $name[0] === '.' || isset($exceptions[$name])) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if ($item->isFile()) {
|
||||||
|
$files[] = $item->getPathName();
|
||||||
|
} else if ($item->isDir()) {
|
||||||
|
$directories[] = $item->getPathName();
|
||||||
|
}
|
||||||
|
}
|
||||||
if ($type === null) {
|
if ($type === null) {
|
||||||
return array($directories, $this->_files);
|
return array($directories, $files);
|
||||||
}
|
}
|
||||||
if ($type === 'dir') {
|
if ($type === 'dir') {
|
||||||
return $directories;
|
return $directories;
|
||||||
}
|
}
|
||||||
$this->cd($original);
|
return $files;
|
||||||
|
|
||||||
return $this->_files;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue