Merging fixes from 1.1.x.x Folder class to 1.2.x.x

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@4096 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2006-12-12 22:11:24 +00:00
parent 37281be9de
commit 64997718e0

View file

@ -87,7 +87,7 @@ class Folder extends Object{
function cd($desiredPath) { function cd($desiredPath) {
$desiredPath = realpath($desiredPath); $desiredPath = realpath($desiredPath);
$newPath = $this->isAbsolute($desiredPath) ? $desiredPath : $this->addPathElement($this->path, $desiredPath); $newPath = $this->isAbsolute($desiredPath) ? $desiredPath : $this->addPathElement($this->path, $desiredPath);
$isDir = is_dir($newPath) ? $this->path = $newPath : false; $isDir = (is_dir($newPath) && file_exists($newPath)) ? $this->path = $newPath : false;
return $isDir; return $isDir;
} }
/** /**
@ -99,10 +99,9 @@ class Folder extends Object{
* @return array * @return array
*/ */
function ls($sort = true, $noDotFiles = false) { function ls($sort = true, $noDotFiles = false) {
$dirs = $files = array();
$dir = opendir($this->path); $dir = opendir($this->path);
if ($dir) { if ($dir) {
$dirs = $files = array();
while(false !== ($n = readdir($dir))) { while(false !== ($n = readdir($dir))) {
if ((!preg_match('#^\.+$#', $n) && $noDotFiles == false) || ($noDotFiles == true && !preg_match('#^\.(.*)$#', $n))) { if ((!preg_match('#^\.+$#', $n) && $noDotFiles == false) || ($noDotFiles == true && !preg_match('#^\.(.*)$#', $n))) {
if (is_dir($this->addPathElement($this->path, $n))) { if (is_dir($this->addPathElement($this->path, $n))) {
@ -118,11 +117,8 @@ class Folder extends Object{
sort ($files); sort ($files);
} }
closedir ($dir); closedir ($dir);
$array = array($dirs,$files); }
return $array; return array($dirs,$files);
} else {
return false;
}
} }
/** /**
* Returns an array of all matching files in current directory. * Returns an array of all matching files in current directory.
@ -137,7 +133,7 @@ class Folder extends Object{
return array(); return array();
} }
list($dirs, $files)=$data; list($dirs, $files) = $data;
$found = array(); $found = array();
foreach($files as $file) { foreach($files as $file) {
@ -168,6 +164,7 @@ class Folder extends Object{
*/ */
function _findRecursive($pattern) { function _findRecursive($pattern) {
list($dirs, $files) = $this->ls(); list($dirs, $files) = $this->ls();
$found = array(); $found = array();
foreach($files as $file) { foreach($files as $file) {
if (preg_match("/^{$pattern}$/i", $file)) { if (preg_match("/^{$pattern}$/i", $file)) {
@ -175,7 +172,6 @@ class Folder extends Object{
} }
} }
$start = $this->path; $start = $this->path;
foreach($dirs as $dir) { foreach($dirs as $dir) {
$this->cd($this->addPathElement($start, $dir)); $this->cd($this->addPathElement($start, $dir));
$found = array_merge($found, $this->findRecursive($pattern)); $found = array_merge($found, $this->findRecursive($pattern));