Pagekit\Filesystem\Filesystem::delete PHP Method

delete() public method

Deletes a file.
public delete ( string | array $files ) : boolean
$files string | array
return boolean
    public function delete($files)
    {
        $files = (array) $files;
        foreach ($files as $file) {
            $file = $this->getPathInfo($file, 'pathname');
            if (is_dir($file)) {
                if (substr($file, -1) != '/') {
                    $file .= '/';
                }
                foreach ($this->listDir($file) as $name) {
                    if (!$this->delete($file . $name)) {
                        return false;
                    }
                }
                if (!@rmdir($file)) {
                    return false;
                }
            } elseif (!@unlink($file)) {
                return false;
            }
        }
        return true;
    }

Usage Example

Beispiel #1
0
 /**
  * @param $uninstall
  * @return bool
  */
 public function uninstall($uninstall)
 {
     foreach ((array) $uninstall as $name) {
         if (!($package = App::package($name))) {
             throw new \RuntimeException(__('Unable to find "%name%".', ['%name%' => $name]));
         }
         $this->disable($package);
         $this->trigger('uninstall', $this->loadScripts($package));
         App::config('system')->remove('packages.' . $package->get('module'));
         if ($this->composer->isInstalled($package->getName())) {
             $this->composer->uninstall($package->getName());
         } else {
             if (!($path = $package->get('path'))) {
                 throw new \RuntimeException(__('Package path is missing.'));
             }
             $this->output->writeln(__("Removing package folder."));
             $file = new Filesystem();
             $file->delete($path);
             @rmdir(dirname($path));
         }
     }
 }