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:

__shared = false
compileCheck = true
caching = false
cacheLifetime = 3600
cacheDir = app/cache/smarty/
__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.

ingo herwig

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

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

Constructor & Destructor Documentation

◆ __construct()

__construct ( Configuration  $configuration)


$configurationConfiguration instance used to construct instances.

Definition at line 108 of file DefaultFactory.php.

Member Function Documentation

◆ getInstance()

getInstance (   $name,
  $dynamicConfiguration = [] 
See also

Implements Factory.

Definition at line 116 of file DefaultFactory.php.

◆ getNewInstance()

getNewInstance (   $name,
  $dynamicConfiguration = [] 
See also

Implements Factory.

Definition at line 144 of file DefaultFactory.php.

◆ getInstanceOf()

getInstanceOf (   $class,
  $dynamicConfiguration = [] 
See also

Implements Factory.

Definition at line 156 of file DefaultFactory.php.

◆ registerInstance()

registerInstance (   $name,
See also

Implements Factory.

Definition at line 169 of file DefaultFactory.php.

◆ addInterfaces()

addInterfaces ( array  $interfaces)
See also

Implements Factory.

Definition at line 177 of file DefaultFactory.php.

◆ clear()

clear ( )
See also

Implements Factory.

Definition at line 184 of file DefaultFactory.php.

◆ getSetterName()

getSetterName (   $property)

Get the setter method name for a property.


Definition at line 193 of file DefaultFactory.php.

◆ createInstance()

createInstance (   $name,

Create an instance from the given configuration array.

$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

Definition at line 210 of file DefaultFactory.php.

◆ resolveValue()

resolveValue (   $value)

Resolve a configuration value into a parameter.


Definition at line 331 of file DefaultFactory.php.

◆ getInterface()

getInterface (   $name)

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

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

Definition at line 376 of file DefaultFactory.php.

Member Data Documentation

◆ $requiredInterfaces

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 = []

The registry for already created instances.

Definition at line 95 of file DefaultFactory.php.

◆ $configuration

$configuration = null

The Configuration instance that holds the instance definitions.

Definition at line 100 of file DefaultFactory.php.

◆ $currentStack

$currentStack = []

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