/** * * Support method to recursively descend into cache subdirectories and * remove their contents. * * @param string $dir The directory to remove. * * @return void * */ protected function _deleteAll($dir) { // get the list of files in the directory, suppress warnings. $list = (array) @scandir($dir, null, $this->_context); // delete each file, and recurse into subdirectories foreach ($list as $item) { // ignore dot-dirs if ($item == '.' || $item == '..') { continue; } // set up the absolute path to the item $item = $dir . DIRECTORY_SEPARATOR . $item; // how to handle the item? if (is_dir($item)) { // recurse into each subdirectory ... $this->_deleteAll($item); // ... then remove it Solar_Dir::rmdir($item); } else { // remove the cache file @unlink($item, $this->_context); } } }
/** * * Removes a file or directory symbolic link. * * Actually, this will remove the file or directory even if it's not * a symbolic link, so be careful with it. * * @param string $path The symbolic link to remove. * * @return void * */ public static function remove($path) { // are we on a windows system prior to NT6? $is_win = strtolower(substr(PHP_OS, 0, 3)) == 'win'; if ($is_win && php_uname('r') < 6) { throw Solar_Symlink::_exception('ERR_WINDOWS_VERSION'); } // does the path exist for removal? $is_dir = Solar_Dir::exists($path); $is_file = Solar_File::exists($path); if (!$is_dir && !$is_file) { throw Solar_Symlink::_exception('ERR_PATH_NOT_FOUND', array('path' => $path)); } // how to remove? if ($is_win) { // have to double up on removals because windows reports all // symlinks as files, even if they point to dirs. @unlink($path); Solar_Dir::rmdir($path); } else { // unix file or dir @unlink($path); } }