getObjectManager() public method

Returns the object manager instance
public getObjectManager ( ) : Neos\Flow\ObjectManagement\ObjectManagerInterface
return Neos\Flow\ObjectManagement\ObjectManagerInterface
 /**
  * Creates an event loop which takes orders from the parent process and executes
  * them in runtime mode.
  *
  * @return void
  */
 public function handleRequest()
 {
     $sequence = $this->bootstrap->buildRuntimeSequence();
     $sequence->invoke($this->bootstrap);
     $objectManager = $this->bootstrap->getObjectManager();
     $systemLogger = $objectManager->get(SystemLoggerInterface::class);
     $systemLogger->log('Running sub process loop.', LOG_DEBUG);
     echo "\nREADY\n";
     try {
         while (true) {
             $commandLine = trim(fgets(STDIN));
             $trimmedCommandLine = trim($commandLine);
             $systemLogger->log(sprintf('Received command "%s".', $trimmedCommandLine), LOG_INFO);
             if ($commandLine === "QUIT\n") {
                 break;
             }
             /** @var Request $request */
             $request = $objectManager->get(RequestBuilder::class)->build($trimmedCommandLine);
             $response = new Response();
             if ($this->bootstrap->isCompiletimeCommand($request->getCommand()->getCommandIdentifier())) {
                 echo "This command must be executed during compiletime.\n";
             } else {
                 $objectManager->get(Dispatcher::class)->dispatch($request, $response);
                 $response->send();
                 $this->emitDispatchedCommandLineSlaveRequest();
             }
             echo "\nREADY\n";
         }
         $systemLogger->log('Exiting sub process loop.', LOG_DEBUG);
         $this->bootstrap->shutdown(Bootstrap::RUNLEVEL_RUNTIME);
         exit($response->getExitCode());
     } catch (\Exception $exception) {
         $this->handleException($exception);
     }
 }
 /**
  * Sends the given HTTP request
  *
  * @param Http\Request $httpRequest
  * @return Http\Response
  * @throws Http\Exception
  * @api
  */
 public function sendRequest(Http\Request $httpRequest)
 {
     $requestHandler = $this->bootstrap->getActiveRequestHandler();
     if (!$requestHandler instanceof FunctionalTestRequestHandler) {
         throw new Http\Exception('The browser\'s internal request engine has only been designed for use within functional tests.', 1335523749);
     }
     $this->securityContext->clearContext();
     $this->validatorResolver->reset();
     $response = new Http\Response();
     $componentContext = new ComponentContext($httpRequest, $response);
     $requestHandler->setComponentContext($componentContext);
     $objectManager = $this->bootstrap->getObjectManager();
     $baseComponentChain = $objectManager->get(\Neos\Flow\Http\Component\ComponentChain::class);
     $componentContext = new ComponentContext($httpRequest, $response);
     try {
         $baseComponentChain->handle($componentContext);
     } catch (\Throwable $throwable) {
         $this->prepareErrorResponse($throwable, $componentContext->getHttpResponse());
     } catch (\Exception $exception) {
         $this->prepareErrorResponse($exception, $componentContext->getHttpResponse());
     }
     $session = $this->bootstrap->getObjectManager()->get(SessionInterface::class);
     if ($session->isStarted()) {
         $session->close();
     }
     $this->persistenceManager->clearState();
     return $componentContext->getHttpResponse();
 }
 /**
  * Initializes the matching boot sequence depending on the type of the command
  * (RUNLEVEL_RUNTIME or RUNLEVEL_COMPILETIME) and manually injects the necessary dependencies of
  * this request handler.
  *
  * @param string $runlevel one of the Bootstrap::RUNLEVEL_* constants
  * @return void
  */
 protected function boot($runlevel)
 {
     $sequence = $runlevel === Bootstrap::RUNLEVEL_COMPILETIME ? $this->bootstrap->buildCompiletimeSequence() : $this->bootstrap->buildRuntimeSequence();
     $sequence->invoke($this->bootstrap);
     $this->objectManager = $this->bootstrap->getObjectManager();
     $this->dispatcher = $this->objectManager->get(Dispatcher::class);
 }
 /**
  * Resolves a few dependencies of this request handler which can't be resolved
  * automatically due to the early stage of the boot process this request handler
  * is invoked at.
  *
  * @return void
  */
 protected function resolveDependencies()
 {
     $objectManager = $this->bootstrap->getObjectManager();
     $this->baseComponentChain = $objectManager->get(ComponentChain::class);
     $configurationManager = $objectManager->get(ConfigurationManager::class);
     $this->settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow');
 }
 /**
  * Refreezes a package
  *
  * @param string $packageKey The package to refreeze
  * @return void
  */
 public function refreezePackage($packageKey)
 {
     if (!$this->isPackageFrozen($packageKey)) {
         return;
     }
     $this->bootstrap->getObjectManager()->get(ReflectionService::class)->unfreezePackageReflection($packageKey);
 }
 /**
  * Cleans up the directory for storing persistent resources during testing
  *
  * @return void
  * @throws \Exception
  */
 protected function cleanupPersistentResourcesDirectory()
 {
     $settings = self::$bootstrap->getObjectManager()->get(ConfigurationManager::class)->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS);
     $resourcesStoragePath = $settings['Neos']['Flow']['resource']['storages']['defaultPersistentResourcesStorage']['storageOptions']['path'];
     if (strpos($resourcesStoragePath, FLOW_PATH_DATA) === false) {
         throw new \Exception(sprintf('The storage path for persistent resources for the Testing context is "%s" but it must point to a directory below "%s". Please check the Flow settings for the Testing context.', $resourcesStoragePath, FLOW_PATH_DATA), 1382018388);
     }
     if (file_exists($resourcesStoragePath)) {
         Files::removeDirectoryRecursively($resourcesStoragePath);
     }
 }
Esempio n. 7
0
 /**
  * Returns autocomplete suggestions on hitting the TAB key.
  *
  * @param string $partialCommand The current (partial) command where the TAB key was hit
  * @param integer $index The cursor index at the current (partial) command
  * @return array
  */
 protected function autocomplete($partialCommand, $index)
 {
     // @TODO Add more functionality by parsing the current buffer with readline_info()
     // @TODO Filter file system elements (if possible at all)
     $suggestions = [];
     $availableCommands = $this->bootstrap->getObjectManager()->get(CommandManager::class)->getAvailableCommands();
     /** @var $command Command */
     foreach ($availableCommands as $command) {
         if ($command->isInternal() === false) {
             $suggestions[] = $command->getCommandIdentifier();
         }
     }
     return $suggestions;
 }
 /**
  * Invokes custom PHP code directly after the package manager has been initialized.
  *
  * @param Bootstrap $bootstrap The current bootstrap
  * @return void
  */
 public function boot(Bootstrap $bootstrap)
 {
     $dispatcher = $bootstrap->getSignalSlotDispatcher();
     $dispatcher->connect(PersistenceManager::class, 'allObjectsPersisted', NodeDataRepository::class, 'flushNodeRegistry');
     $dispatcher->connect(NodeDataRepository::class, 'repositoryObjectsPersisted', NodeDataRepository::class, 'flushNodeRegistry');
     $dispatcher->connect(Node::class, 'nodePathChanged', function () use($bootstrap) {
         $contextFactory = $bootstrap->getObjectManager()->get(ContextFactoryInterface::class);
         /** @var Context $contextInstance */
         foreach ($contextFactory->getInstances() as $contextInstance) {
             $contextInstance->getFirstLevelNodeCache()->flush();
         }
     });
     $dispatcher->connect(ConfigurationManager::class, 'configurationManagerReady', function (ConfigurationManager $configurationManager) {
         $configurationManager->registerConfigurationType('NodeTypes', ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, true);
     });
     $context = $bootstrap->getContext();
     if (!$context->isProduction()) {
         $dispatcher->connect(Sequence::class, 'afterInvokeStep', function ($step) use($bootstrap) {
             if ($step->getIdentifier() === 'typo3.flow:systemfilemonitor') {
                 $nodeTypeConfigurationFileMonitor = FileMonitor::createFileMonitorAtBoot('TYPO3CR_NodeTypesConfiguration', $bootstrap);
                 $packageManager = $bootstrap->getEarlyInstance(PackageManagerInterface::class);
                 foreach ($packageManager->getActivePackages() as $packageKey => $package) {
                     if ($packageManager->isPackageFrozen($packageKey)) {
                         continue;
                     }
                     if (file_exists($package->getConfigurationPath())) {
                         $nodeTypeConfigurationFileMonitor->monitorDirectory($package->getConfigurationPath(), 'NodeTypes(\\..+)\\.yaml');
                     }
                 }
                 $nodeTypeConfigurationFileMonitor->monitorDirectory(FLOW_PATH_CONFIGURATION, 'NodeTypes(\\..+)\\.yaml');
                 $nodeTypeConfigurationFileMonitor->detectChanges();
                 $nodeTypeConfigurationFileMonitor->shutdownObject();
             }
         });
     }
 }
 /**
  * @param Bootstrap $bootstrap The current bootstrap
  * @return void
  */
 public function boot(Bootstrap $bootstrap)
 {
     $dispatcher = $bootstrap->getSignalSlotDispatcher();
     $flushConfigurationCache = function () use($bootstrap) {
         $cacheManager = $bootstrap->getEarlyInstance(CacheManager::class);
         $cacheManager->getCache('TYPO3_Neos_Configuration_Version')->flush();
     };
     $flushXliffServiceCache = function () use($bootstrap) {
         $cacheManager = $bootstrap->getEarlyInstance(CacheManager::class);
         $cacheManager->getCache('TYPO3_Neos_XliffToJsonTranslations')->flush();
     };
     $dispatcher->connect(FileMonitor::class, 'filesHaveChanged', function ($fileMonitorIdentifier, array $changedFiles) use($flushConfigurationCache, $flushXliffServiceCache) {
         switch ($fileMonitorIdentifier) {
             case 'TYPO3CR_NodeTypesConfiguration':
             case 'Flow_ConfigurationFiles':
                 $flushConfigurationCache();
                 break;
             case 'Flow_TranslationFiles':
                 $flushConfigurationCache();
                 $flushXliffServiceCache();
         }
     });
     $dispatcher->connect(Site::class, 'siteChanged', $flushConfigurationCache);
     $dispatcher->connect(Site::class, 'siteChanged', RouterCachingService::class, 'flushCaches');
     $dispatcher->connect(Node::class, 'nodeUpdated', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'nodeAdded', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'nodeRemoved', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'beforeNodeMove', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(AssetService::class, 'assetResourceReplaced', ContentCacheFlusher::class, 'registerAssetResourceChange');
     $dispatcher->connect(Node::class, 'nodeAdded', NodeUriPathSegmentGenerator::class, '::setUniqueUriPathSegment');
     $dispatcher->connect(Node::class, 'nodePropertyChanged', Service\ImageVariantGarbageCollector::class, 'removeUnusedImageVariant');
     $dispatcher->connect(Node::class, 'nodePropertyChanged', function (NodeInterface $node, $propertyName) use($bootstrap) {
         if ($propertyName === 'uriPathSegment') {
             NodeUriPathSegmentGenerator::setUniqueUriPathSegment($node);
             $bootstrap->getObjectManager()->get(RouteCacheFlusher::class)->registerNodeChange($node);
         }
     });
     $dispatcher->connect(Node::class, 'nodePathChanged', function (NodeInterface $node, $oldPath, $newPath, $recursion) {
         if (!$recursion) {
             NodeUriPathSegmentGenerator::setUniqueUriPathSegment($node);
         }
     });
     $dispatcher->connect(PublishingService::class, 'nodePublished', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(PublishingService::class, 'nodeDiscarded', ContentCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'nodePathChanged', RouteCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(Node::class, 'nodeRemoved', RouteCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(PublishingService::class, 'nodeDiscarded', RouteCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(PublishingService::class, 'nodePublished', RouteCacheFlusher::class, 'registerNodeChange');
     $dispatcher->connect(PublishingService::class, 'nodePublished', function ($node, $targetWorkspace) use($bootstrap) {
         $cacheManager = $bootstrap->getObjectManager()->get(CacheManager::class);
         if ($cacheManager->hasCache('Flow_Persistence_Doctrine')) {
             $cacheManager->getCache('Flow_Persistence_Doctrine')->flush();
         }
     });
     $dispatcher->connect(PersistenceManager::class, 'allObjectsPersisted', RouteCacheFlusher::class, 'commit');
     $dispatcher->connect(SiteService::class, 'sitePruned', ContentCache::class, 'flush');
     $dispatcher->connect(SiteService::class, 'sitePruned', RouterCachingService::class, 'flushCaches');
     $dispatcher->connect(SiteImportService::class, 'siteImported', ContentCache::class, 'flush');
     $dispatcher->connect(SiteImportService::class, 'siteImported', RouterCachingService::class, 'flushCaches');
     // Eventlog
     $dispatcher->connect(Node::class, 'beforeNodeCreate', ContentRepositoryIntegrationService::class, 'beforeNodeCreate');
     $dispatcher->connect(Node::class, 'afterNodeCreate', ContentRepositoryIntegrationService::class, 'afterNodeCreate');
     $dispatcher->connect(Node::class, 'nodeUpdated', ContentRepositoryIntegrationService::class, 'nodeUpdated');
     $dispatcher->connect(Node::class, 'nodeRemoved', ContentRepositoryIntegrationService::class, 'nodeRemoved');
     $dispatcher->connect(Node::class, 'beforeNodePropertyChange', ContentRepositoryIntegrationService::class, 'beforeNodePropertyChange');
     $dispatcher->connect(Node::class, 'nodePropertyChanged', ContentRepositoryIntegrationService::class, 'nodePropertyChanged');
     $dispatcher->connect(Node::class, 'beforeNodeCopy', ContentRepositoryIntegrationService::class, 'beforeNodeCopy');
     $dispatcher->connect(Node::class, 'afterNodeCopy', ContentRepositoryIntegrationService::class, 'afterNodeCopy');
     $dispatcher->connect(Node::class, 'beforeNodeMove', ContentRepositoryIntegrationService::class, 'beforeNodeMove');
     $dispatcher->connect(Node::class, 'afterNodeMove', ContentRepositoryIntegrationService::class, 'afterNodeMove');
     $dispatcher->connect(Context::class, 'beforeAdoptNode', ContentRepositoryIntegrationService::class, 'beforeAdoptNode');
     $dispatcher->connect(Context::class, 'afterAdoptNode', ContentRepositoryIntegrationService::class, 'afterAdoptNode');
     $dispatcher->connect(Workspace::class, 'beforeNodePublishing', ContentRepositoryIntegrationService::class, 'beforeNodePublishing');
     $dispatcher->connect(Workspace::class, 'afterNodePublishing', ContentRepositoryIntegrationService::class, 'afterNodePublishing');
     $dispatcher->connect(PersistenceManager::class, 'allObjectsPersisted', ContentRepositoryIntegrationService::class, 'updateEventsAfterPublish');
     $dispatcher->connect(NodeDataRepository::class, 'repositoryObjectsPersisted', ContentRepositoryIntegrationService::class, 'updateEventsAfterPublish');
 }
 /**
  * Initialize the stream wrappers.
  *
  * @param Bootstrap $bootstrap
  * @return void
  */
 public static function initializeResources(Bootstrap $bootstrap)
 {
     StreamWrapperAdapter::initializeStreamWrapper($bootstrap->getObjectManager());
 }
 /**
  * Helper method to create a FileMonitor instance during boot sequence as injections have to be done manually.
  *
  * @param string $identifier
  * @param Bootstrap $bootstrap
  * @return FileMonitor
  */
 public static function createFileMonitorAtBoot($identifier, Bootstrap $bootstrap)
 {
     $fileMonitorCache = $bootstrap->getEarlyInstance(CacheManager::class)->getCache('Flow_Monitor');
     // The change detector needs to be instantiated and registered manually because
     // it has a complex dependency (cache) but still needs to be a singleton.
     $fileChangeDetector = new ChangeDetectionStrategy\ModificationTimeStrategy();
     $fileChangeDetector->injectCache($fileMonitorCache);
     $bootstrap->getObjectManager()->registerShutdownObject($fileChangeDetector, 'shutdownObject');
     $fileMonitor = new FileMonitor($identifier);
     $fileMonitor->injectCache($fileMonitorCache);
     $fileMonitor->injectChangeDetectionStrategy($fileChangeDetector);
     $fileMonitor->injectSignalDispatcher($bootstrap->getEarlyInstance(Dispatcher::class));
     $fileMonitor->injectSystemLogger($bootstrap->getEarlyInstance(SystemLoggerInterface::class));
     return $fileMonitor;
 }
Esempio n. 12
0
 /**
  * Invokes custom PHP code directly after the package manager has been initialized.
  *
  * @param Core\Bootstrap $bootstrap The current bootstrap
  * @return void
  */
 public function boot(Core\Bootstrap $bootstrap)
 {
     $bootstrap->registerRequestHandler(new Cli\SlaveRequestHandler($bootstrap));
     $bootstrap->registerRequestHandler(new Cli\CommandRequestHandler($bootstrap));
     $bootstrap->registerRequestHandler(new Http\RequestHandler($bootstrap));
     if ($bootstrap->getContext()->isTesting()) {
         $bootstrap->registerRequestHandler(new Tests\FunctionalTestRequestHandler($bootstrap));
     }
     $bootstrap->registerCompiletimeCommand('neos.flow:core:*');
     $bootstrap->registerCompiletimeCommand('neos.flow:cache:flush');
     $bootstrap->registerCompiletimeCommand('neos.flow:package:rescan');
     $dispatcher = $bootstrap->getSignalSlotDispatcher();
     $dispatcher->connect(\Neos\Flow\Mvc\Dispatcher::class, 'afterControllerInvocation', function ($request) use($bootstrap) {
         if ($bootstrap->getObjectManager()->hasInstance(\Neos\Flow\Persistence\PersistenceManagerInterface::class)) {
             if (!$request instanceof Mvc\ActionRequest || $request->getHttpRequest()->isMethodSafe() !== true) {
                 $bootstrap->getObjectManager()->get(\Neos\Flow\Persistence\PersistenceManagerInterface::class)->persistAll();
             } elseif ($request->getHttpRequest()->isMethodSafe()) {
                 $bootstrap->getObjectManager()->get(\Neos\Flow\Persistence\PersistenceManagerInterface::class)->persistAll(true);
             }
         }
     });
     $dispatcher->connect(\Neos\Flow\Cli\SlaveRequestHandler::class, 'dispatchedCommandLineSlaveRequest', \Neos\Flow\Persistence\PersistenceManagerInterface::class, 'persistAll');
     $context = $bootstrap->getContext();
     if (!$context->isProduction()) {
         $dispatcher->connect(\Neos\Flow\Core\Booting\Sequence::class, 'afterInvokeStep', function ($step) use($bootstrap, $dispatcher) {
             if ($step->getIdentifier() === 'neos.flow:resources') {
                 $publicResourcesFileMonitor = \Neos\Flow\Monitor\FileMonitor::createFileMonitorAtBoot('Flow_PublicResourcesFiles', $bootstrap);
                 $packageManager = $bootstrap->getEarlyInstance(\Neos\Flow\Package\PackageManagerInterface::class);
                 foreach ($packageManager->getActivePackages() as $packageKey => $package) {
                     if ($packageManager->isPackageFrozen($packageKey)) {
                         continue;
                     }
                     $publicResourcesPath = $package->getResourcesPath() . 'Public/';
                     if (is_dir($publicResourcesPath)) {
                         $publicResourcesFileMonitor->monitorDirectory($publicResourcesPath);
                     }
                 }
                 $publicResourcesFileMonitor->detectChanges();
                 $publicResourcesFileMonitor->shutdownObject();
             }
         });
     }
     $publishResources = function ($identifier, $changedFiles) use($bootstrap) {
         if ($identifier !== 'Flow_PublicResourcesFiles') {
             return;
         }
         $objectManager = $bootstrap->getObjectManager();
         $resourceManager = $objectManager->get(\Neos\Flow\ResourceManagement\ResourceManager::class);
         $resourceManager->getCollection(ResourceManager::DEFAULT_STATIC_COLLECTION_NAME)->publish();
     };
     $dispatcher->connect(\Neos\Flow\Monitor\FileMonitor::class, 'filesHaveChanged', $publishResources);
     $dispatcher->connect(\Neos\Flow\Core\Bootstrap::class, 'bootstrapShuttingDown', \Neos\Flow\Configuration\ConfigurationManager::class, 'shutdown');
     $dispatcher->connect(\Neos\Flow\Core\Bootstrap::class, 'bootstrapShuttingDown', \Neos\Flow\ObjectManagement\ObjectManagerInterface::class, 'shutdown');
     $dispatcher->connect(\Neos\Flow\Core\Bootstrap::class, 'bootstrapShuttingDown', \Neos\Flow\Reflection\ReflectionService::class, 'saveToCache');
     $dispatcher->connect(\Neos\Flow\Command\CoreCommandController::class, 'finishedCompilationRun', \Neos\Flow\Security\Authorization\Privilege\Method\MethodPrivilegePointcutFilter::class, 'savePolicyCache');
     $dispatcher->connect(\Neos\Flow\Command\CoreCommandController::class, 'finishedCompilationRun', \Neos\Flow\Aop\Pointcut\RuntimeExpressionEvaluator::class, 'saveRuntimeExpressions');
     $dispatcher->connect(\Neos\Flow\Security\Authentication\AuthenticationProviderManager::class, 'authenticatedToken', function () use($bootstrap) {
         $session = $bootstrap->getObjectManager()->get(\Neos\Flow\Session\SessionInterface::class);
         if ($session->isStarted()) {
             $session->renewId();
         }
     });
     $dispatcher->connect(\Neos\Flow\Monitor\FileMonitor::class, 'filesHaveChanged', \Neos\Flow\Cache\CacheManager::class, 'flushSystemCachesByChangedFiles');
     $dispatcher->connect(\Neos\Flow\Tests\FunctionalTestCase::class, 'functionalTestTearDown', \Neos\Flow\Mvc\Routing\RouterCachingService::class, 'flushCaches');
     $dispatcher->connect(\Neos\Flow\Configuration\ConfigurationManager::class, 'configurationManagerReady', function (Configuration\ConfigurationManager $configurationManager) {
         $configurationManager->registerConfigurationType('Views', Configuration\ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_APPEND);
     });
     $dispatcher->connect(\Neos\Flow\Command\CacheCommandController::class, 'warmupCaches', \Neos\Flow\Configuration\ConfigurationManager::class, 'warmup');
     $dispatcher->connect(\Neos\Flow\Package\PackageManager::class, 'packageStatesUpdated', function () use($dispatcher) {
         $dispatcher->connect(\Neos\Flow\Core\Bootstrap::class, 'bootstrapShuttingDown', \Neos\Flow\Cache\CacheManager::class, 'flushCaches');
     });
 }