This commit is contained in:
2023-04-07 00:04:59 +08:00
parent 9a8d2b8bea
commit 06e2b691bb
+15 -2
View File
@@ -12,7 +12,6 @@ namespace Kiri\Di;
use Closure;
use Exception;
use Kiri;
use Kiri\Di\ContainerInterface;
use ReflectionClass;
use ReflectionException;
use ReflectionFunction;
@@ -78,6 +77,20 @@ class Container implements ContainerInterface
}
/**
* @param $id
* @return mixed
* @throws Exception
*/
public function copy($id): mixed
{
if ($id == ContainerInterface::class) {
return $this;
}
return clone $this->make($id, [], []);
}
/**
* @return static
*/
@@ -148,7 +161,7 @@ class Container implements ContainerInterface
if (is_string($object)) {
$this->_interfaces[$interface] = $object;
} else {
$className = get_class($object);
$className = get_class($object);
$this->_interfaces[$interface] = $className;
$this->_singletons[$className] = $object;
}