PEAR_Command_Remote::doClearCache PHP Méthode

doClearCache() public méthode

public doClearCache ( $command, $options, $params )
    function doClearCache($command, $options, $params)
    {
        $cache_dir = $this->config->get('cache_dir');
        $verbose = $this->config->get('verbose');
        $output = '';
        if (!file_exists($cache_dir) || !is_dir($cache_dir)) {
            return $this->raiseError("{$cache_dir} does not exist or is not a directory");
        }
        if (!($dp = @opendir($cache_dir))) {
            return $this->raiseError("opendir({$cache_dir}) failed: {$php_errormsg}");
        }
        if ($verbose >= 1) {
            $output .= "reading directory {$cache_dir}\n";
        }
        $num = 0;
        while ($ent = readdir($dp)) {
            if (preg_match('/rest.cache(file|id)\\z/', $ent)) {
                $path = $cache_dir . DIRECTORY_SEPARATOR . $ent;
                if (file_exists($path)) {
                    $ok = @unlink($path);
                } else {
                    $ok = false;
                    $php_errormsg = '';
                }
                if ($ok) {
                    if ($verbose >= 2) {
                        $output .= "deleted {$path}\n";
                    }
                    $num++;
                } elseif ($verbose >= 1) {
                    $output .= "failed to delete {$path} {$php_errormsg}\n";
                }
            }
        }
        closedir($dp);
        if ($verbose >= 1) {
            $output .= "{$num} cache entries cleared\n";
        }
        $this->ui->outputData(rtrim($output), $command);
        return $num;
    }