Method | Description | |
---|---|---|
__get ( string $name ) : mixed | Getter magic method. | |
__isset ( string $name ) : boolean | Checks if a property value is null. | |
clear ( string $id ) | Removes the component from the locator. | |
get ( string $id, boolean $throwException = true ) : object | null | Returns the component instance with the specified ID. | |
getComponents ( boolean $returnDefinitions = true ) : array | Returns the list of the component definitions or the loaded component instances. | |
has ( string $id, boolean $checkInstance = false ) : boolean | Returns a value indicating whether the locator has the specified component definition or has instantiated the component. | |
set ( string $id, mixed $definition ) | Registers a component definition with this locator. | |
setComponents ( array $components ) | Registers a set of component definitions in this locator. |
public get ( string $id, boolean $throwException = true ) : object | null | ||
$id | string | component ID (e.g. `db`). |
$throwException | boolean | whether to throw an exception if `$id` is not registered with the locator before. |
return | object | null | the component of the specified ID. If `$throwException` is false and `$id` is not registered before, null will be returned. |
public getComponents ( boolean $returnDefinitions = true ) : array | ||
$returnDefinitions | boolean | whether to return component definitions instead of the loaded component instances. |
return | array | the list of the component definitions or the loaded component instances (ID => definition or instance). |
public has ( string $id, boolean $checkInstance = false ) : boolean | ||
$id | string | component ID (e.g. `db`). |
$checkInstance | boolean | whether the method should check if the component is shared and instantiated. |
return | boolean | whether the locator has the specified component definition or has instantiated the component. |
public set ( string $id, mixed $definition ) | ||
$id | string | component ID (e.g. `db`). |
$definition | mixed | the component definition to be registered with this locator. It can be one of the following: - a class name - a configuration array: the array contains name-value pairs that will be used to initialize the property values of the newly created object when [[get()]] is called. The `class` element is required and stands for the the class of the object to be created. - a PHP callable: either an anonymous function or an array representing a class method (e.g. `['Foo', 'bar']`). The callable will be called by [[get()]] to return an object associated with the specified component ID. - an object: When [[get()]] is called, this object will be returned. |
public setComponents ( array $components ) | ||
$components | array | component definitions or instances |