summaryrefslogtreecommitdiff
path: root/app/Core/Tool.php
diff options
context:
space:
mode:
Diffstat (limited to 'app/Core/Tool.php')
-rw-r--r--app/Core/Tool.php28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/Core/Tool.php b/app/Core/Tool.php
index bfa6c955..9b8820eb 100644
--- a/app/Core/Tool.php
+++ b/app/Core/Tool.php
@@ -3,6 +3,8 @@
namespace Kanboard\Core;
use Pimple\Container;
+use RecursiveDirectoryIterator;
+use RecursiveIteratorIterator;
/**
* Tool class
@@ -13,6 +15,32 @@ use Pimple\Container;
class Tool
{
/**
+ * Remove recursively a directory
+ *
+ * @static
+ * @access public
+ * @param string $directory
+ * @param bool $removeDirectory
+ */
+ public static function removeAllFiles($directory, $removeDirectory = true)
+ {
+ $it = new RecursiveDirectoryIterator($directory, RecursiveDirectoryIterator::SKIP_DOTS);
+ $files = new RecursiveIteratorIterator($it, RecursiveIteratorIterator::CHILD_FIRST);
+
+ foreach ($files as $file) {
+ if ($file->isDir()) {
+ rmdir($file->getRealPath());
+ } else {
+ unlink($file->getRealPath());
+ }
+ }
+
+ if ($removeDirectory) {
+ rmdir($directory);
+ }
+ }
+
+ /**
* Build dependency injection container from an array
*
* @static