Advertisement
Huymada

Washing

May 26th, 2022
1,095
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.01 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Washing
  4.  * Última revisão: 29-08-17
  5.  */
  6. class Washing {
  7.  
  8.     /**
  9.      * Smarty
  10.      */
  11.     public function __construct(...$item) {
  12.         if(empty($item)) {
  13.             self::clean(getcwd());
  14.         }
  15.         else {
  16.             foreach($item as $current) {
  17.                 self::list($current);
  18.             }
  19.         }
  20.     }
  21.  
  22.         /**
  23.          * List
  24.          */
  25.         private function list($item = false) {
  26.             if(isset($item) && is_string($item)) {
  27.                 self::clean($item);
  28.             }
  29.             else if(isset($item) && is_array($item)) {
  30.                 foreach($item as $current) {
  31.                     self::clean($current);
  32.                 }
  33.             }
  34.             else {
  35.                 self::clean(getcwd());
  36.             }
  37.         }
  38.  
  39.         /**
  40.          * Clean
  41.          */
  42.         private function clean($item) {
  43.             if(file_exists($item) && is_file($item)) {
  44.                 unlink($item);
  45.             }
  46.             else {
  47.                 foreach(new RecursiveIteratorIterator(new RecursiveDirectoryIterator($item, FilesystemIterator::SKIP_DOTS), RecursiveIteratorIterator::CHILD_FIRST) as $file) {
  48.                     $file->isFile() ? unlink($file->getPathname()) : rmdir($file->getPathname());
  49.                 }
  50.                 rmdir($item);
  51.             }
  52.         }
  53.  
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement