This commit is contained in:
2026-06-24 20:11:11 +08:00
parent fead1203be
commit 0087115bdc
2 changed files with 266 additions and 0 deletions
+33
View File
@@ -105,6 +105,39 @@ class DeferRegistry
}
/**
* 移除指定类的所有 Defer 注册,用于热重载时清理失效类
* @param string $class
* @return void
*/
public static function removeClass(string $class): void
{
$prefix = $class . '::';
foreach (array_keys(self::$registry) as $key) {
if (str_starts_with($key, $prefix)) {
unset(self::$registry[$key]);
}
}
}
/**
* 获取注册表统计信息,用于内存监控
* @return array{totalKeys: int, totalDefer: int}
*/
public static function getStats(): array
{
$totalDefer = 0;
foreach (self::$registry as $defers) {
$totalDefer += count($defers);
}
return [
'totalKeys' => count(self::$registry),
'totalDefer' => $totalDefer,
];
}
/**
* @return void
*/