class Container implements ContainerInterface, ArrayAccess, IteratorAggregate, Countable

Class Container

Traits

Class NameAliasTrait

Constants

DEFAULT_OPTIONS

Properties

protected array $aliases 服务别名
string $name 当前容器名称,初始时即固定
protected Container $parent 当前容器的父级容器

Methods

bool|string
alias(array|string $name, array|string|null $alias = null)

set/get name alias

mixed
resolveAlias(string $alias)

No description

bool
hasAlias(string $alias)

No description

array
getAliases()

No description

$this
setAliases(array $aliases)

No description

__construct(array $services = [], Container $parent = null)

Container constructor.

__destruct()

No description

$this
set(string $id, $definition, array $opts = [])

在容器注册服务(详细的参数信息请查看README.md)

$this
sets(array $services)

通过设置配置的多维数组 注册多个服务. 服务详细设置请看{see self::set()}

$this
protect(string $id, $definition, $share = false)

注册受保护的服务 alias of the lock()

$this
lock(string $id, $definition, $share = false)

(注册)锁定的服务,也可在注册后锁定,防止 getNew() 强制重载

$this
registerServiceProvider(ServiceProviderInterface $provider)

注册服务提供者(可能含有多个服务)

$this
registerServiceProviders(array $providers)

No description

callable
createCallback(mixed $target, array $arguments = [], array $props = [])

创建(类实例/类的方法)回调

mixed
get(string $id)

get 获取已注册的服务组件实例 - (单例)共享服务总是获取已存储的实例 - 其他的则总是返回新的实例

mixed
getNew(string $id)

强制获取服务的新实例,针对共享服务

mixed|null
new(string $id)

No description

mixed|null
getIfExist(string $id)

若存在服务则返回 否则返回 null

mixed
raw(string $id)

No description

del(string $id)

删除服务

mixed|null
getInstance(string $id, bool $thrErr = true, bool $forceNew = false)

get 获取已注册的服务组件实例

Service|null
getService(string $id, bool $thrErr = false)

获取某一个服务的信息

clear()

clear

array
getServices()

获取全部服务信息

setParent(Container $parent)

Method to set property parent

array
getIds(bool $toArray = true)

获取全部服务id

bool
isShared(string $id)

No description

bool
isLocked(string $id)

No description

bool|Service
has(string $id)

是已注册的服务

bool
exists(string $id)

No description

bool|Service
__isset($name)

No description

__set($name, $value)

No description

bool
__get($name)

No description

int
count()

No description

getIterator()

Defined by IteratorAggregate interface Returns an iterator for this object, for use with foreach

boolean
offsetExists(mixed $offset)

Checks whether an offset exists in the iterator.

mixed
offsetGet(mixed $offset)

Gets an offset in the iterator.

$this
offsetSet(mixed $offset, mixed $value)

Sets an offset in the iterator.

void
offsetUnset(mixed $offset)

Unset an offset in the iterator.

Details

in NameAliasTrait at line 26
bool|string alias(array|string $name, array|string|null $alias = null)

set/get name alias

Parameters

array|string $name
array|string|null $alias

Return Value

bool|string

at line 485
mixed resolveAlias(string $alias)

Parameters

string $alias

Return Value

mixed

in NameAliasTrait at line 72
bool hasAlias(string $alias)

Parameters

string $alias

Return Value

bool

in NameAliasTrait at line 80
array getAliases()

Return Value

array

in NameAliasTrait at line 89
$this setAliases(array $aliases)

Parameters

array $aliases

Return Value

$this

at line 79
__construct(array $services = [], Container $parent = null)

Container constructor.

Parameters

array $services
Container $parent

Exceptions

InvalidArgumentException
DependencyResolutionException

at line 86
__destruct()

at line 103
$this set(string $id, $definition, array $opts = [])

在容器注册服务(详细的参数信息请查看README.md)

Parameters

string $id 服务组件注册id
$definition
array $opts

Return Value

$this

Exceptions

DependencyResolutionException

at line 183
$this sets(array $services)

通过设置配置的多维数组 注册多个服务. 服务详细设置请看{see self::set()}

Parameters

array $services

Return Value

$this

Exceptions

InvalidArgumentException
DependencyResolutionException

at line 215
$this protect(string $id, $definition, $share = false)

注册受保护的服务 alias of the lock()

Parameters

string $id [description]
$definition
$share

Return Value

$this

Exceptions

InvalidArgumentException
DependencyResolutionException

at line 229
$this lock(string $id, $definition, $share = false)

(注册)锁定的服务,也可在注册后锁定,防止 getNew() 强制重载

Parameters

string $id description
$definition
$share

Return Value

$this

Exceptions

DependencyResolutionException
InvalidArgumentException

at line 242
$this registerServiceProvider(ServiceProviderInterface $provider)

注册服务提供者(可能含有多个服务)

Parameters

ServiceProviderInterface $provider 在提供者内添加需要的服务到容器

Return Value

$this

at line 253
$this registerServiceProviders(array $providers)

Parameters

array $providers

Return Value

$this

at line 272
callable createCallback(mixed $target, array $arguments = [], array $props = [])

创建(类实例/类的方法)回调

Parameters

mixed $target
array $arguments
array $props

Return Value

callable

Exceptions

InvalidArgumentException
DependencyResolutionException

at line 353
mixed get(string $id)

get 获取已注册的服务组件实例 - (单例)共享服务总是获取已存储的实例 - 其他的则总是返回新的实例

Parameters

string $id 要获取的服务组件id

Return Value

mixed

Exceptions

InvalidArgumentException

at line 374
mixed getNew(string $id)

强制获取服务的新实例,针对共享服务

Parameters

string $id

Return Value

mixed

Exceptions

InvalidArgumentException

at line 383
mixed|null new(string $id)

Parameters

string $id

Return Value

mixed|null

at line 394
mixed|null getIfExist(string $id)

若存在服务则返回 否则返回 null

Parameters

string $id

Return Value

mixed|null

Exceptions

InvalidArgumentException

at line 405
mixed raw(string $id)

Parameters

string $id

Return Value

mixed

Exceptions

InvalidArgumentException

at line 420
del(string $id)

删除服务

Parameters

string $id

at line 441
mixed|null getInstance(string $id, bool $thrErr = true, bool $forceNew = false)

get 获取已注册的服务组件实例

Parameters

string $id
bool $thrErr
bool $forceNew 强制获取服务的新实例

Return Value

mixed|null

Exceptions

InvalidArgumentException

at line 466
Service|null getService(string $id, bool $thrErr = false)

获取某一个服务的信息

Parameters

string $id
bool $thrErr

Return Value

Service|null

Exceptions

InvalidArgumentException

at line 498
clear()

clear

at line 512
array getServices()

获取全部服务信息

Return Value

array

at line 522
Container setParent(Container $parent)

Method to set property parent

Parameters

Container $parent Parent container.

Return Value

Container Return self to support chaining.

at line 534
array getIds(bool $toArray = true)

获取全部服务id

Parameters

bool $toArray

Return Value

array

at line 546
bool isShared(string $id)

Parameters

string $id

Return Value

bool

Exceptions

InvalidArgumentException

at line 560
bool isLocked(string $id)

Parameters

string $id

Return Value

bool

Exceptions

InvalidArgumentException

at line 576
bool|Service has(string $id)

是已注册的服务

Parameters

string $id

Return Value

bool|Service

at line 585
bool exists(string $id)

Parameters

string $id

Return Value

bool

at line 614
bool|Service __isset($name)

Parameters

$name

Return Value

bool|Service

at line 625
__set($name, $value)

Parameters

$name
$value

Exceptions

InvalidArgumentException
DependencyResolutionException

at line 636
bool __get($name)

Parameters

$name

Return Value

bool

Exceptions

InvalidArgumentException
NotFoundException

at line 658
int count()

Return Value

int

at line 668
ArrayIterator getIterator()

Defined by IteratorAggregate interface Returns an iterator for this object, for use with foreach

Return Value

ArrayIterator

at line 678
boolean offsetExists(mixed $offset)

Checks whether an offset exists in the iterator.

Parameters

mixed $offset The array offset.

Return Value

boolean True if the offset exists, false otherwise.

at line 689
mixed offsetGet(mixed $offset)

Gets an offset in the iterator.

Parameters

mixed $offset The array offset.

Return Value

mixed The array value if it exists, null otherwise.

Exceptions

InvalidArgumentException

at line 702
$this offsetSet(mixed $offset, mixed $value)

Sets an offset in the iterator.

Parameters

mixed $offset The array offset.
mixed $value The array value.

Return Value

$this

Exceptions

InvalidArgumentException
DependencyResolutionException

at line 712
void offsetUnset(mixed $offset)

Unset an offset in the iterator.

Parameters

mixed $offset The array offset.

Return Value

void