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:

[View]
__shared = false
compileCheck = true
caching = false
cacheLifetime = 3600
cacheDir = app/cache/smarty/

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.

Author
ingo herwig ingo@.nosp@m.wemo.nosp@m.ve.co.nosp@m.m

Definition at line 57 of file DefaultFactory.php.

+ Inheritance diagram for DefaultFactory:

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
$configurationConfiguration 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 ( )
See also
Factory::clear()

Implements Factory.

Definition at line 162 of file DefaultFactory.php.

getSetterName (   $property)
protected

Get the setter method name for a property.

Parameters
$property
Returns
String

Definition at line 171 of file DefaultFactory.php.

createInstance (   $name,
  $configuration,
  $instanceKey 
)
protected

Create an instance from the given configuration array.

Parameters
$nameThe name by which the instance may be retrieved later using Factory::getInstance(). The name is also used to check the interface (see Factory::addInterfaces())
$configurationAssociative 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())
$instanceKeyThe name under which the instance is registered for later retrieval
Returns
Object

Definition at line 187 of file DefaultFactory.php.

resolveValue (   $value)
protected

Resolve a configuration value into a parameter.

Parameters
$value
Returns
Mixed

Definition at line 302 of file DefaultFactory.php.

getInterface (   $name)
protected

Get the interface that is required to be implemented by the given instance.

Parameters
$nameThe name of the instance
Returns
Interface or null, if undefined

Definition at line 347 of file DefaultFactory.php.

Member Data Documentation

$_requiredInterfaces
protected
Initial value:
= array(
'eventManager' => 'wcmf\lib\core\EventManager',
'logger' => 'wcmf\lib\core\Logger',
'logManager' => 'wcmf\lib\core\LogManager',
'session' => 'wcmf\lib\core\Session',
'configuration' => 'wcmf\lib\config\Configuration',
'localization' => 'wcmf\lib\i18n\Localization',
'message' => 'wcmf\lib\i18n\Message',
'cache' => 'wcmf\lib\io\Cache',
'persistenceFacade' => 'wcmf\lib\persistence\PersistenceFacade',
'transaction' => 'wcmf\lib\persistence\Transaction',
'concurrencyManager' => 'wcmf\lib\persistence\concurrency\ConcurrencyManager',
'actionMapper' => 'wcmf\lib\presentation\ActionMapper',
'request' => 'wcmf\lib\presentation\Request',
'response' => 'wcmf\lib\presentation\Response',
'listStrategies' => 'wcmf\lib\presentation\control\lists\ListStrategy',
'formats' => 'wcmf\lib\presentation\format\Format',
'formatter' => 'wcmf\lib\presentation\format\Formatter',
'view' => 'wcmf\lib\presentation\view\View',
'authenticationManager' => 'wcmf\lib\security\AuthenticationManager',
'permissionManager' => 'wcmf\lib\security\PermissionManager',
'principalFactory' => 'wcmf\lib\security\principal\PrincipalFactory',
'user' => 'wcmf\lib\security\principal\User',
'role' => 'wcmf\lib\security\principal\Role',
)

Interfaces that must be implemented by the given instances used in the framework.

Definition at line 63 of file DefaultFactory.php.

$_instances = array()
protected

The registry for already created instances.

Definition at line 92 of file DefaultFactory.php.

$_configuration = null
protected

The Configuration instance that holds the instance definitions.

Definition at line 97 of file DefaultFactory.php.