fixing folder class when path give does not exist

This commit is contained in:
gwoo 2009-08-02 15:42:27 -07:00
parent f9f67a1759
commit ffe801bb28
2 changed files with 16 additions and 1 deletions

View file

@ -161,6 +161,9 @@ class Folder extends Object {
* @access public
*/
function read($sort = true, $exceptions = false, $fullPath = false) {
if (!$this->pwd()) {
return array();
}
$dirs = $files = array();
if (is_array($exceptions)) {
@ -214,6 +217,9 @@ class Folder extends Object {
* @access public
*/
function findRecursive($pattern = '.*', $sort = false) {
if (!$this->pwd()) {
return array();
}
$startsOn = $this->path;
$out = $this->_findRecursive($pattern, $sort);
$this->cd($startsOn);
@ -425,6 +431,9 @@ class Folder extends Object {
* @access public
*/
function tree($path, $exceptions = true, $type = null) {
if (!$this->pwd()) {
return array();
}
$original = $this->path;
$path = rtrim($path, DS);
$this->__files = array();
@ -554,6 +563,9 @@ class Folder extends Object {
if (!$path) {
$path = $this->pwd();
}
if (!$path) {
return null;
}
$path = Folder::slashTerm($path);
if (is_dir($path) === true) {
$normalFiles = glob($path . '*');
@ -598,6 +610,9 @@ class Folder extends Object {
* @access public
*/
function copy($options = array()) {
if (!$this->pwd()) {
return false;
}
$to = null;
if (is_string($options)) {
$to = $options;

View file

@ -95,7 +95,7 @@ class FolderTest extends CakeTestCase {
* @return void
*/
function testOperations() {
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'libs' . DS . 'templates' . DS . 'skel';
$path = TEST_CAKE_CORE_INCLUDE_PATH . 'console' . DS . 'templates' . DS . 'skel';
$Folder =& new Folder($path);
$result = is_dir($Folder->pwd());