PhpBrew\Utils::recursive_unlink PHP Méthode

    public static function recursive_unlink($path, Logger $logger)
    {
        $directoryIterator = new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS);
        $it = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::CHILD_FIRST);
        foreach ($it as $file) {
            $logger->debug('Deleting ' . $file->getPathname());
            if ($file->isDir()) {
                rmdir($file->getPathname());
            } else {
                unlink($file->getPathname());
            }
        }
        if (is_dir($path)) {
            rmdir($path);
        } elseif (is_file($path)) {
            unlink($path);
        }
    }

Usage Example

Exemple #1
0
 public function execute($buildName)
 {
     $prefix = Config::getVersionInstallPrefix($buildName);
     if (!file_exists($prefix)) {
         throw new Exception("{$prefix} does not exist.");
     }
     $prompter = new \CLIFramework\Prompter();
     $answer = $prompter->ask("Are you sure to delete {$buildName}?", array('Y', 'n'), 'Y');
     if (strtolower($answer) == "y") {
         Utils::recursive_unlink($prefix, $this->logger);
         $this->logger->info("{$buildName} is removed.  I hope you're not surprised. :)");
     } else {
         $this->logger->info("Let me guess, you drunk tonight.");
     }
 }
All Usage Examples Of PhpBrew\Utils::recursive_unlink