Neos\Flow\ObjectManagement\ObjectManager::setInstance PHP Метод

setInstance() публичный Метод

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
Результат void
    public function setInstance($objectName, $instance)
    {
        if (!isset($this->objects[$objectName])) {
            if (!class_exists($objectName, false)) {
                throw new Exception\UnknownObjectException('Cannot set instance of object "' . $objectName . '" because the object or class name is unknown to the Object Manager.', 1265370539);
            } else {
                throw new Exception\WrongScopeException('Cannot set instance of class "' . $objectName . '" because no matching object configuration was found. Classes which exist but are not registered are considered to be of scope prototype. However, setInstance() only accepts "session" and "singleton" instances. Check your object configuration and class name spellings.', 12653705341);
            }
        }
        if ($this->objects[$objectName]['s'] === ObjectConfiguration::SCOPE_PROTOTYPE) {
            throw new Exception\WrongScopeException('Cannot set instance of object "' . $objectName . '" because it is of scope prototype. Only session and singleton instances can be set.', 1265370540);
        }
        $this->objects[$objectName]['i'] = $instance;
    }

Usage Example

 /**
  * 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);
 }
All Usage Examples Of Neos\Flow\ObjectManagement\ObjectManager::setInstance