protected function deleteFromDir(
        /*# string */ $dir,
        /*# int */ $maxlife = 0,
        /*# bool */ $removeDir = false
    )/*# : bool */ {
        $now = time();
        if (is_dir($dir)) {
            $files = scandir($dir);
            foreach ($files as $file) {
                if ($file == "." || $file == "..") {
                    continue;
                }
                $sub = $dir . DIRECTORY_SEPARATOR . $file;
                $res = true;
                if (is_dir($sub)) {
                    $res = $this->deleteFromDir($sub, $maxlife, true);
                } else {
                    if (!$maxlife || $now - filemtime($sub) > $maxlife) {
                        $res = unlink($sub);
                    }
                }
                if ($res === false) {
                    return $this->falseAndSetError(
                        Message::get(Message::CACHE_FAIL_DELETE, $sub),
                        Message::CACHE_FAIL_DELETE
                    );
                }
            }
            if ($removeDir && ! @rmdir($dir)) {
                return $this->falseAndSetError(
                    Message::get(Message::CACHE_FAIL_DELETE, $dir),
                    Message::CACHE_FAIL_DELETE
                );
            }
        }
        return true;
    }
protected function deleteFromDir(
        /*# string */ $dir,
        /*# int */ $maxlife = 0,
        /*# bool */ $removeDir = false
    )/*# : bool */ {
        $now = time();
        if (is_dir($dir)) {
            $files = scandir($dir);
            foreach ($files as $file) {
                if ($file == "." || $file == "..") {
                    continue;
                }
                $sub = $dir . DIRECTORY_SEPARATOR . $file;
                $res = true;
                if (is_dir($sub)) {
                    $res = $this->deleteFromDir($sub, $maxlife, true);
                } else {
                    if (!$maxlife || $now - filemtime($sub) > $maxlife) {
                        $res = unlink($sub);
                    }
                }
                if ($res === false) {
                    return $this->falseAndSetError(
                        Message::get(Message::CACHE_FAIL_DELETE, $sub),
                        Message::CACHE_FAIL_DELETE
                    );
                }
            }
            if ($removeDir && ! @rmdir($dir)) {
                return $this->falseAndSetError(
                    Message::get(Message::CACHE_FAIL_DELETE, $dir),
                    Message::CACHE_FAIL_DELETE
                );
            }
        }
        return true;
    }
protected function deleteFromDir ( /*# string */ $ dir , /*# int */ $ maxlife = 0 , /*# bool */ $ removeDir = false ) /*# : bool */ { $ now = time ( ) ; if ( is_dir ( $ dir ) ) { $ files = scandir ( $ dir ) ; foreach ( $ files as $ file ) { if ( $ file == "." || $ file == ".." ) { continue ; } $ sub = $ dir . DIRECTORY_SEPARATOR . $ file ; $ res = true ; if ( is_dir ( $ sub ) ) { $ res = $ this -> deleteFromDir ( $ sub , $ maxlife , true ) ; } else { if ( ! $ maxlife || $ now - filemtime ( $ sub ) > $ maxlife ) { $ res = unlink ( $ sub ) ; } } if ( $ res === false ) { return $ this -> falseAndSetError ( Message :: get ( Message :: CACHE_FAIL_DELETE , $ sub ) , Message :: CACHE_FAIL_DELETE ) ; } } if ( $ removeDir && ! @ rmdir ( $ dir ) ) { return $ this -> falseAndSetError ( Message :: get ( Message :: CACHE_FAIL_DELETE , $ dir ) , Message :: CACHE_FAIL_DELETE ) ; } } return true ; }
Remove all contents under one directory

@param  string $dir directory
@param  int $maxlife delete those older than $maxlife seconds
@param  bool $removeDir remove the directory also
@return bool
@access protected
Remove all contents under one directory