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/
[HtmlView]
__ref = $view

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. HtmlView is defined as an alias for View.

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

Definition at line 60 of file DefaultFactory.php.

+ Inheritance diagram for DefaultFactory:

Public Member Functions

 __construct (Configuration $configuration)
 
 getInstance ($name, $dynamicConfiguration=[])
 
 getNewInstance ($name, $dynamicConfiguration=[])
 
 getInstanceOf ($class, $dynamicConfiguration=[])
 
 registerInstance ($name, $instance)
 
 addInterfaces (array $interfaces)
 
 clear ()
 

Protected Member Functions

 getSetterName ($property)
 
 createInstance ($name, $configuration, $instanceKey)
 
 resolveValue ($value)
 
 getInterface ($name)
 

Protected Attributes

 $requiredInterfaces
 
 $instances = []
 
 $configuration = null
 
 $currentStack = []
 

Constructor & Destructor Documentation

◆ __construct()

__construct ( Configuration  $configuration)

Constructor.

Parameters
$configurationConfiguration instance used to construct instances.

Definition at line 108 of file DefaultFactory.php.

Member Function Documentation

◆ getInstance()

getInstance (   $name,
  $dynamicConfiguration = [] 
)
See also
Factory::getInstance()

Implements Factory.

Definition at line 116 of file DefaultFactory.php.

◆ getNewInstance()

getNewInstance (   $name,
  $dynamicConfiguration = [] 
)
See also
Factory::getNewInstance()

Implements Factory.

Definition at line 144 of file DefaultFactory.php.

◆ getInstanceOf()

getInstanceOf (   $class,
  $dynamicConfiguration = [] 
)
See also
Factory::getInstanceOf()

Implements Factory.

Definition at line 156 of file DefaultFactory.php.

◆ registerInstance()

registerInstance (   $name,
  $instance 
)
See also
Factory::registerInstance()

Implements Factory.

Definition at line 169 of file DefaultFactory.php.

◆ addInterfaces()

addInterfaces ( array  $interfaces)
See also
Factory::addInterfaces()

Implements Factory.

Definition at line 177 of file DefaultFactory.php.

◆ clear()

clear ( )
See also
Factory::clear()

Implements Factory.

Definition at line 184 of file DefaultFactory.php.

◆ getSetterName()

getSetterName (   $property)
protected

Get the setter method name for a property.

Parameters
$property
Returns
String

Definition at line 193 of file DefaultFactory.php.

◆ createInstance()

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())
  • '__ref' optional, defines this instance as an alias of the referenced instance
$instanceKeyThe name under which the instance is registered for later retrieval
Returns
Object

Definition at line 210 of file DefaultFactory.php.

◆ resolveValue()

resolveValue (   $value)
protected

Resolve a configuration value into a parameter.

Parameters
$value
Returns
Mixed

Definition at line 331 of file DefaultFactory.php.

◆ getInterface()

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 376 of file DefaultFactory.php.

Member Data Documentation

◆ $requiredInterfaces

$requiredInterfaces
protected
Initial value:
= [
'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 66 of file DefaultFactory.php.

◆ $instances

$instances = []
protected

The registry for already created instances.

Definition at line 95 of file DefaultFactory.php.

◆ $configuration

$configuration = null
protected

The Configuration instance that holds the instance definitions.

Definition at line 100 of file DefaultFactory.php.

◆ $currentStack

$currentStack = []
protected

Definition at line 102 of file DefaultFactory.php.

View is used by Controller to handle the view presentation in MVC pattern.
Definition: SmartyView.php:36