ObjectManager
class ObjectManager implements ObjectManagerInterface (View source)
Object Manager
Properties
protected ApplicationContext | $context | The configuration context for this Flow run |
|
protected array | $allSettings | An array of settings of all packages, indexed by package key |
|
protected array | $objects | ||
protected DependencyProxy[] | $dependencyProxies | ||
protected array | $classesBeingInstantiated | ||
protected array | $cachedLowerCasedObjectNames | ||
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. |
|
protected SplObjectStorage | $internalShutdownObjects | A SplObjectStorage containing only those shutdown objects which have been registered for Flow. |
Methods
Sets the objects array
Injects the global settings array, indexed by package key.
Returns the context Flow is running in.
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 scope of the specified object.
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.
Unsets the instance of the given object
Returns all instances of objects with scope session
Shuts down this Object Container by calling the shutdown methods of all object instances which were configured to be shut down.
Returns all current object configurations.
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.
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.
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
Objects of scope sessions are assumed to be the real session object, not the lazy loading proxy.
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.