/** * Initializes the runtime Object Manager * * @param Bootstrap $bootstrap * @return void */ public static function initializeObjectManager(Bootstrap $bootstrap) { $configurationManager = $bootstrap->getEarlyInstance(ConfigurationManager::class); $objectConfigurationCache = $bootstrap->getEarlyInstance(CacheManager::class)->getCache('Flow_Object_Configuration'); $objectManager = new ObjectManager($bootstrap->getContext()); Bootstrap::$staticObjectManager = $objectManager; $objectManager->injectAllSettings($configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS)); $objectManager->setObjects($objectConfigurationCache->get('objects')); foreach ($bootstrap->getEarlyInstances() as $objectName => $instance) { $objectManager->setInstance($objectName, $instance); } $objectManager->get(Dispatcher::class)->injectObjectManager($objectManager); Debugger::injectObjectManager($objectManager); $bootstrap->setEarlyInstance(ObjectManagerInterface::class, $objectManager); }
/** * 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. * * @param string $objectName The object name * @param object $instance A prebuilt instance * @return void */ public function setInstance($objectName, $instance) { if ($this->registeredClassNames === []) { $this->objects[$objectName]['i'] = $instance; } else { parent::setInstance($objectName, $instance); } }