Detailed Description
DefaultFactory is used to create service instances.
The concrete service implementations and building parameters are described in the given configuration. Dependencies are injected in the following ways:
- Constructor injection: Each constructor parameter is resolved either from the instance configuration or, if not specified, from an existing class that is of the same type as defined in the type hinting.
- Setter injection: Each parameter of the instance configuration, that is not part of the constructor is injected through an appropriate setter method, if existing.
To ensure that an instance implements a certain interface, the interface name may be passed together with the instance name to the DefaultFactory::addInterfaces method. The interfaces required by framework classes are already defined internally (see DefaultFactory::$_requiredInterfaces).
The following configuration shows the definition of the View instance:
In this example views are instances of SmartyView. They are not shared, meaning that clients get a fresh instance each time they request a view. The parameters compileCheck, caching, ... are either defined in the constructor of SmartyView or there is an appropriate setter method (e.g. SmartyView::setCompileCheck). Any other constructor parameter of SmartyView is tried to resolve from either another instance defined in the configuration or an existing class.
Definition at line 57 of file DefaultFactory.php.
Public Member Functions | |
__construct (Configuration $configuration) | |
getInstance ($name, $dynamicConfiguration=array()) | |
getClassInstance ($class, $dynamicConfiguration=array()) | |
registerInstance ($name, $instance) | |
addInterfaces (array $interfaces) | |
clear () | |
Protected Member Functions | |
getSetterName ($property) | |
createInstance ($name, $configuration, $instanceKey) | |
resolveValue ($value) | |
getInterface ($name) | |
Protected Attributes | |
$_requiredInterfaces | |
$_instances = array() | |
$_configuration = null | |
Constructor & Destructor Documentation
__construct | ( | Configuration | $configuration | ) |
Constructor.
- Parameters
-
$configuration Configuration instance used to construct instances.
Definition at line 103 of file DefaultFactory.php.
Member Function Documentation
getInstance | ( | $name, | |
$dynamicConfiguration = array() |
|||
) |
- See also
- Factory::getInstance()
Implements Factory.
Definition at line 111 of file DefaultFactory.php.
getClassInstance | ( | $class, | |
$dynamicConfiguration = array() |
|||
) |
- See also
- Factory::getClassInstance()
Implements Factory.
Definition at line 134 of file DefaultFactory.php.
registerInstance | ( | $name, | |
$instance | |||
) |
- See also
- Factory::registerInstance()
Implements Factory.
Definition at line 147 of file DefaultFactory.php.
addInterfaces | ( | array | $interfaces | ) |
- See also
- Factory::addInterfaces()
Implements Factory.
Definition at line 155 of file DefaultFactory.php.
clear | ( | ) |
|
protected |
Get the setter method name for a property.
- Parameters
-
$property
- Returns
- String
Definition at line 171 of file DefaultFactory.php.
|
protected |
Create an instance from the given configuration array.
- Parameters
-
$name The name by which the instance may be retrieved later using Factory::getInstance(). The name is also used to check the interface (see Factory::addInterfaces()) $configuration Associative array with key value pairs for instance properties passed to the constructor, setters or public properties and the special keys '__class' (optional, denotes the instance class name), '__shared' (optional, if true, the instance may be reused using Factory::getInstance()) $instanceKey The name under which the instance is registered for later retrieval
- Returns
- Object
Definition at line 187 of file DefaultFactory.php.
|
protected |
Resolve a configuration value into a parameter.
- Parameters
-
$value
- Returns
- Mixed
Definition at line 302 of file DefaultFactory.php.
|
protected |
Get the interface that is required to be implemented by the given instance.
- Parameters
-
$name The name of the instance
- Returns
- Interface or null, if undefined
Definition at line 347 of file DefaultFactory.php.
Member Data Documentation
|
protected |
Interfaces that must be implemented by the given instances used in the framework.
Definition at line 63 of file DefaultFactory.php.
|
protected |
The registry for already created instances.
Definition at line 92 of file DefaultFactory.php.
|
protected |
The Configuration instance that holds the instance definitions.
Definition at line 97 of file DefaultFactory.php.