Updated delete method to support recrusive deletes

This commit is contained in:
Eldad Fux committed 2020-05-26 20:11:20 +03:00
1 parent 41ecda5ea3
commit 419fabd80a
6 files changed
+103 -7

No files matched your search

+2 -1
View File
@@ -95,10 +95,11 @@ abstract class Device
* @see http://php.net/manual/en/function.filesize.php
*
* @param string $path
* @param bool $recrusive
*
* @return bool
*/
abstract public function delete(string $path):bool;
abstract public function delete(string $path, bool $recrusive):bool;
/**
* Returns given file path its size.
+16 -2
View File
@@ -151,12 +151,26 @@ class Local extends Device
* @see http://php.net/manual/en/function.filesize.php
*
* @param string $path
* @param bool $recrusive
*
* @return bool
*/
public function delete(string $path):bool
public function delete(string $path, bool $recrusive = false):bool
{
return unlink($path);
if(is_dir($path) && $recrusive) {
$files = glob($path.'*', GLOB_MARK); // GLOB_MARK adds a slash to directories returned
foreach($files as $file) {
$this->delete($file);
}
rmdir($path);
}
elseif(is_file($path)) {
return unlink($path);
}
return false;
}
/**