Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Make Folder::tree use SPL Iterators.

  • Loading branch information...
commit 682dc5e24b5e4f9ff9b9a526eaf84535372353e5 1 parent 7656feb
Mark Story markstory authored
Showing with 25 additions and 12 deletions.
  1. +25 −12 lib/Cake/Utility/Folder.php
37 lib/Cake/Utility/Folder.php
View
@@ -393,28 +393,41 @@ public function tree($path, $exceptions = true, $type = null) {
}
return array();
}
- $this->_files = array();
- $this->_directories = array($this->realpath($path));
- $directories = array();
+ $files = array();
+ $directories = array($path);
+ $skipHidden = false;
if ($exceptions === false) {
- $exceptions = true;
+ $skipHidden = true;
}
- while (!empty($this->_directories)) {
- $dir = array_pop($this->_directories);
- $this->_tree($dir, $exceptions);
- $directories[] = $dir;
+ if (is_array($exceptions)) {
+ $exceptions = array_flip($exceptions);
}
+ 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) {
- return array($directories, $this->_files);
+ return array($directories, $files);
}
if ($type === 'dir') {
return $directories;
}
- $this->cd($original);
-
- return $this->_files;
+ return $files;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.