This commit is contained in:
2026-04-17 16:30:52 +08:00
parent 754042b994
commit d23e55391e
5 changed files with 600 additions and 183 deletions
+54
View File
@@ -153,6 +153,60 @@ class Container implements ContainerInterface
}
public function forgetReflection(string $className): void
{
unset($this->_reflection[$className]);
}
public function forgetMethodParams(string $className, ?string $method = null): void
{
if (!isset($this->_parameters[$className])) {
return;
}
if ($method === null) {
unset($this->_parameters[$className]);
return;
}
unset($this->_parameters[$className][$method]);
if ($this->_parameters[$className] === []) {
unset($this->_parameters[$className]);
}
}
public function forgetClass(string $className): void
{
unset($this->_singletons[$className]);
$this->forgetReflection($className);
$this->forgetMethodParams($className);
}
public function forgetNamespace(string $prefix): void
{
foreach (array_keys($this->_singletons) as $className) {
if ($className !== ContainerInterface::class && str_starts_with($className, $prefix)) {
unset($this->_singletons[$className]);
}
}
foreach (array_keys($this->_reflection) as $className) {
if (str_starts_with($className, $prefix)) {
unset($this->_reflection[$className]);
}
}
foreach (array_keys($this->_parameters) as $className) {
if (str_starts_with($className, $prefix)) {
unset($this->_parameters[$className]);
}
}
}
/**
* @param string $className
* @param array $construct