Permalink
Browse files

Closes #5734, Call static methods in Folder statically

git-svn-id: https://svn.cakephp.org/repo/branches/1.2.x.x@7937 3807eeeb-6ff5-0310-8944-8be069107fe0
  • Loading branch information...
1 parent e102144 commit 3daa7c9e1f90244b2974172da78f3671680e1243 @phpnut phpnut committed Dec 18, 2008
Showing with 90 additions and 83 deletions.
  1. +16 −16 cake/libs/folder.php
  2. +74 −67 cake/tests/cases/libs/folder.test.php
View
@@ -106,7 +106,7 @@ function __construct($path = false, $create = false, $mode = false) {
if (!file_exists($path) && $create === true) {
$this->create($path, $this->mode);
}
- if (!$this->isAbsolute($path)) {
+ if (!Folder::isAbsolute($path)) {
$path = realpath($path);
}
if (!empty($path)) {
@@ -163,7 +163,7 @@ function read($sort = true, $exceptions = false, $fullPath = false) {
continue;
}
- $path = $this->addPathElement($this->path, $item);
+ $path = Folder::addPathElement($this->path, $item);
if (is_dir($path)) {
$dirs[] = $fullPath ? $path : $item;
} else {
@@ -216,12 +216,12 @@ function _findRecursive($pattern, $sort = false) {
$found = array();
foreach ($files as $file) {
if (preg_match('/^' . $pattern . '$/i', $file)) {
- $found[] = $this->addPathElement($this->path, $file);
+ $found[] = Folder::addPathElement($this->path, $file);
}
}
$start = $this->path;
foreach ($dirs as $dir) {
- $this->cd($this->addPathElement($start, $dir));
+ $this->cd(Folder::addPathElement($start, $dir));
$found = array_merge($found, $this->findRecursive($pattern));
}
return $found;
@@ -301,7 +301,7 @@ function slashTerm($path) {
* @static
*/
function addPathElement($path, $element) {
- return $this->slashTerm($path) . $element;
+ return Folder::slashTerm($path) . $element;
}
/**
* Returns true if the File is in a given CakePath.
@@ -310,7 +310,7 @@ function addPathElement($path, $element) {
* @access public
*/
function inCakePath($path = '') {
- $dir = substr($this->slashTerm(ROOT), 0, -1);
+ $dir = substr(Folder::slashTerm(ROOT), 0, -1);
$newdir = $dir . $path;
return $this->inPath($newdir);
@@ -322,8 +322,8 @@ function inCakePath($path = '') {
* @access public
*/
function inPath($path = '', $reverse = false) {
- $dir = $this->slashTerm($path);
- $current = $this->slashTerm($this->pwd());
+ $dir = Folder::slashTerm($path);
+ $current = Folder::slashTerm($this->pwd());
if (!$reverse) {
$return = preg_match('/^(.*)' . preg_quote($dir, '/') . '(.*)/', $current);
@@ -484,7 +484,7 @@ function create($pathname, $mode = false) {
*/
function dirsize() {
$size = 0;
- $directory = $this->slashTerm($this->path);
+ $directory = Folder::slashTerm($this->path);
$stack = array($directory);
$count = count($stack);
for ($i = 0, $j = $count; $i < $j; ++$i) {
@@ -500,7 +500,7 @@ function dirsize() {
$add = $stack[$i] . $entry;
if (is_dir($stack[$i] . $entry)) {
- $add = $this->slashTerm($add);
+ $add = Folder::slashTerm($add);
}
$stack[] = $add;
}
@@ -522,7 +522,7 @@ function delete($path = null) {
if (!$path) {
$path = $this->pwd();
}
- $path = $this->slashTerm($path);
+ $path = Folder::slashTerm($path);
if (is_dir($path) === true) {
$normalFiles = glob($path . '*');
$hiddenFiles = glob($path . '\.?*');
@@ -590,8 +590,8 @@ function copy($options = array()) {
if ($handle = @opendir($fromDir)) {
while (false !== ($item = readdir($handle))) {
if (!in_array($item, $exceptions)) {
- $from = $this->addPathElement($fromDir, $item);
- $to = $this->addPathElement($toDir, $item);
+ $from = Folder::addPathElement($fromDir, $item);
+ $to = Folder::addPathElement($toDir, $item);
if (is_file($from)) {
if (copy($from, $to)) {
chmod($to, intval($mode, 8));
@@ -722,8 +722,8 @@ function rm($path) {
function realpath($path) {
$path = str_replace('/', DS, trim($path));
if (strpos($path, '..') === false) {
- if (!$this->isAbsolute($path)) {
- $path = $this->addPathElement($this->path, $path);
+ if (!Folder::isAbsolute($path)) {
+ $path = Folder::addPathElement($this->path, $path);
}
return $path;
}
@@ -750,7 +750,7 @@ function realpath($path) {
}
$newpath .= implode(DS, $newparts);
- return $this->slashTerm($newpath);
+ return Folder::slashTerm($newpath);
}
/**
* Returns true if given $path ends in a slash (i.e. is slash-terminated).
@@ -45,7 +45,7 @@ function testBasic() {
$result = $Folder->pwd();
$this->assertEqual($result, $path);
- $result = $Folder->addPathElement($path, 'test');
+ $result = Folder::addPathElement($path, 'test');
$expected = $path . DS . 'test';
$this->assertEqual($result, $expected);
@@ -71,7 +71,7 @@ function testInPath() {
$result = $Folder->pwd();
$this->assertEqual($result, $path);
- $result = $Folder->isSlashTerm($inside);
+ $result = Folder::isSlashTerm($inside);
$this->assertTrue($result);
$result = $Folder->realpath('tests/');
@@ -286,9 +286,9 @@ function testFolderTree() {
* @return void
*/
function testWindowsPath() {
- $Folder =& new Folder();
- $this->assertTrue($Folder->isWindowsPath('C:\cake'));
- $this->assertTrue($Folder->isWindowsPath('c:\cake'));
+ $this->assertFalse(Folder::isWindowsPath('0:\\cake\\is\\awesome'));
+ $this->assertTrue(Folder::isWindowsPath('C:\\cake\\is\\awesome'));
+ $this->assertTrue(Folder::isWindowsPath('d:\\cake\\is\\awesome'));
}
/**
* testIsAbsolute method
@@ -297,10 +297,18 @@ function testWindowsPath() {
* @return void
*/
function testIsAbsolute() {
- $Folder =& new Folder();
- $this->assertTrue($Folder->isAbsolute('C:\cake'));
- $this->assertTrue($Folder->isAbsolute('/usr/local'));
- $this->assertFalse($Folder->isAbsolute('cake/'));
+ $this->assertFalse(Folder::isAbsolute('path/to/file'));
+ $this->assertFalse(Folder::isAbsolute('cake/'));
+ $this->assertFalse(Folder::isAbsolute('path\\to\\file'));
+ $this->assertFalse(Folder::isAbsolute('0:\\path\\to\\file'));
+ $this->assertFalse(Folder::isAbsolute('\\path/to/file'));
+ $this->assertFalse(Folder::isAbsolute('\\path\\to\\file'));
+
+ $this->assertTrue(Folder::isAbsolute('/usr/local'));
+ $this->assertTrue(Folder::isAbsolute('//path/to/file'));
+ $this->assertTrue(Folder::isAbsolute('C:\\cake'));
+ $this->assertTrue(Folder::isAbsolute('C:\\path\\to\\file'));
+ $this->assertTrue(Folder::isAbsolute('d:\\path\\to\\file'));
}
/**
* testIsSlashTerm method
@@ -309,18 +317,18 @@ function testIsAbsolute() {
* @return void
*/
function testIsSlashTerm() {
- $Folder =& new Folder();
- $this->assertTrue($Folder->isSlashTerm('C:\cake\\'));
- $this->assertTrue($Folder->isSlashTerm('/usr/local/'));
- $this->assertFalse($Folder->isSlashTerm('cake'));
+ $this->assertFalse(Folder::isSlashTerm('cake'));
+
+ $this->assertTrue(Folder::isSlashTerm('C:\\cake\\'));
+ $this->assertTrue(Folder::isSlashTerm('/usr/local/'));
}
/**
* testStatic method
*
* @access public
* @return void
*/
- function testStatic() {
+ function testSlashTerm() {
$result = Folder::slashTerm('/path/to/file');
$this->assertEqual($result, '/path/to/file/');
}
@@ -335,11 +343,11 @@ function testNormalizePath() {
$result = Folder::normalizePath($path);
$this->assertEqual($result, '/');
- $path = '\path\to\file';
+ $path = '\\path\\\to\\\file';
$result = Folder::normalizePath($path);
$this->assertEqual($result, '/');
- $path = 'C:\path\to\file';
+ $path = 'C:\\path\\to\\file';
$result = Folder::normalizePath($path);
$this->assertEqual($result, '\\');
}
@@ -349,16 +357,16 @@ function testNormalizePath() {
* @access public
* @return void
*/
- function correctSlashFor() {
+ function testCorrectSlashFor() {
$path = '/path/to/file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '/');
- $path = '\path\to\file';
+ $path = '\\path\\to\\file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '/');
- $path = 'C:\path\to\file';
+ $path = 'C:\\path\to\\file';
$result = Folder::correctSlashFor($path);
$this->assertEqual($result, '\\');
}
@@ -371,7 +379,7 @@ function correctSlashFor() {
function testInCakePath() {
$Folder =& new Folder();
$Folder->cd(ROOT);
- $path = 'C:\path\to\file';
+ $path = 'C:\\path\\to\\file';
$result = $Folder->inCakePath($path);
$this->assertFalse($result);
@@ -393,39 +401,39 @@ function testInCakePath() {
* @return void
*/
function testFind() {
- $folder =& new Folder();
- $folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
- $result = $folder->find();
+ $Folder =& new Folder();
+ $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
+ $result = $Folder->find();
$expected = array('config.php', 'paths.php');
$this->assertIdentical($result, $expected);
- $result = $folder->find('.*\.php');
+ $result = $Folder->find('.*\.php');
$expected = array('config.php', 'paths.php');
$this->assertIdentical($result, $expected);
- $result = $folder->find('.*ig\.php');
+ $result = $Folder->find('.*ig\.php');
$expected = array('config.php');
$this->assertIdentical($result, $expected);
- $result = $folder->find('paths\.php');
+ $result = $Folder->find('paths\.php');
$expected = array('paths.php');
$this->assertIdentical($result, $expected);
- $folder->cd(TMP);
- $file = new File($folder->pwd() . DS . 'paths.php', true);
- $folder->mkdir($folder->pwd() . DS . 'testme');
- $folder->cd('testme');
- $result = $folder->find('paths\.php');
+ $Folder->cd(TMP);
+ $file = new File($Folder->pwd() . DS . 'paths.php', true);
+ $Folder->mkdir($Folder->pwd() . DS . 'testme');
+ $Folder->cd('testme');
+ $result = $Folder->find('paths\.php');
$expected = array();
$this->assertIdentical($result, $expected);
- $folder->cd($folder->pwd() . '/..');
- $result = $folder->find('paths\.php');
+ $Folder->cd($Folder->pwd() . '/..');
+ $result = $Folder->find('paths\.php');
$expected = array('paths.php');
$this->assertIdentical($result, $expected);
- $folder->cd(TMP);
- $folder->delete($folder->pwd() . DS . 'testme');
+ $Folder->cd(TMP);
+ $Folder->delete($Folder->pwd() . DS . 'testme');
$file->delete();
}
/**
@@ -435,41 +443,41 @@ function testFind() {
* @return void
*/
function testFindRecursive() {
- $folder =& new Folder();
- $folder->cd(TEST_CAKE_CORE_INCLUDE_PATH);
- $result = $folder->findRecursive('(config|paths)\.php');
+ $Folder =& new Folder();
+ $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH);
+ $result = $Folder->findRecursive('(config|paths)\.php');
$expected = array(
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'config.php',
TEST_CAKE_CORE_INCLUDE_PATH . 'config' . DS . 'paths.php'
);
$this->assertIdentical($result, $expected);
- $folder->cd(TMP);
- $folder->mkdir($folder->pwd() . DS . 'testme');
- $folder->cd('testme');
- $file =& new File($folder->pwd() . DS . 'paths.php');
- $file->create();
- $folder->cd(TMP . 'sessions');
- $result = $folder->findRecursive('paths\.php');
+ $Folder->cd(TMP);
+ $Folder->mkdir($Folder->pwd() . DS . 'testme');
+ $Folder->cd('testme');
+ $File =& new File($Folder->pwd() . DS . 'paths.php');
+ $File->create();
+ $Folder->cd(TMP . 'sessions');
+ $result = $Folder->findRecursive('paths\.php');
$expected = array();
$this->assertIdentical($result, $expected);
- $folder->cd(TMP . 'testme');
- $file =& new File($folder->pwd() . DS . 'my.php');
- $file->create();
- $folder->cd($folder->pwd() . '/../..');
+ $Folder->cd(TMP . 'testme');
+ $File =& new File($Folder->pwd() . DS . 'my.php');
+ $File->create();
+ $Folder->cd($Folder->pwd() . '/../..');
- $result = $folder->findRecursive('(paths|my)\.php');
+ $result = $Folder->findRecursive('(paths|my)\.php');
$expected = array(
TMP . 'testme' . DS . 'my.php',
TMP . 'testme' . DS . 'paths.php'
);
$this->assertIdentical($result, $expected);
- $folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
- $folder->cd(TMP);
- $folder->delete($folder->pwd() . DS . 'testme');
- $file->delete();
+ $Folder->cd(TEST_CAKE_CORE_INCLUDE_PATH . 'config');
+ $Folder->cd(TMP);
+ $Folder->delete($Folder->pwd() . DS . 'testme');
+ $File->delete();
}
/**
* testConstructWithNonExistantPath method
@@ -478,10 +486,10 @@ function testFindRecursive() {
* @return void
*/
function testConstructWithNonExistantPath() {
- $folder =& new Folder(TMP . 'config_non_existant', true);
+ $Folder =& new Folder(TMP . 'config_non_existant', true);
$this->assertTrue(is_dir(TMP . 'config_non_existant'));
- $folder->cd(TMP);
- $folder->delete($folder->pwd() . 'config_non_existant');
+ $Folder->cd(TMP);
+ $Folder->delete($Folder->pwd() . 'config_non_existant');
}
/**
* testDirSize method
@@ -490,19 +498,18 @@ function testConstructWithNonExistantPath() {
* @return void
*/
function testDirSize() {
- $folder =& new Folder(TMP . 'config_non_existant', true);
- $this->assertEqual($folder->dirSize(), 0);
+ $Folder =& new Folder(TMP . 'config_non_existant', true);
+ $this->assertEqual($Folder->dirSize(), 0);
- $file =& new File($folder->pwd() . DS . 'my.php', true, 0777);
- $file->create();
- $file->write('something here');
- $file->close();
- $this->assertEqual($folder->dirSize(), 14);
+ $File =& new File($Folder->pwd() . DS . 'my.php', true, 0777);
+ $File->create();
+ $File->write('something here');
+ $File->close();
+ $this->assertEqual($Folder->dirSize(), 14);
- $folder->cd(TMP);
- $folder->delete($folder->pwd() . 'config_non_existant');
+ $Folder->cd(TMP);
+ $Folder->delete($Folder->pwd() . 'config_non_existant');
}
-
/**
* testDelete method
*

0 comments on commit 3daa7c9

Please sign in to comment.