Add unregister to IoC-Contrainer
Signed-off-by: Steven Klar <steven.klar@mayflower.de>
This commit is contained in:
@@ -31,6 +31,19 @@ class IoC {
|
||||
static::$registry[$name] = compact('resolver', 'singleton');
|
||||
}
|
||||
|
||||
/**
|
||||
* Unregister an object
|
||||
*
|
||||
* @param string $name
|
||||
*/
|
||||
public static function unregister($name)
|
||||
{
|
||||
if (array_key_exists($name, static::$registry)) {
|
||||
unset(static::$registry[$name]);
|
||||
unset(static::$singletons[$name]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Determine if an object has been registered in the container.
|
||||
*
|
||||
@@ -141,6 +154,7 @@ class IoC {
|
||||
* @param string $type
|
||||
* @param array $parameters
|
||||
* @return mixed
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected static function build($type, $parameters = array())
|
||||
{
|
||||
@@ -193,7 +207,7 @@ class IoC {
|
||||
$dependency = $parameter->getClass();
|
||||
|
||||
// If the person passed in some parameters to the class
|
||||
// then we should probably use those instead of trying
|
||||
// then we should probably use those instead of trying
|
||||
// to resolve a new instance of the class
|
||||
if (count($arguments) > 0)
|
||||
{
|
||||
@@ -205,7 +219,7 @@ class IoC {
|
||||
}
|
||||
else
|
||||
{
|
||||
$dependencies[] = static::resolve($dependency->name);
|
||||
$dependencies[] = static::resolve($dependency->name);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -218,6 +232,7 @@ class IoC {
|
||||
*
|
||||
* @param ReflectionParameter
|
||||
* @return default value
|
||||
* @throws \Exception
|
||||
*/
|
||||
protected static function resolveNonClass($parameter)
|
||||
{
|
||||
@@ -229,6 +244,6 @@ class IoC {
|
||||
{
|
||||
throw new \Exception("Unresolvable dependency resolving [$parameter].");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user