Dropped file class
All it contained was a method to remove a directory recursively. Moved files over to joshtronic/php-rmr (rm -r)
This commit is contained in:
parent
68b2f83379
commit
ea28dbbc5e
2 changed files with 0 additions and 135 deletions
72
src/File.php
72
src/File.php
|
@ -1,72 +0,0 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* File Utility Collection
|
||||
*
|
||||
* Licensed under The MIT License
|
||||
* Redistribution of these files must retain the above copyright notice.
|
||||
*
|
||||
* @copyright Copyright 2007-2014, Josh Sherman
|
||||
* @license http://www.opensource.org/licenses/mit-license.html
|
||||
* @link https://github.com/joshtronic/pickles
|
||||
* @package Pickles
|
||||
*/
|
||||
|
||||
namespace Pickles;
|
||||
|
||||
/**
|
||||
* File Class
|
||||
*
|
||||
* Just a simple collection of static functions to accomplish some of the more
|
||||
* redundant file related manipulation.
|
||||
*/
|
||||
class File
|
||||
{
|
||||
/**
|
||||
* Remove a Directory, Recursively
|
||||
*
|
||||
* Removes a directory by emptying all of the contents recursively and then
|
||||
* removing the directory, as PHP will not let you rmdir() on ain non-empty
|
||||
* directory. Use with caution, seriously.
|
||||
*
|
||||
* @static
|
||||
* @param string $directory directory to remove
|
||||
* @return boolean status of the final rmdir();
|
||||
*/
|
||||
public static function removeDirectory($directory)
|
||||
{
|
||||
// If directory is a directory, read in all the files
|
||||
if (is_dir($directory))
|
||||
{
|
||||
if (substr($directory, -1) != '/')
|
||||
{
|
||||
$directory .= '/';
|
||||
}
|
||||
|
||||
$files = scandir($directory);
|
||||
|
||||
// Loop through said files, check for directories, and unlink files
|
||||
foreach ($files as $file)
|
||||
{
|
||||
if (!in_array($file, ['.', '..']))
|
||||
{
|
||||
if (is_dir($directory . $file))
|
||||
{
|
||||
File::removeDirectory($directory . $file);
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($directory . $file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
rmdir($directory);
|
||||
}
|
||||
else
|
||||
{
|
||||
unlink($directory);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1,63 +0,0 @@
|
|||
<?php
|
||||
|
||||
class FileTest extends PHPUnit_Framework_TestCase
|
||||
{
|
||||
public static function setUpBeforeClass()
|
||||
{
|
||||
// Using actual filesystem because you can't chdir with vfs://
|
||||
$directory = '/tmp/pickles-fs/filetest/test/test';
|
||||
|
||||
if (!file_exists($directory))
|
||||
{
|
||||
mkdir($directory, 0777, true);
|
||||
}
|
||||
}
|
||||
|
||||
public static function tearDownAfterClass()
|
||||
{
|
||||
Pickles\File::removeDirectory('/tmp/pickles-fs');
|
||||
}
|
||||
|
||||
public function testRemoveDirectory()
|
||||
{
|
||||
$directory = '/tmp/pickles-fs/filetest/';
|
||||
|
||||
touch($directory . 'ing');
|
||||
touch($directory . 'test/ing');
|
||||
touch($directory . 'test/test/ing');
|
||||
|
||||
Pickles\File::removeDirectory($directory);
|
||||
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
|
||||
public function testMissingTrailingSlash()
|
||||
{
|
||||
$directory = '/tmp/pickles-fs/missing';
|
||||
|
||||
mkdir($directory, 0777, true);
|
||||
touch('/tmp/pickles-fs/missing/slash');
|
||||
|
||||
Pickles\File::removeDirectory($directory);
|
||||
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
|
||||
public function testRemoveFileNotDirectory()
|
||||
{
|
||||
$directory = '/tmp/pickles-fs/dir';
|
||||
$file = '/tmp/pickles-fs/dir/file';
|
||||
|
||||
mkdir($directory, 0777, true);
|
||||
touch($file);
|
||||
|
||||
Pickles\File::removeDirectory($file);
|
||||
|
||||
$this->assertFalse(file_exists($file));
|
||||
|
||||
Pickles\File::removeDirectory($directory);
|
||||
|
||||
$this->assertFalse(file_exists($directory));
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue