TYPO3  7.6
Public Member Functions | Public Attributes | Protected Member Functions | Protected Attributes | Private Member Functions | Private Attributes | List of all members
Container Class Reference
Inheritance diagram for Container:
SingletonInterface

Public Member Functions

 __construct ()
 
 getInstance ($className, $givenConstructorArguments=array())
 
 getEmptyObject ($className)
 
 registerImplementation ($className, $alternativeClassName)
 
 getImplementationClassName ($className)
 
 isSingleton ($className)
 
 isPrototype ($className)
 

Public Attributes

const SCOPE_PROTOTYPE = 1
 
const SCOPE_SINGLETON = 2
 

Protected Member Functions

 getClassInfoFactory ()
 
 getClassInfoCache ()
 
 getInstantiator ()
 
 getInstanceInternal ($className, $givenConstructorArguments=array())
 
 instanciateObject (\TYPO3\CMS\Extbase\Object\Container\ClassInfo $classInfo, array $givenConstructorArguments)
 
 injectDependencies ($instance,\TYPO3\CMS\Extbase\Object\Container\ClassInfo $classInfo)
 
 initializeObject ($instance,\TYPO3\CMS\Extbase\Object\Container\ClassInfo $classInfo)
 
 log ($message, $severity)
 

Protected Attributes

 $instantiator = null
 

Private Member Functions

 getConstructorArguments ($className,\TYPO3\CMS\Extbase\Object\Container\ClassInfo $classInfo, array $givenConstructorArguments)
 
 getClassInfo ($className)
 

Private Attributes

 $cache = null
 
 $alternativeImplementation
 
 $classInfoFactory = null
 
 $singletonInstances = array()
 
 $prototypeObjectsWhichAreCurrentlyInstanciated
 

Detailed Description

Internal TYPO3 Dependency Injection container

Definition at line 20 of file Container.php.

Constructor & Destructor Documentation

__construct ( )

Constructor is protected since container should be a singleton.

See Also
getContainer()

Definition at line 72 of file Container.php.

Member Function Documentation

getClassInfo (   $className)
private

Gets Classinfos for the className - using the cache and the factory

Parameters
string$className
Returns

Definition at line 344 of file Container.php.

References Container\getClassInfoCache(), and Container\getClassInfoFactory().

Referenced by Container\getEmptyObject(), Container\getInstanceInternal(), and Container\isSingleton().

getClassInfoCache ( )
protected

Internal method to create the classInfoCache, extracted to be mockable.

Returns

Definition at line 94 of file Container.php.

References Container\$cache.

Referenced by Container\getClassInfo().

getClassInfoFactory ( )
protected

Internal method to create the classInfoFactory, extracted to be mockable.

Returns

Definition at line 81 of file Container.php.

References Container\$classInfoFactory.

Referenced by Container\getClassInfo().

getConstructorArguments (   $className,
\TYPO3\CMS\Extbase\Object\Container\ClassInfo  $classInfo,
array  $givenConstructorArguments 
)
private

gets array of parameter that can be used to call a constructor

Parameters
string$className
\TYPO3\CMS\Extbase\Object\Container\ClassInfo$classInfo
array$givenConstructorArguments
Exceptions
\InvalidArgumentException
Returns
array

Definition at line 295 of file Container.php.

References elseif, Container\getInstanceInternal(), and Container\log().

Referenced by Container\instanciateObject().

getEmptyObject (   $className)

Create an instance of $className without calling its constructor

Parameters
string$className
Returns
object

Definition at line 135 of file Container.php.

References Container\getClassInfo(), Container\getImplementationClassName(), Container\getInstantiator(), Container\initializeObject(), and Container\injectDependencies().

getImplementationClassName (   $className)

Returns the class name for a new instance, taking into account the class-extension API.

Parameters
string$classNameBase class name to evaluate
Returns
string Final class name to instantiate with "new [classname]

Definition at line 327 of file Container.php.

Referenced by Container\getEmptyObject(), and Container\getInstanceInternal().

getInstance (   $className,
  $givenConstructorArguments = array() 
)

Main method which should be used to get an instance of the wished class specified by $className.

Parameters
string$className
array$givenConstructorArgumentsthe list of constructor arguments as array
Returns
object the built object

Definition at line 123 of file Container.php.

References Container\getInstanceInternal().

getInstanceInternal (   $className,
  $givenConstructorArguments = array() 
)
protected

Internal implementation for getting a class.

Parameters
string$className
array$givenConstructorArgumentsthe list of constructor arguments as array
Exceptions
\TYPO3\CMS\Extbase\Object\Exception
\TYPO3\CMS\Extbase\Object\Exception\CannotBuildObjectException
Returns
object the built object

Definition at line 154 of file Container.php.

References Container\getClassInfo(), Container\getImplementationClassName(), Container\initializeObject(), Container\injectDependencies(), and Container\instanciateObject().

Referenced by Container\getConstructorArguments(), Container\getInstance(), and Container\injectDependencies().

getInstantiator ( )
protected

Internal method to create the class instantiator, extracted to be mockable

Returns

Definition at line 107 of file Container.php.

References Container\$instantiator.

Referenced by Container\getEmptyObject().

initializeObject (   $instance,
\TYPO3\CMS\Extbase\Object\Container\ClassInfo  $classInfo 
)
protected

Call object initializer if present in object

Parameters
object$instance
\TYPO3\CMS\Extbase\Object\Container\ClassInfo$classInfo

Definition at line 255 of file Container.php.

Referenced by Container\getEmptyObject(), and Container\getInstanceInternal().

injectDependencies (   $instance,
\TYPO3\CMS\Extbase\Object\Container\ClassInfo  $classInfo 
)
protected

Inject setter-dependencies into $instance

Parameters
object$instance
\TYPO3\CMS\Extbase\Object\Container\ClassInfo$classInfo
Returns
void

Definition at line 223 of file Container.php.

References Container\getInstanceInternal(), and Container\log().

Referenced by Container\getEmptyObject(), and Container\getInstanceInternal().

instanciateObject ( \TYPO3\CMS\Extbase\Object\Container\ClassInfo  $classInfo,
array  $givenConstructorArguments 
)
protected

Instanciates an object, possibly setting the constructor dependencies. Additionally, directly registers all singletons in the singleton registry, such that circular references of singletons are correctly instanciated.

Parameters
\TYPO3\CMS\Extbase\Object\Container\ClassInfo$classInfo
array$givenConstructorArguments
Exceptions
\TYPO3\CMS\Extbase\Object\Exception
Returns
object the new instance

Definition at line 200 of file Container.php.

References Container\getConstructorArguments().

Referenced by Container\getInstanceInternal().

isPrototype (   $className)
Parameters
string$className
Returns
bool

Definition at line 370 of file Container.php.

References Container\isSingleton().

isSingleton (   $className)
Parameters
string$className
Returns
bool

Definition at line 360 of file Container.php.

References Container\getClassInfo().

Referenced by ClassInfo\__construct(), and Container\isPrototype().

log (   $message,
  $severity 
)
protected

Wrapper for dev log, in order to ease testing

Parameters
string$messageMessage (in english).
int$severitySeverity: 0 is info, 1 is notice, 2 is warning, 3 is fatal error, -1 is "OK" message
Returns
void

Definition at line 269 of file Container.php.

Referenced by Container\getConstructorArguments(), and Container\injectDependencies().

registerImplementation (   $className,
  $alternativeClassName 
)

register a classname that should be used if a dependency is required. e.g. used to define default class for an interface

Parameters
string$className
string$alternativeClassName

Definition at line 281 of file Container.php.

Member Data Documentation

$alternativeImplementation
private

Definition at line 38 of file Container.php.

$cache = null
private

Definition at line 30 of file Container.php.

Referenced by Container\getClassInfoCache().

$classInfoFactory = null
private

Definition at line 45 of file Container.php.

Referenced by Container\getClassInfoFactory().

$instantiator = null
protected

Definition at line 50 of file Container.php.

Referenced by Container\getInstantiator().

$prototypeObjectsWhichAreCurrentlyInstanciated
private

Definition at line 64 of file Container.php.

$singletonInstances = array()
private

Definition at line 57 of file Container.php.

const SCOPE_PROTOTYPE = 1

Definition at line 22 of file Container.php.

Referenced by ObjectManager\getScope().

const SCOPE_SINGLETON = 2

Definition at line 23 of file Container.php.

Referenced by ObjectManager\getScope().