改名
This commit is contained in:
+32
-4
@@ -11,14 +11,18 @@ namespace Kiri\Di;
|
|||||||
|
|
||||||
use Annotation\Inject;
|
use Annotation\Inject;
|
||||||
use Exception;
|
use Exception;
|
||||||
|
use Kiri\Abstracts\BaseObject;
|
||||||
|
use Kiri\Exception\NotFindClassException;
|
||||||
|
use Kiri\Kiri;
|
||||||
use ReflectionClass;
|
use ReflectionClass;
|
||||||
use ReflectionException;
|
use ReflectionException;
|
||||||
use ReflectionFunction;
|
use ReflectionFunction;
|
||||||
use ReflectionMethod;
|
use ReflectionMethod;
|
||||||
use ReflectionProperty;
|
use ReflectionProperty;
|
||||||
use Kiri\Abstracts\BaseObject;
|
use Server\Constrict\Request;
|
||||||
use Kiri\Exception\NotFindClassException;
|
use Server\Constrict\Response;
|
||||||
use Kiri\Kiri;
|
use Server\RequestInterface;
|
||||||
|
use Server\ResponseInterface;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class Container
|
* Class Container
|
||||||
@@ -55,6 +59,13 @@ class Container extends BaseObject
|
|||||||
private array $_parameters = [];
|
private array $_parameters = [];
|
||||||
|
|
||||||
|
|
||||||
|
/** @var array|string[] */
|
||||||
|
private array $_interfaces = [
|
||||||
|
RequestInterface::class => Request::class,
|
||||||
|
ResponseInterface::class => Response::class
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @var array
|
* @var array
|
||||||
*
|
*
|
||||||
@@ -68,12 +79,14 @@ class Container extends BaseObject
|
|||||||
* @param array $config
|
* @param array $config
|
||||||
*
|
*
|
||||||
* @return mixed
|
* @return mixed
|
||||||
* @throws NotFindClassException
|
|
||||||
* @throws ReflectionException
|
* @throws ReflectionException
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
public function get($class, array $constrict = [], array $config = []): mixed
|
public function get($class, array $constrict = [], array $config = []): mixed
|
||||||
{
|
{
|
||||||
|
if ($this->_isInterface($class)) {
|
||||||
|
$class = $this->_interfaces[$class];
|
||||||
|
}
|
||||||
if (!isset($this->_singletons[$class])) {
|
if (!isset($this->_singletons[$class])) {
|
||||||
$this->_singletons[$class] = $this->resolve($class, $constrict, $config);
|
$this->_singletons[$class] = $this->resolve($class, $constrict, $config);
|
||||||
}
|
}
|
||||||
@@ -81,6 +94,21 @@ class Container extends BaseObject
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param $class
|
||||||
|
* @return bool
|
||||||
|
* @throws ReflectionException
|
||||||
|
*/
|
||||||
|
private function _isInterface($class): bool
|
||||||
|
{
|
||||||
|
$reflect = $this->getReflect($class);
|
||||||
|
if ($reflect->isInterface()) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param $class
|
* @param $class
|
||||||
* @param array $constrict
|
* @param array $constrict
|
||||||
|
|||||||
Reference in New Issue
Block a user