Zhamao Framework  3.0.0-beta1
A high-performance chatbot + web framework
ZM\Container 命名空间参考

结构体

class  BoundMethod
 
class  ClassAliasHelper
 
class  Container
 
interface  ContainerInterface
 
class  ContainerServicesProvider
 
class  EntryNotFoundException
 
class  EntryResolutionException
 
class  WorkerContainer
 

函数

 __construct ()
 
 bound (string $abstract)
 
 getAlias (string $abstract)
 
 alias (string $abstract, string $alias)
 
 bind (string $abstract, $concrete=null, bool $shared=false)
 
 bindIf (string $abstract, $concrete=null, bool $shared=false)
 
 singleton (string $abstract, $concrete=null)
 
 singletonIf (string $abstract, $concrete=null)
 
 instance (string $abstract, mixed $instance)
 
 factory (string $abstract)
 
 flush ()
 
 make (string $abstract, array $parameters=[])
 
 build (\Closure|string $concrete)
 
 call (callable|string $callback, array $parameters=[], string $default_method=null)
 
 get (string $id)
 
 has (string $id)
 
 extend (string $abstract, \Closure $closure)
 
 getLogPrefix ()
 
 setLogPrefix (string $prefix)
 
 getExtenders (string $abstract)
 
 isAlias (string $name)
 
 dropStaleInstances (string $abstract)
 
 getClosure (string $abstract, string $concrete)
 
 getLastParameterOverride ()
 
 notInstantiable (string $concrete, string $reason='')
 
 resolveDependencies (array $dependencies)
 
 hasParameterOverride (\ReflectionParameter $parameter)
 
 getParameterOverride (\ReflectionParameter $parameter)
 
 hasParameterTypeOverride (\ReflectionParameter $parameter)
 
 getParameterTypeOverride (\ReflectionParameter $parameter)
 
 resolvePrimitive (\ReflectionParameter $parameter)
 
 resolveClass (\ReflectionParameter $parameter)
 
 getConcrete (string $abstract)
 
 isBuildable (mixed $concrete, string $abstract)
 
 isShared (string $abstract)
 
 shouldLog ()
 
 log (string $message)
 

变量

trait ContainerTrait
 
array $build_stack = []
 
array $with = []
 
string $log_prefix
 

函数说明

◆ __construct()

ZM\Container\__construct ( )
函数调用图:

◆ alias()

ZM\Container\alias ( string  $abstract,
string  $alias 
)

注册一个类别名

参数
string$abstract类或接口名
string$alias别名

◆ bind()

ZM\Container\bind ( string  $abstract,
  $concrete = null,
bool  $shared = false 
)

注册绑定

参数
string$abstract类或接口名
null | \Closure | string$concrete返回类实例的闭包,或是类名
bool$shared是否共享
函数调用图:

◆ bindIf()

ZM\Container\bindIf ( string  $abstract,
  $concrete = null,
bool  $shared = false 
)

注册绑定

在已经绑定时不会重复注册

参数
string$abstract类或接口名
null | \Closure | string$concrete返回类实例的闭包,或是类名
bool$shared是否共享
函数调用图:

◆ bound()

ZM\Container\bound ( string  $abstract)

判断对应的类或接口是否已经注册

参数
string$abstract类或接口名

◆ build()

ZM\Container\build ( \Closure|string  $concrete)

实例化具体的类实例

参数
\Closure | string$concrete类名或对应的闭包
返回
mixed
异常
EntryResolutionException
函数调用图:

◆ call()

ZM\Container\call ( callable|string  $callback,
array  $parameters = [],
string  $default_method = null 
)

调用对应的方法,并自动注入依赖

参数
callable | string$callback对应的方法
array$parameters参数
null | string$default_method默认方法
返回
mixed
函数调用图:

◆ dropStaleInstances()

ZM\Container\dropStaleInstances ( string  $abstract)
protected

抛弃所有过时的实例和别名

参数
string$abstract类或接口名

◆ extend()

ZM\Container\extend ( string  $abstract,
\Closure  $closure 
)

扩展一个类或接口

参数
string$abstract类或接口名
\Closure$closure扩展闭包
函数调用图:

◆ factory()

ZM\Container\factory ( string  $abstract)

获取一个解析对应类实例的闭包

参数
string$abstract类或接口名
函数调用图:

◆ flush()

ZM\Container\flush ( )

清除所有绑定和实例

◆ get()

ZM\Container\get ( string  $id)

Finds an entry of the container by its identifier and returns it.

参数
string$ididentifier of the entry to look for
返回
mixed entry
异常
NotFoundExceptionInterfaceno entry was found for this identifier
ContainerExceptionInterfaceerror while retrieving the entry
函数调用图:

◆ getAlias()

ZM\Container\getAlias ( string  $abstract)

获取类别名(如存在)

参数
string$abstract类或接口名
返回
string 别名,不存在时返回传入的类或接口名

◆ getClosure()

ZM\Container\getClosure ( string  $abstract,
string  $concrete 
)
protected

获取一个解析对应类的闭包

参数
string$abstract类或接口名
string$concrete实际类名

◆ getConcrete()

ZM\Container\getConcrete ( string  $abstract)
protected

获取类名的实际类型

参数
string$abstract类或接口名

◆ getExtenders()

ZM\Container\getExtenders ( string  $abstract)
protected

获取对应类型的所有扩展器

参数
string$abstract类或接口名
返回
\Closure[]
函数调用图:

◆ getLastParameterOverride()

ZM\Container\getLastParameterOverride ( )
protected

获取最后一次的覆盖参数

◆ getLogPrefix()

ZM\Container\getLogPrefix ( )

获取日志前缀

◆ getParameterOverride()

ZM\Container\getParameterOverride ( \ReflectionParameter  $parameter)
protected

获取覆盖参数

返回
mixed
函数调用图:

◆ getParameterTypeOverride()

ZM\Container\getParameterTypeOverride ( \ReflectionParameter  $parameter)
protected

获取临时注入的参数

返回
mixed
函数调用图:

◆ has()

ZM\Container\has ( string  $id)

Returns true if the container can return an entry for the given identifier. Returns false otherwise.

has($id) returning true does not mean that get($id) will not throw an exception. It does however mean that get($id) will not throw a NotFoundExceptionInterface.

参数
string$ididentifier of the entry to look for
函数调用图:

◆ hasParameterOverride()

ZM\Container\hasParameterOverride ( \ReflectionParameter  $parameter)
protected

判断传入的参数是否存在覆盖参数

◆ hasParameterTypeOverride()

ZM\Container\hasParameterTypeOverride ( \ReflectionParameter  $parameter)
protected

判断传入的参数是否存在临时注入的参数

◆ instance()

ZM\Container\instance ( string  $abstract,
mixed  $instance 
)

注册一个已有的实例,效果等同于单例绑定

参数
string$abstract类或接口名
mixed$instance实例
返回
mixed

◆ isAlias()

ZM\Container\isAlias ( string  $name)
protected

判断传入的是否为别名

◆ isBuildable()

ZM\Container\isBuildable ( mixed  $concrete,
string  $abstract 
)
protected

判断传入的实际类型是否可以构造

参数
mixed$concrete实际类型
string$abstract类或接口名

◆ isShared()

ZM\Container\isShared ( string  $abstract)
protected

判断传入的类型是否为共享实例

参数
string$abstract类或接口名

◆ log()

ZM\Container\log ( string  $message)
protected

记录日志(自动附加容器日志前缀)

函数调用图:

◆ make()

ZM\Container\make ( string  $abstract,
array  $parameters = [] 
)

获取一个绑定的实例

@template T

参数
class-string<T>$abstract 类或接口名
array$parameters参数
返回
\Closure|mixed|T 实例
异常
EntryResolutionException
函数调用图:

◆ notInstantiable()

ZM\Container\notInstantiable ( string  $concrete,
string  $reason = '' 
)
protected

抛出实例化异常

异常
EntryResolutionException

◆ resolveClass()

ZM\Container\resolveClass ( \ReflectionParameter  $parameter)
protected

解析类

返回
mixed
异常
EntryResolutionException如果无法解析类,则抛出异常
函数调用图:

◆ resolveDependencies()

ZM\Container\resolveDependencies ( array  $dependencies)
protected

解析依赖

参数
\ReflectionParameter[]$dependencies
异常
EntryResolutionException
函数调用图:

◆ resolvePrimitive()

ZM\Container\resolvePrimitive ( \ReflectionParameter  $parameter)
protected

解析基本类型

返回
mixed 对应类型的默认值
异常
EntryResolutionException如参数不存在默认值,则抛出异常

◆ setLogPrefix()

ZM\Container\setLogPrefix ( string  $prefix)

设置日志前缀

◆ shouldLog()

ZM\Container\shouldLog ( )
protected

判断是否输出日志

◆ singleton()

ZM\Container\singleton ( string  $abstract,
  $concrete = null 
)

注册一个单例绑定

参数
string$abstract类或接口名
null | \Closure | string$concrete返回类实例的闭包,或是类名
函数调用图:

◆ singletonIf()

ZM\Container\singletonIf ( string  $abstract,
  $concrete = null 
)

注册一个单例绑定

在已经绑定时不会重复注册

参数
string$abstract类或接口名
null | \Closure | string$concrete返回类实例的闭包,或是类名
函数调用图:

变量说明

◆ $build_stack

array $build_stack = []
protected

◆ $log_prefix

string $log_prefix
protected

日志前缀

◆ $with

array $with = []
protected

◆ ContainerTrait

trait ContainerTrait
初始值:
{
protected array $shared = []