本文整理汇总了PHP中RecursiveDirectoryIterator::getRealPath方法的典型用法代码示例。如果您正苦于以下问题:PHP RecursiveDirectoryIterator::getRealPath方法的具体用法?PHP RecursiveDirectoryIterator::getRealPath怎么用?PHP RecursiveDirectoryIterator::getRealPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类RecursiveDirectoryIterator
的用法示例。
在下文中一共展示了RecursiveDirectoryIterator::getRealPath方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: delete
/**
* Force deletion on a cached resource.
*
* @param {string} $key Identifier of target cache.
* @param {?string} $hash Target revision to delete, all revisions will be deleted if omitted.
*/
public static function delete($key, $hash = '*')
{
$res = self::resolve($key, $hash);
// Skip the delete if nothing is found.
if ($res === null) {
return;
}
if ($res->isFile()) {
// Remove target revision(s).
if (!$res->isWritable()) {
Log::warning('Target file is not writable, deletion skipped.');
} else {
$path = $res->getRealPath();
unlink($path);
$path = dirname($path);
// Remove the directory if empty.
$res = new \RecursiveDirectoryIterator($path, \FilesystemIterator::KEY_AS_PATHNAME | \FilesystemIterator::CURRENT_AS_FILEINFO | \FilesystemIterator::SKIP_DOTS);
if ($res->isDir() && !$res->hasChildren()) {
rmdir($path);
}
}
} else {
if ($res->isDir()) {
$cacheDirectory = $res->getRealPath();
foreach ($res as $file) {
if ($file->isFile()) {
unlink($file->getRealPath());
} else {
if ($file->isDir()) {
rmdir($file->getRealPath());
}
}
}
rmdir($cacheDirectory);
}
}
}