CompileTimeObjectManager
class CompileTimeObjectManager extends ObjectManager (View source)
A specialized Object Manager which is able to do some basic dependency injection for singleton scoped objects. This Object Manager is used during compile time when the proxy class based DI mechanism is not yet available.
Properties
protected ApplicationContext | $context | The configuration context for this Flow run |
from ObjectManager |
protected array | $allSettings | An array of settings of all packages, indexed by package key |
from ObjectManager |
protected array | $objects | from ObjectManager | |
protected DependencyProxy[] | $dependencyProxies | from ObjectManager | |
protected array | $classesBeingInstantiated | from ObjectManager | |
protected array | $cachedLowerCasedObjectNames | from ObjectManager | |
protected SplObjectStorage | $shutdownObjects | 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. |
from ObjectManager |
protected SplObjectStorage | $internalShutdownObjects | A SplObjectStorage containing only those shutdown objects which have been registered for Flow. |
from ObjectManager |
protected VariableFrontend | $configurationCache | ||
protected ReflectionService | $reflectionService | ||
protected ConfigurationManager | $configurationManager | ||
protected LoggerInterface | $logger | ||
protected array | $objectConfigurations | ||
protected array | $registeredClassNames | A list of all class names known to the Object Manager |
|
protected array | $objectNameBuildStack | ||
protected array | $cachedClassNamesByScope |
Methods
Injects the global settings array, indexed by package key.
Returns true if an object with the given name is registered
Returns true if the container can return an entry for the given identifier.
Registers the passed shutdown lifecycle method for the given object
Returns a fresh or existing instance of the object specified by $objectName.
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.
Returns the object name corresponding to a given class name.
Returns the implementation class name for the specified object
Returns the key of the package the specified object is contained in.
Sets the instance of the given object
Returns true if this object manager already has an instance for the specified object.
Returns the instance of the specified object or NULL if no instance has been registered yet.
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.
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.
Shuts down this Object Container by calling the shutdown methods of all object instances which were configured to be shut down.
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.
Speed optimized alternative to ReflectionClass::newInstanceArgs()
Executes the methods of the provided objects.
Injects the configuration cache of the Object Framework
Injects the (system) logger based on PSR-3.
Initializes the the object configurations and some other parts of this Object Manager.
Returns a list of all class names, grouped by package key, which were registered by registerClassFiles()
Returns a list of class names, which are configured with the given scope
Traverses through all class files of the active packages and registers collects the class names as "all available class names". If the respective Flow settings say so, also function test classes are registered.
Given an array of class names by package key this filters out classes that have been configured to be included by object management.
Filters the classnames available for object management by filter expressions that includes classes.
Builds the objects array which contains information about the registered objects, their scope, class, built method etc.
Returns object configurations which were previously built by the ConfigurationBuilder.
Details
__construct(ApplicationContext $context)
Constructor for this Object Container
void
setObjects(array $objects)
Sets the objects array
void
injectAllSettings(array $settings)
Injects the global settings array, indexed by package key.
ApplicationContext
getContext()
Returns the context Flow is running in.
bool
isRegistered(string $objectName)
Returns true if an object with the given name is registered
bool
has(string $objectName)
Returns true if the container can return an entry for the given identifier.
Returns false otherwise.
void
registerShutdownObject(object $object, string $shutdownLifecycleMethodName)
Registers the passed shutdown lifecycle method for the given object
object
get(string $objectName, array ...$constructorArguments)
Returns a fresh or existing instance of the object specified by $objectName.
This specialized get() method is able to do setter injection for properties defined in the object configuration of the specified object.
int
getScope(string $objectName)
Returns the scope of the specified object.
string|null
getCaseSensitiveObjectName(string $caseInsensitiveObjectName)
internal |
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.
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.
string
getObjectNameByClassName(string $className)
Returns the object name corresponding to a given class name.
string
getClassNameByObjectName(string $objectName)
Returns the implementation class name for the specified object
string
getPackageKeyByObjectName(string $objectName)
internal |
Returns the key of the package the specified object is contained in.
void
setInstance(string $objectName, object $instance)
Sets the instance of the given object
In the Compile Time Object Manager it is even allowed to set instances of not-yet-known objects as long as the Object Manager is not initialized, because some few parts need an object registry even before the Object Manager is fully functional.
bool
hasInstance(string $objectName)
Returns true if this object manager already has an instance for the specified object.
object
getInstance(string $objectName)
Returns the instance of the specified object or NULL if no instance has been registered yet.
mixed
getLazyDependencyByHash(string $hash, mixed $propertyReferenceVariable)
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.
Internally used by the injectProperties method of generated proxy classes.
DependencyProxy
createLazyDependency(string $hash, string $propertyReferenceVariable, string $className, Closure $builder)
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.
Internally used by the injectProperties method of generated proxy classes.
void
forgetInstance(string $objectName)
Unsets the instance of the given object
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.
array
getSessionInstances()
Returns all instances of objects with scope session
void
shutdown()
Shuts down this Object Container by calling the shutdown methods of all object instances which were configured to be shut down.
array
getAllObjectConfigurations()
Returns all current object configurations.
For internal use in bootstrap only. Can change anytime.
protected object
buildObjectByFactory(string $objectName)
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 object
instantiateClass(string $className, array $arguments)
Speed optimized alternative to ReflectionClass::newInstanceArgs()
protected void
callShutdownMethods(SplObjectStorage $shutdownObjects)
Executes the methods of the provided objects.
void
injectReflectionService(ReflectionService $reflectionService)
No description
void
injectConfigurationManager(ConfigurationManager $configurationManager)
No description
void
injectConfigurationCache(VariableFrontend $configurationCache)
Injects the configuration cache of the Object Framework
void
injectLogger(LoggerInterface $logger)
Injects the (system) logger based on PSR-3.
void
initialize(array $packages)
Initializes the the object configurations and some other parts of this Object Manager.
array
getRegisteredClassNames()
Returns a list of all class names, grouped by package key, which were registered by registerClassFiles()
array
getClassNamesByScope(int $scope)
Returns a list of class names, which are configured with the given scope
protected array
registerClassFiles(array $packages)
Traverses through all class files of the active packages and registers collects the class names as "all available class names". If the respective Flow settings say so, also function test classes are registered.
For performance reasons this function ignores classes whose name ends with "Exception".
protected array
filterClassNamesFromConfiguration(array $classNames, array $includeClassesConfiguration)
Given an array of class names by package key this filters out classes that have been configured to be included by object management.
protected array
applyClassFilterConfiguration(array $classNames, array $filterConfiguration)
Filters the classnames available for object management by filter expressions that includes classes.
protected array
buildObjectsArray()
Builds the objects array which contains information about the registered objects, their scope, class, built method etc.
array
getObjectConfigurations()
Returns object configurations which were previously built by the ConfigurationBuilder.