add container generics type hint

This commit is contained in:
sunxyw 2022-04-05 01:06:47 +08:00 committed by sunxyw
parent 9f7ebceeb9
commit 90290bee94
No known key found for this signature in database
GPG Key ID: CEA01A083E98C578
4 changed files with 14 additions and 11 deletions

View File

@ -13,12 +13,9 @@ class Container extends WorkerContainer
*/
protected $parent;
/**
* @param ContainerInterface $parent 父容器
*/
public function __construct(ContainerInterface $parent)
public function __construct()
{
$this->parent = $parent;
$this->parent = WorkerContainer::getInstance();
}
/**
@ -46,10 +43,11 @@ class Container extends WorkerContainer
/**
* 获取一个绑定的实例
*
* @template T
* @param string $abstract 类或接口名
* @param array $parameters 参数
* @throws EntryResolutionException
* @return mixed 实例
* @return T 实例
*/
public function make(string $abstract, array $parameters = [])
{

View File

@ -91,9 +91,10 @@ interface ContainerInterface extends PsrContainerInterface
/**
* 获取一个绑定的实例
*
* @template T
* @param string $abstract 类或接口名
* @param array $parameters 参数
* @return mixed 实例
* @return T 实例
*/
public function make(string $abstract, array $parameters = []);

View File

@ -210,10 +210,11 @@ class WorkerContainer implements ContainerInterface
/**
* 获取一个绑定的实例
*
* @template T
* @param string $abstract 类或接口名
* @param array $parameters 参数
* @throws EntryResolutionException
* @return mixed 实例
* @return T 实例
*/
public function make(string $abstract, array $parameters = [])
{

View File

@ -655,7 +655,9 @@ function container(): ContainerInterface
/**
* 解析类实例(使用容器)
*
* @return mixed
* @template T
* @param string<T> $abstract
* @return T
*/
function resolve(string $abstract, array $parameters = [])
{
@ -665,8 +667,9 @@ function resolve(string $abstract, array $parameters = [])
/**
* 获取容器实例
*
* @param null|string $abstract 类或接口名,不传入则返回容器实例
* @return ContainerInterface|mixed
* @template T
* @param null|string<T> $abstract
* @return ContainerInterface|T
*/
function app(string $abstract = null, array $parameters = [])
{