PHP Class Neos\Flow\ObjectManagement\ObjectManager

Inheritance: implements Neos\Flow\ObjectManagement\ObjectManagerInterface
Show file Open project: neos/flow-development-collection Class Usage Examples

Protected Properties

Property Type Description
$allSettings array An array of settings of all packages, indexed by package key
$cachedLowerCasedObjectNames array
$classesBeingInstantiated array
$context Neos\Flow\Core\ApplicationContext The configuration context for this Flow run
$dependencyProxies array
$internalShutdownObjects SplObjectStorage These shutdown method will be called after all other shutdown methods have been called.
$objectSerializer ObjectSerializer
$objects array
$shutdownObjects SplObjectStorage A SplObjectStorage containing those objects which need to be shutdown when the container shuts down. Each value of each entry is the respective shutdown method name.

Public Methods

Method Description
__construct ( ApplicationContext $context ) Constructor for this Object Container
createLazyDependency ( string $hash, &$propertyReferenceVariable, string $className, Closure $builder ) : DependencyProxy Creates a new DependencyProxy class for a dependency built through code identified through "hash" for a dependency of class $className. The closure in $builder contains code for actually creating the dependency instance once it needs to be materialized.
forgetInstance ( string $objectName ) : void Unsets the instance of the given object
get ( string $objectName ) : object Returns a fresh or existing instance of the object specified by $objectName.
getAllObjectConfigurations ( ) : array Returns all current object configurations.
getCaseSensitiveObjectName ( string $caseInsensitiveObjectName ) : mixed Returns the case sensitive object name of an object specified by a case insensitive object name. If no object of that name exists, FALSE is returned.
getClassNameByObjectName ( string $objectName ) : string Returns the implementation class name for the specified object
getContext ( ) : ApplicationContext Returns the context Flow is running in.
getInstance ( string $objectName ) : object Returns the instance of the specified object or NULL if no instance has been registered yet.
getLazyDependencyByHash ( string $hash, &$propertyReferenceVariable ) : mixed This method is used internally to retrieve either an actual (singleton) instance of the specified dependency or, if no instance exists yet, a Dependency Proxy object which automatically triggers the creation of an instance as soon as it is used the first time.
getObjectNameByClassName ( string $className ) : string Returns the object name corresponding to a given class name.
getPackageKeyByObjectName ( string $objectName ) : string Returns the key of the package the specified object is contained in.
getScope ( string $objectName ) : integer Returns the scope of the specified object.
getSessionInstances ( ) : array Returns all instances of objects with scope session
getSettingsByPath ( array $settingsPath ) : mixed Returns the an array of package settings or a single setting value by the given path.
hasInstance ( string $objectName ) : boolean Returns TRUE if this object manager already has an instance for the specified object.
injectAllSettings ( array $settings ) : void Injects the global settings array, indexed by package key.
isRegistered ( string $objectName ) : boolean Returns TRUE if an object with the given name is registered
registerShutdownObject ( object $object, string $shutdownLifecycleMethodName ) : void Registers the passed shutdown lifecycle method for the given object
setInstance ( string $objectName, object $instance ) : void Sets the instance of the given object
setObjects ( array $objects ) : void Sets the objects array
shutdown ( ) : void Shuts down this Object Container by calling the shutdown methods of all object instances which were configured to be shut down.

Protected Methods

Method Description
buildObjectByFactory ( string $objectName ) : object Invokes the Factory defined in the object configuration of the specified object in order to build an instance. Arguments which were defined in the object configuration are passed to the factory method.
callShutdownMethods ( SplObjectStorage $shutdownObjects ) : void Executes the methods of the provided objects.
instantiateClass ( string $className, array $arguments ) : object Speed optimized alternative to ReflectionClass::newInstanceArgs()

Method Details

__construct() public method

Constructor for this Object Container
public __construct ( ApplicationContext $context )
$context Neos\Flow\Core\ApplicationContext The configuration context for this Flow run

buildObjectByFactory() protected method

Invokes the Factory defined in the object configuration of the specified object in order to build an instance. Arguments which were defined in the object configuration are passed to the factory method.
protected buildObjectByFactory ( string $objectName ) : object
$objectName string Name of the object to build
return object The built object

callShutdownMethods() protected method

Executes the methods of the provided objects.
protected callShutdownMethods ( SplObjectStorage $shutdownObjects ) : void
$shutdownObjects SplObjectStorage
return void

createLazyDependency() public method

Internally used by the injectProperties method of generated proxy classes.
public createLazyDependency ( string $hash, &$propertyReferenceVariable, string $className, Closure $builder ) : DependencyProxy
$hash string An md5 hash over the code needed to actually build the dependency instance
$className string Name of the class of the dependency which eventually will be instantiated
$builder Closure An anonymous function which creates the instance to be injected
return Neos\Flow\ObjectManagement\DependencyInjection\DependencyProxy

forgetInstance() public method

If run during standard runtime, the whole application might become unstable because certain parts might already use an instance of this object. Therefore this method should only be used in a setUp() method of a functional test case.
public forgetInstance ( string $objectName ) : void
$objectName string The object name
return void

get() public method

Returns a fresh or existing instance of the object specified by $objectName.
public get ( string $objectName ) : object
$objectName string The name of the object to return an instance of
return object The object instance

getAllObjectConfigurations() public method

For internal use in bootstrap only. Can change anytime.
public getAllObjectConfigurations ( ) : array
return array

getCaseSensitiveObjectName() public method

In general, the case sensitive variant is used everywhere in Flow, however there might be special situations in which the case sensitive name is not available. This method helps you in these rare cases.
public getCaseSensitiveObjectName ( string $caseInsensitiveObjectName ) : mixed
$caseInsensitiveObjectName string The object name in lower-, upper- or mixed case
return mixed Either the mixed case object name or FALSE if no object of that name was found.

getClassNameByObjectName() public method

Returns the implementation class name for the specified object
public getClassNameByObjectName ( string $objectName ) : string
$objectName string The object name
return string The class name corresponding to the given object name or FALSE if no such object is registered

getContext() public method

Returns the context Flow is running in.
public getContext ( ) : ApplicationContext
return Neos\Flow\Core\ApplicationContext The context, for example "Development" or "Production"

getInstance() public method

Returns the instance of the specified object or NULL if no instance has been registered yet.
public getInstance ( string $objectName ) : object
$objectName string The object name
return object The object or NULL

getLazyDependencyByHash() public method

Internally used by the injectProperties method of generated proxy classes.
public getLazyDependencyByHash ( string $hash, &$propertyReferenceVariable ) : mixed
$hash string
return mixed

getObjectNameByClassName() public method

Returns the object name corresponding to a given class name.
public getObjectNameByClassName ( string $className ) : string
$className string The class name
return string The object name corresponding to the given class name or FALSE if no object is configured to use that class

getPackageKeyByObjectName() public method

Returns the key of the package the specified object is contained in.
public getPackageKeyByObjectName ( string $objectName ) : string
$objectName string The object name
return string The package key or FALSE if no such object exists

getScope() public method

Returns the scope of the specified object.
public getScope ( string $objectName ) : integer
$objectName string The object name
return integer One of the Configuration::SCOPE_ constants

getSessionInstances() public method

Returns all instances of objects with scope session
public getSessionInstances ( ) : array
return array

getSettingsByPath() public method

Returns the an array of package settings or a single setting value by the given path.
public getSettingsByPath ( array $settingsPath ) : mixed
$settingsPath array Path to the setting(s) as an array, for example array('Neos', 'Flow', 'persistence', 'backendOptions')
return mixed Either an array of settings or the value of a single setting

hasInstance() public method

Returns TRUE if this object manager already has an instance for the specified object.
public hasInstance ( string $objectName ) : boolean
$objectName string The object name
return boolean TRUE if an instance already exists

injectAllSettings() public method

Injects the global settings array, indexed by package key.
public injectAllSettings ( array $settings ) : void
$settings array The global settings
return void

instantiateClass() protected method

Speed optimized alternative to ReflectionClass::newInstanceArgs()
protected instantiateClass ( string $className, array $arguments ) : object
$className string Name of the class to instantiate
$arguments array Arguments to pass to the constructor
return object The object

isRegistered() public method

Returns TRUE if an object with the given name is registered
public isRegistered ( string $objectName ) : boolean
$objectName string Name of the object
return boolean TRUE if the object has been registered, otherwise FALSE

registerShutdownObject() public method

Registers the passed shutdown lifecycle method for the given object
public registerShutdownObject ( object $object, string $shutdownLifecycleMethodName ) : void
$object object The object to register the shutdown method for
$shutdownLifecycleMethodName string The method name of the shutdown method to be called
return void

setInstance() public method

Objects of scope sessions are assumed to be the real session object, not the lazy loading proxy.
public setInstance ( string $objectName, object $instance ) : void
$objectName string The object name
$instance object A prebuilt instance
return void

setObjects() public method

Sets the objects array
public setObjects ( array $objects ) : void
$objects array An array of object names and some information about each registered object (scope, lower cased name etc.)
return void

shutdown() public method

Shuts down this Object Container by calling the shutdown methods of all object instances which were configured to be shut down.
public shutdown ( ) : void
return void

Property Details

$allSettings protected property

An array of settings of all packages, indexed by package key
protected array $allSettings
return array

$cachedLowerCasedObjectNames protected property

protected array $cachedLowerCasedObjectNames
return array

$classesBeingInstantiated protected property

protected array $classesBeingInstantiated
return array

$context protected property

The configuration context for this Flow run
protected ApplicationContext,Neos\Flow\Core $context
return Neos\Flow\Core\ApplicationContext

$dependencyProxies protected property

protected array $dependencyProxies
return array

$internalShutdownObjects protected property

These shutdown method will be called after all other shutdown methods have been called.
protected SplObjectStorage $internalShutdownObjects
return SplObjectStorage

$objectSerializer protected property

protected ObjectSerializer,Neos\Flow\ObjectManagement $objectSerializer
return ObjectSerializer

$objects protected property

protected array $objects
return array

$shutdownObjects protected property

A SplObjectStorage containing those objects which need to be shutdown when the container shuts down. Each value of each entry is the respective shutdown method name.
protected SplObjectStorage $shutdownObjects
return SplObjectStorage