public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) { // 1. Make Gedmo\Translatable\Entity\Translation known to Doctrine, so that it can participate in Database Schema Generation // // Internally, we use a MappingDriverChain for that, which delegates almost all of its behavior to the already-existing // FlowAnnotationDriver. We additionally add the (default doctrine) Annotation Driver for the Gedmo namespace. // // Note: We replace FlowAnnotationDriver *on a very low level* with the *MappingDriverChain* object; because this class // is only used inside EntityManagerFactory -- so we know quite exactly what methods are called on that object. $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\Flow\\Core\\Booting\\Sequence', 'beforeInvokeStep', function ($step) use($bootstrap) { if ($step->getIdentifier() === 'typo3.flow:resources') { $flowAnnotationDriver = $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Persistence\\Doctrine\\Mapping\\Driver\\FlowAnnotationDriver'); $driverChain = new MappingDriverChainWithFlowAnnotationDriverAsDefault($flowAnnotationDriver); $driverChain->addDriver(new AnnotationDriver(ObjectAccess::getProperty($flowAnnotationDriver, 'reader', TRUE), FLOW_PATH_PACKAGES . 'Libraries/gedmo/doctrine-extensions/lib/Gedmo/Translatable/Entity'), 'Gedmo'); $bootstrap->getObjectManager()->setInstance('TYPO3\\Flow\\Persistence\\Doctrine\\Mapping\\Driver\\FlowAnnotationDriver', $driverChain); } }); // 2. Work around a bug in TYPO3\Flow\Persistence\Doctrine\PersistenceManager::onFlush which expects that all objects in the // Doctrine subsystem are entities known to Flow. // // The line $this->reflectionService->getClassSchema($entity)->getModelType() triggers a fatal error, for get_class($entity) == 'Gedmo\Translatable\Entity\Translation' // because this class is known only to Doctrine (see 1. above), but not to the Flow reflection service. // // As a workaround, we just add an empty placeholder class schema to the Class Schemata cache, right before the class schema is saved // inside the TYPO3\Flow\Core\Bootstrap::bootstrapShuttingDown signal (which is fired directly after "finishedCompiletimeRun"). $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\Flow\\Core\\Bootstrap', 'finishedCompiletimeRun', function () use($bootstrap) { $classSchemataCache = $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Cache\\CacheManager')->getCache('Flow_Reflection_RuntimeClassSchemata'); if (!$classSchemataCache->has('Gedmo_Translatable_Entity_Translation')) { $classSchemataCache->set('Gedmo_Translatable_Entity_Translation', new ClassSchema('Gedmo\\Translatable\\Entity\\Translation')); } }); }
/** * 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); } }
/** */ public function __construct() { if (self::$bootstrap === NULL) { self::$bootstrap = $this->initializeFlow(); } $this->objectManager = self::$bootstrap->getObjectManager(); }
/** * Retrieve current authenticated account * * @return \TYPO3\Flow\Security\Account|NULL */ public static function getAuthenticatedAccount() { self::initializeBootstrap(); if (self::$bootstrap) { $objectManager = self::$bootstrap->getObjectManager(); if ($objectManager) { $securityContext = $objectManager->get('\\TYPO3\\Flow\\Security\\Context'); if ($securityContext && $securityContext->canBeInitialized()) { return $securityContext->getAccount(); } } } return null; }
/** * Initializes the matching boot sequence depending on the type of the command * (runtime or compiletime) and manually injects the necessary dependencies of * this request handler. * * @param string $runlevel Either "Compiletime" or "Runtime" * @return void */ protected function boot($runlevel) { $sequence = $runlevel === 'Compiletime' ? $this->bootstrap->buildCompiletimeSequence() : $this->bootstrap->buildRuntimeSequence(); $sequence->invoke($this->bootstrap); $this->objectManager = $this->bootstrap->getObjectManager(); $this->dispatcher = $this->objectManager->get('TYPO3\\Flow\\Mvc\\Dispatcher'); }
/** * 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(); $requestHandler->setHttpRequest($httpRequest); $requestHandler->setHttpResponse($response); $objectManager = $this->bootstrap->getObjectManager(); $baseComponentChain = $objectManager->get(\TYPO3\Flow\Http\Component\ComponentChain::class); $componentContext = new ComponentContext($httpRequest, $response); if (version_compare(PHP_VERSION, '6.0.0') >= 0) { try { $baseComponentChain->handle($componentContext); } catch (\Throwable $throwable) { $this->prepareErrorResponse($throwable, $response); } } else { try { $baseComponentChain->handle($componentContext); } catch (\Exception $exception) { $this->prepareErrorResponse($exception, $response); } } $session = $this->bootstrap->getObjectManager()->get(\TYPO3\Flow\Session\SessionInterface::class); if ($session->isStarted()) { $session->close(); } $this->persistenceManager->clearState(); return $response; }
/** * 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('TYPO3\\Flow\\Http\\Component\\ComponentChain'); $configurationManager = $objectManager->get('TYPO3\\Flow\\Configuration\\ConfigurationManager'); $this->settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.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(\TYPO3\Flow\Reflection\ReflectionService::class)->unfreezePackageReflection($packageKey); }
/** * 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(\TYPO3\Flow\Mvc\Dispatcher::class); }
/** * @param string $path * @return string * @throws \Exception */ public function render($path = NULL) { if ($path === NULL) { $path = '404'; } /** @var RequestHandler $activeRequestHandler */ $activeRequestHandler = $this->bootstrap->getActiveRequestHandler(); $parentHttpRequest = $activeRequestHandler->getHttpRequest(); $requestPath = $parentHttpRequest->getUri()->getPath(); $language = explode('/', ltrim($requestPath, '/'))[0]; if ($language === 'neos') { throw new \Exception('NotFoundViewHelper can not be used for neos-routes.', 1435648210); } $language = $this->localeDetector->detectLocaleFromLocaleTag($language)->getLanguage(); if ($this->contentDimensionPresetSource->findPresetByUriSegment('language', $language) === NULL) { $language = ''; } if ($language !== '') { $language .= '/'; } $request = Request::create(new Uri(rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $language . $path)); $matchingRoute = $this->router->route($request); if (!$matchingRoute) { throw new \Exception(sprintf('Uri with path "%s" could not be found.', rtrim($parentHttpRequest->getBaseUri(), '/') . '/' . $language . $path), 1426446160); } $response = new Response(); $objectManager = $this->bootstrap->getObjectManager(); $baseComponentChain = $objectManager->get('TYPO3\\Flow\\Http\\Component\\ComponentChain'); $componentContext = new ComponentContext($request, $response); $baseComponentChain->handle($componentContext); return $response->getContent(); }
/** * Registers slots for signals in order to be able to index nodes * * @param Bootstrap $bootstrap */ public function registerExtractionSlot(Bootstrap $bootstrap) { $configurationManager = $bootstrap->getObjectManager()->get(ConfigurationManager::class); $settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->getPackageKey()); if (isset($settings['realtimeExtraction']['enabled']) && $settings['realtimeExtraction']['enabled'] === TRUE) { $dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher->connect(Asset::class, 'assetCreated', ExtractionManager::class, 'extractMetaData'); } }
/** * @param \TYPO3\Flow\Core\Bootstrap $bootstrap */ public function prepareRealtimeIndexing(\TYPO3\Flow\Core\Bootstrap $bootstrap) { $this->configurationManager = $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Configuration\\ConfigurationManager'); $settings = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->getPackageKey()); if (isset($settings['realtimeIndexing']['enabled']) && $settings['realtimeIndexing']['enabled'] === TRUE) { $bootstrap->getSignalSlotDispatcher()->connect('Flowpack\\ElasticSearch\\Indexer\\Object\\Signal\\SignalEmitter', 'objectUpdated', 'Flowpack\\ElasticSearch\\Indexer\\Object\\ObjectIndexer', 'indexObject'); $bootstrap->getSignalSlotDispatcher()->connect('Flowpack\\ElasticSearch\\Indexer\\Object\\Signal\\SignalEmitter', 'objectPersisted', 'Flowpack\\ElasticSearch\\Indexer\\Object\\ObjectIndexer', 'indexObject'); $bootstrap->getSignalSlotDispatcher()->connect('Flowpack\\ElasticSearch\\Indexer\\Object\\Signal\\SignalEmitter', 'objectRemoved', 'Flowpack\\ElasticSearch\\Indexer\\Object\\ObjectIndexer', 'removeObject'); } }
/** * @param \TYPO3\Flow\Core\Bootstrap $bootstrap The current bootstrap * @return void */ public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) { $dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher->connect('TYPO3\\Flow\\Mvc\\Dispatcher', 'afterControllerInvocation', function ($request) use($bootstrap) { if (!$request instanceof \TYPO3\Flow\Mvc\ActionRequest || $request->getHttpRequest()->isMethodSafe() !== TRUE) { $bootstrap->getObjectManager()->get('Radmiraal\\CouchDB\\CouchDBHelper')->flush(); } }); $dispatcher->connect('TYPO3\\Flow\\Cli\\SlaveRequestHandler', 'dispatchedCommandLineSlaveRequest', 'Radmiraal\\CouchDB\\CouchDBHelper', 'flush'); }
/** * 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->dispatcher = $objectManager->get('TYPO3\\Flow\\Mvc\\Dispatcher'); $configurationManager = $objectManager->get('TYPO3\\Flow\\Configuration\\ConfigurationManager'); $this->settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'TYPO3.Flow'); $this->routesConfiguration = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_ROUTES); $this->router = $objectManager->get('TYPO3\\Flow\\Mvc\\Routing\\Router'); $this->securityContext = $objectManager->get('TYPO3\\Flow\\Security\\Context'); }
/** * Cleans up the directory for storing persistent resources during testing * * @return void * @throws \Exception */ protected function cleanupPersistentResourcesDirectory() { $settings = self::$bootstrap->getObjectManager()->get(\TYPO3\Flow\Configuration\ConfigurationManager::class)->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS); $resourcesStoragePath = $settings['TYPO3']['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); } }
/** * @param Bootstrap $bootstrap The current bootstrap * @return void */ public function boot(Bootstrap $bootstrap) { $dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher->connect('TYPO3\\Flow\\Core\\Booting\\Sequence', 'afterInvokeStep', function ($step) use($bootstrap) { if ($step instanceof \TYPO3\Flow\Core\Booting\Step && $step->getIdentifier() == 'typo3.flow:persistence') { /** @var \Doctrine\Common\Persistence\ObjectManager $entityManager */ $entityManager = $bootstrap->getObjectManager()->get(\Doctrine\Common\Persistence\ObjectManager::class); $entityManager->getConnection()->getDatabasePlatform()->registerDoctrineTypeMapping('enum', 'string'); } }); }
/** * {@inheritdoc} */ public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) { require_once FLOW_PATH_PACKAGES . '/Libraries/raven/raven/lib/Raven/Autoloader.php'; \Raven_Autoloader::register(); $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\Flow\\Core\\Booting\\Sequence', 'afterInvokeStep', function ($step, $runlevel) use($bootstrap) { if ($step->getIdentifier() === 'typo3.flow:objectmanagement:runtime') { // This triggers the initializeObject method $bootstrap->getObjectManager()->get('Networkteam\\SentryClient\\ErrorHandler'); } }); }
/** * Registers slots for signals in order to be able to index nodes * * @param Bootstrap $bootstrap */ public function registerIndexingSlots(Bootstrap $bootstrap) { $configurationManager = $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Configuration\\ConfigurationManager'); $settings = $configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, $this->getPackageKey()); if (isset($settings['realtimeIndexing']['enabled']) && $settings['realtimeIndexing']['enabled'] === TRUE) { $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeAdded', 'TYPO3\\TYPO3CR\\Search\\Indexer\\NodeIndexingManager', 'indexNode'); $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeUpdated', 'TYPO3\\TYPO3CR\\Search\\Indexer\\NodeIndexingManager', 'indexNode'); $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeRemoved', 'TYPO3\\TYPO3CR\\Search\\Indexer\\NodeIndexingManager', 'removeNode'); $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\Neos\\Service\\PublishingService', 'nodePublished', 'TYPO3\\TYPO3CR\\Search\\Indexer\\NodeIndexingManager', 'indexNode', FALSE); $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\Flow\\Persistence\\Doctrine\\PersistenceManager', 'allObjectsPersisted', 'TYPO3\\TYPO3CR\\Search\\Indexer\\NodeIndexingManager', 'flushQueues'); } }
/** * 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 = array(); $availableCommands = $this->bootstrap->getObjectManager()->get(\TYPO3\Flow\Cli\CommandManager::class)->getAvailableCommands(); /** @var $command \TYPO3\Flow\Cli\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 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('typo3.flow:core:*'); $bootstrap->registerCompiletimeCommand('typo3.flow:cache:flush'); $dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher->connect('TYPO3\\Flow\\Mvc\\Dispatcher', 'afterControllerInvocation', function ($request) use($bootstrap) { if (!$request instanceof Mvc\ActionRequest || $request->getHttpRequest()->isMethodSafe() !== TRUE) { $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Persistence\\PersistenceManagerInterface')->persistAll(); } elseif ($request->getHttpRequest()->isMethodSafe()) { $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Persistence\\PersistenceManagerInterface')->persistAll(TRUE); } }); $dispatcher->connect('TYPO3\\Flow\\Cli\\SlaveRequestHandler', 'dispatchedCommandLineSlaveRequest', 'TYPO3\\Flow\\Persistence\\PersistenceManagerInterface', 'persistAll'); $dispatcher->connect('TYPO3\\Flow\\Core\\Bootstrap', 'bootstrapShuttingDown', 'TYPO3\\Flow\\Configuration\\ConfigurationManager', 'shutdown'); $dispatcher->connect('TYPO3\\Flow\\Core\\Bootstrap', 'bootstrapShuttingDown', 'TYPO3\\Flow\\Object\\ObjectManagerInterface', 'shutdown'); $dispatcher->connect('TYPO3\\Flow\\Core\\Bootstrap', 'bootstrapShuttingDown', 'TYPO3\\Flow\\Reflection\\ReflectionService', 'saveToCache'); $dispatcher->connect('TYPO3\\Flow\\Command\\CoreCommandController', 'finishedCompilationRun', 'TYPO3\\Flow\\Security\\Policy\\PolicyService', 'savePolicyCache'); $dispatcher->connect('TYPO3\\Flow\\Command\\DoctrineCommandController', 'afterDatabaseMigration', 'TYPO3\\Flow\\Security\\Policy\\PolicyService', 'initializeRolesFromPolicy'); $dispatcher->connect('TYPO3\\Flow\\Security\\Authentication\\AuthenticationProviderManager', 'authenticatedToken', function () use($bootstrap) { $session = $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Session\\SessionInterface'); if ($session->isStarted()) { $session->renewId(); } }); $dispatcher->connect('TYPO3\\Flow\\Monitor\\FileMonitor', 'filesHaveChanged', 'TYPO3\\Flow\\Cache\\CacheManager', 'flushSystemCachesByChangedFiles'); $dispatcher->connect('TYPO3\\Flow\\Tests\\FunctionalTestCase', 'functionalTestTearDown', 'TYPO3\\Flow\\Mvc\\Routing\\RouterCachingService', 'flushCaches'); $dispatcher->connect('TYPO3\\Flow\\Configuration\\ConfigurationManager', 'configurationManagerReady', function (Configuration\ConfigurationManager $configurationManager) { $configurationManager->registerConfigurationType('Views', Configuration\ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_APPEND); }); $dispatcher->connect('TYPO3\\Flow\\Command\\CacheCommandController', 'warmupCaches', 'TYPO3\\Flow\\Configuration\\ConfigurationManager', 'warmup'); }
/** * {@inheritdoc} */ public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) { require_once FLOW_PATH_PACKAGES . '/Libraries/raven/raven/lib/Raven/Autoloader.php'; \Raven_Autoloader::register(); $bootstrap->getSignalSlotDispatcher()->connect('TYPO3\\Flow\\Core\\Booting\\Sequence', 'afterInvokeStep', function ($step, $runlevel) use($bootstrap) { if ($step->getIdentifier() === 'typo3.flow:objectmanagement:runtime') { // This triggers the initializeObject method $bootstrap->getObjectManager()->get('Networkteam\\SentryClient\\ErrorHandler'); } }); // Make Sentry DSN settable via Environment Variables. Only used in context Production/Heroku. if (getenv('ENV_SENTRY_DSN')) { define('ENV_SENTRY_DSN', getenv('ENV_SENTRY_DSN')); } }
/** * 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('TYPO3\\Flow\\Cache\\CacheManager')->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 \TYPO3\Flow\Monitor\ChangeDetectionStrategy\ModificationTimeStrategy(); $fileChangeDetector->injectCache($fileMonitorCache); $bootstrap->getObjectManager()->registerShutdownObject($fileChangeDetector, 'shutdownObject'); $fileMonitor = new FileMonitor($identifier); $fileMonitor->injectCache($fileMonitorCache); $fileMonitor->injectChangeDetectionStrategy($fileChangeDetector); $fileMonitor->injectSignalDispatcher($bootstrap->getEarlyInstance('TYPO3\\Flow\\SignalSlot\\Dispatcher')); $fileMonitor->injectSystemLogger($bootstrap->getEarlyInstance('TYPO3\\Flow\\Log\\SystemLoggerInterface')); $fileMonitor->initializeObject(); return $fileMonitor; }
/** * Tears down test requirements depending on the enabled tests * * Note: tearDown() is also called if an exception occurred in one of the tests. If the problem is caused by * some security or persistence related part of Flow, the error might be hard to track because their * specialized tearDown() methods might cause fatal errors. In those cases just output the original * exception message by adding an echo($this->statusMessage) as the first line of this method. * * @return void */ public function tearDown() { if ($this->testableSecurityEnabled === TRUE) { $this->tearDownSecurity(); } $persistenceManager = self::$bootstrap->getObjectManager()->get('TYPO3\\Flow\\Persistence\\PersistenceManagerInterface'); // Explicitly call persistAll() so that the "allObjectsPersisted" signal is sent even if persistAll() // has not been called during a test. This makes sure that for example certain repositories can clear // their internal registry in order to avoid side effects in the following test run. // Wrap in try/catch to suppress errors after the actual test is run (e.g. validation) try { $persistenceManager->persistAll(); } catch (\Exception $exception) { } if (is_callable(array($persistenceManager, 'tearDown'))) { $persistenceManager->tearDown(); } self::$bootstrap->getObjectManager()->forgetInstance('TYPO3\\Flow\\Http\\Client\\InternalRequestEngine'); $this->emitFunctionalTestTearDown(); }
/** * 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(); $requestHandler->setHttpRequest($httpRequest); $requestHandler->setHttpResponse($response); $objectManager = $this->bootstrap->getObjectManager(); $baseComponentChain = $objectManager->get('TYPO3\\Flow\\Http\\Component\\ComponentChain'); $componentContext = new ComponentContext($httpRequest, $response); $componentContext->setParameter('TYPO3\\Flow\\Mvc\\Routing\\RoutingComponent', 'skipRouterInitialization', TRUE); try { $baseComponentChain->handle($componentContext); } catch (\Exception $exception) { $pathPosition = strpos($exception->getFile(), 'Packages/'); $filePathAndName = $pathPosition !== FALSE ? substr($exception->getFile(), $pathPosition) : $exception->getFile(); $exceptionCodeNumber = $exception->getCode() > 0 ? '#' . $exception->getCode() . ': ' : ''; $content = PHP_EOL . 'Uncaught Exception in Flow ' . $exceptionCodeNumber . $exception->getMessage() . PHP_EOL; $content .= 'thrown in file ' . $filePathAndName . PHP_EOL; $content .= 'in line ' . $exception->getLine() . PHP_EOL . PHP_EOL; $content .= Debugger::getBacktraceCode($exception->getTrace(), FALSE, TRUE) . PHP_EOL; if ($exception instanceof Exception) { $statusCode = $exception->getStatusCode(); } else { $statusCode = 500; } $response->setStatus($statusCode); $response->setContent($content); $response->setHeader('X-Flow-ExceptionCode', $exception->getCode()); $response->setHeader('X-Flow-ExceptionMessage', $exception->getMessage()); } $session = $this->bootstrap->getObjectManager()->get('TYPO3\\Flow\\Session\\SessionInterface'); if ($session->isStarted()) { $session->close(); } return $response; }
/** * Invokes custom PHP code directly after the package manager has been initialized. * * @param \TYPO3\Flow\Core\Bootstrap $bootstrap The current bootstrap * @return void */ public function boot(\TYPO3\Flow\Core\Bootstrap $bootstrap) { $dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher->connect('TYPO3\\Flow\\Persistence\\Doctrine\\PersistenceManager', 'allObjectsPersisted', 'TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository', 'flushNodeRegistry'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository', 'repositoryObjectsPersisted', 'TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository', 'flushNodeRegistry'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodePathChanged', function () use($bootstrap) { $contextFactory = $bootstrap->getObjectManager()->get('TYPO3\\TYPO3CR\\Domain\\Service\\ContextFactoryInterface'); /** @var Context $contextInstance */ foreach ($contextFactory->getInstances() as $contextInstance) { $contextInstance->getFirstLevelNodeCache()->flush(); } }); $dispatcher->connect('TYPO3\\Flow\\Configuration\\ConfigurationManager', 'configurationManagerReady', function (ConfigurationManager $configurationManager) { $configurationManager->registerConfigurationType('NodeTypes', ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_DEFAULT, true); }); $context = $bootstrap->getContext(); if (!$context->isProduction()) { $dispatcher->connect('TYPO3\\Flow\\Core\\Booting\\Sequence', 'afterInvokeStep', function ($step) use($bootstrap) { if ($step->getIdentifier() === 'typo3.flow:systemfilemonitor') { $nodeTypeConfigurationFileMonitor = \TYPO3\Flow\Monitor\FileMonitor::createFileMonitorAtBoot('TYPO3CR_NodeTypesConfiguration', $bootstrap); $packageManager = $bootstrap->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManagerInterface'); 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(); } }); } }
/** * 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('typo3.flow:core:*'); $bootstrap->registerCompiletimeCommand('typo3.flow:cache:flush'); $dispatcher = $bootstrap->getSignalSlotDispatcher(); $dispatcher->connect(\TYPO3\Flow\Mvc\Dispatcher::class, 'afterControllerInvocation', function ($request) use($bootstrap) { if ($bootstrap->getObjectManager()->hasInstance(\TYPO3\Flow\Persistence\PersistenceManagerInterface::class)) { if (!$request instanceof Mvc\ActionRequest || $request->getHttpRequest()->isMethodSafe() !== true) { $bootstrap->getObjectManager()->get(\TYPO3\Flow\Persistence\PersistenceManagerInterface::class)->persistAll(); } elseif ($request->getHttpRequest()->isMethodSafe()) { $bootstrap->getObjectManager()->get(\TYPO3\Flow\Persistence\PersistenceManagerInterface::class)->persistAll(true); } } }); $dispatcher->connect(\TYPO3\Flow\Cli\SlaveRequestHandler::class, 'dispatchedCommandLineSlaveRequest', \TYPO3\Flow\Persistence\PersistenceManagerInterface::class, 'persistAll'); $context = $bootstrap->getContext(); if (!$context->isProduction()) { $dispatcher->connect(\TYPO3\Flow\Core\Booting\Sequence::class, 'afterInvokeStep', function ($step) use($bootstrap, $dispatcher) { if ($step->getIdentifier() === 'typo3.flow:resources') { $publicResourcesFileMonitor = \TYPO3\Flow\Monitor\FileMonitor::createFileMonitorAtBoot('Flow_PublicResourcesFiles', $bootstrap); $packageManager = $bootstrap->getEarlyInstance(\TYPO3\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(\TYPO3\Flow\Resource\ResourceManager::class); $resourceManager->getCollection(ResourceManager::DEFAULT_STATIC_COLLECTION_NAME)->publish(); }; $dispatcher->connect(\TYPO3\Flow\Monitor\FileMonitor::class, 'filesHaveChanged', $publishResources); $dispatcher->connect(\TYPO3\Flow\Core\Bootstrap::class, 'bootstrapShuttingDown', \TYPO3\Flow\Configuration\ConfigurationManager::class, 'shutdown'); $dispatcher->connect(\TYPO3\Flow\Core\Bootstrap::class, 'bootstrapShuttingDown', \TYPO3\Flow\Object\ObjectManagerInterface::class, 'shutdown'); $dispatcher->connect(\TYPO3\Flow\Core\Bootstrap::class, 'bootstrapShuttingDown', \TYPO3\Flow\Reflection\ReflectionService::class, 'saveToCache'); $dispatcher->connect(\TYPO3\Flow\Command\CoreCommandController::class, 'finishedCompilationRun', \TYPO3\Flow\Security\Authorization\Privilege\Method\MethodPrivilegePointcutFilter::class, 'savePolicyCache'); $dispatcher->connect(\TYPO3\Flow\Command\CoreCommandController::class, 'finishedCompilationRun', \TYPO3\Flow\Aop\Pointcut\RuntimeExpressionEvaluator::class, 'saveRuntimeExpressions'); $dispatcher->connect(\TYPO3\Flow\Security\Authentication\AuthenticationProviderManager::class, 'authenticatedToken', function () use($bootstrap) { $session = $bootstrap->getObjectManager()->get(\TYPO3\Flow\Session\SessionInterface::class); if ($session->isStarted()) { $session->renewId(); } }); $dispatcher->connect(\TYPO3\Flow\Monitor\FileMonitor::class, 'filesHaveChanged', \TYPO3\Flow\Cache\CacheManager::class, 'flushSystemCachesByChangedFiles'); $dispatcher->connect(\TYPO3\Flow\Tests\FunctionalTestCase::class, 'functionalTestTearDown', \TYPO3\Flow\Mvc\Routing\RouterCachingService::class, 'flushCaches'); $dispatcher->connect(\TYPO3\Flow\Configuration\ConfigurationManager::class, 'configurationManagerReady', function (Configuration\ConfigurationManager $configurationManager) { $configurationManager->registerConfigurationType('Views', Configuration\ConfigurationManager::CONFIGURATION_PROCESSING_TYPE_APPEND); }); $dispatcher->connect(\TYPO3\Flow\Command\CacheCommandController::class, 'warmupCaches', \TYPO3\Flow\Configuration\ConfigurationManager::class, 'warmup'); $dispatcher->connect(\TYPO3\Fluid\Core\Parser\TemplateParser::class, 'initializeNamespaces', function (TemplateParser $templateParser) use($bootstrap) { /** @var PackageManagerInterface $packageManager */ $packageManager = $bootstrap->getEarlyInstance(\TYPO3\Flow\Package\PackageManagerInterface::class); /** @var PackageInterface $package */ foreach ($packageManager->getActivePackages() as $package) { $templateParser->registerNamespace(strtolower($package->getPackageKey()), $package->getNamespace() . '\\ViewHelpers'); } }); $dispatcher->connect(\TYPO3\Flow\Package\PackageManager::class, 'packageStatesUpdated', function () use($dispatcher) { $dispatcher->connect(\TYPO3\Flow\Core\Bootstrap::class, 'bootstrapShuttingDown', \TYPO3\Flow\Cache\CacheManager::class, 'flushCaches'); }); }
/** * @param Bootstrap $bootstrap The current bootstrap * @return void */ public function boot(Bootstrap $bootstrap) { $dispatcher = $bootstrap->getSignalSlotDispatcher(); $flushConfigurationCache = function () use($bootstrap) { $cacheManager = $bootstrap->getEarlyInstance('TYPO3\\Flow\\Cache\\CacheManager'); $cacheManager->getCache('TYPO3_Neos_Configuration_Version')->flush(); }; $flushXliffServiceCache = function () use($bootstrap) { $cacheManager = $bootstrap->getEarlyInstance('TYPO3\\Flow\\Cache\\CacheManager'); $cacheManager->getCache('TYPO3_Neos_XliffToJsonTranslations')->flush(); }; $dispatcher->connect('TYPO3\\Flow\\Monitor\\FileMonitor', '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('TYPO3\\Neos\\Domain\\Model\\Site', 'siteChanged', $flushConfigurationCache); $dispatcher->connect('TYPO3\\Neos\\Domain\\Model\\Site', 'siteChanged', 'TYPO3\\Flow\\Mvc\\Routing\\RouterCachingService', 'flushCaches'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeUpdated', 'TYPO3\\Neos\\TypoScript\\Cache\\ContentCacheFlusher', 'registerNodeChange'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeAdded', 'TYPO3\\Neos\\TypoScript\\Cache\\ContentCacheFlusher', 'registerNodeChange'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeRemoved', 'TYPO3\\Neos\\TypoScript\\Cache\\ContentCacheFlusher', 'registerNodeChange'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'beforeNodeMove', 'TYPO3\\Neos\\TypoScript\\Cache\\ContentCacheFlusher', 'registerNodeChange'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeAdded', NodeUriPathSegmentGenerator::class, '::setUniqueUriPathSegment'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodePropertyChanged', Service\ImageVariantGarbageCollector::class, 'removeUnusedImageVariant'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodePropertyChanged', function (NodeInterface $node, $propertyName) use($bootstrap) { if ($propertyName === 'uriPathSegment') { NodeUriPathSegmentGenerator::setUniqueUriPathSegment($node); $bootstrap->getObjectManager()->get('TYPO3\\Neos\\Routing\\Cache\\RouteCacheFlusher')->registerNodeChange($node); } }); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodePathChanged', function (NodeInterface $node, $oldPath, $newPath, $recursion) { if (!$recursion) { NodeUriPathSegmentGenerator::setUniqueUriPathSegment($node); } }); $dispatcher->connect('TYPO3\\Neos\\Service\\PublishingService', 'nodePublished', 'TYPO3\\Neos\\TypoScript\\Cache\\ContentCacheFlusher', 'registerNodeChange'); $dispatcher->connect('TYPO3\\Neos\\Service\\PublishingService', 'nodeDiscarded', 'TYPO3\\Neos\\TypoScript\\Cache\\ContentCacheFlusher', 'registerNodeChange'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodePathChanged', 'TYPO3\\Neos\\Routing\\Cache\\RouteCacheFlusher', 'registerNodePathChange'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeRemoved', 'TYPO3\\Neos\\Routing\\Cache\\RouteCacheFlusher', 'registerNodeChange'); $dispatcher->connect('TYPO3\\Neos\\Service\\PublishingService', 'nodePublished', 'TYPO3\\Neos\\Routing\\Cache\\RouteCacheFlusher', 'registerNodeChange'); $dispatcher->connect('TYPO3\\Neos\\Service\\PublishingService', '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('TYPO3\\Flow\\Persistence\\Doctrine\\PersistenceManager', 'allObjectsPersisted', 'TYPO3\\Neos\\Routing\\Cache\\RouteCacheFlusher', 'commit'); $dispatcher->connect('TYPO3\\Neos\\Domain\\Service\\SiteService', 'sitePruned', 'TYPO3\\TypoScript\\Core\\Cache\\ContentCache', 'flush'); $dispatcher->connect('TYPO3\\Neos\\Domain\\Service\\SiteService', 'sitePruned', 'TYPO3\\Flow\\Mvc\\Routing\\RouterCachingService', 'flushCaches'); $dispatcher->connect('TYPO3\\Neos\\Domain\\Service\\SiteImportService', 'siteImported', 'TYPO3\\TypoScript\\Core\\Cache\\ContentCache', 'flush'); $dispatcher->connect('TYPO3\\Neos\\Domain\\Service\\SiteImportService', 'siteImported', 'TYPO3\\Flow\\Mvc\\Routing\\RouterCachingService', 'flushCaches'); // Eventlog $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'beforeNodeCreate', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'beforeNodeCreate'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'afterNodeCreate', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'afterNodeCreate'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeUpdated', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'nodeUpdated'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodeRemoved', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'nodeRemoved'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'beforeNodePropertyChange', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'beforeNodePropertyChange'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'nodePropertyChanged', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'nodePropertyChanged'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'beforeNodeCopy', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'beforeNodeCopy'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'afterNodeCopy', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'afterNodeCopy'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'beforeNodeMove', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'beforeNodeMove'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Node', 'afterNodeMove', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'afterNodeMove'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Service\\Context', 'beforeAdoptNode', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'beforeAdoptNode'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Service\\Context', 'afterAdoptNode', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'afterAdoptNode'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Workspace', 'beforeNodePublishing', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'beforeNodePublishing'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Model\\Workspace', 'afterNodePublishing', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'afterNodePublishing'); $dispatcher->connect('TYPO3\\Flow\\Persistence\\Doctrine\\PersistenceManager', 'allObjectsPersisted', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'updateEventsAfterPublish'); $dispatcher->connect('TYPO3\\TYPO3CR\\Domain\\Repository\\NodeDataRepository', 'repositoryObjectsPersisted', 'TYPO3\\Neos\\EventLog\\Integrations\\TYPO3CRIntegrationService', 'updateEventsAfterPublish'); }
/** * Initialize the resource management component, setting up stream wrappers, * publishing the public resources of all found packages, ... * * @param Bootstrap $bootstrap * @return void */ public static function initializeResources(Bootstrap $bootstrap) { $packageManager = $bootstrap->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManagerInterface'); $resourceManager = $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Resource\\ResourceManager'); $resourceManager->initialize(); $resourceManager->publishPublicPackageResources($packageManager->getActivePackages()); }
/** * Initialize the resource management component, setting up stream wrappers, * publishing the public resources of all found packages, ... * * @param Bootstrap $bootstrap * @return void */ public static function initializeResources(Bootstrap $bootstrap) { $resourceManager = $bootstrap->getObjectManager()->get('TYPO3\\Flow\\Resource\\ResourceManager'); $resourceManager->initialize(); }
/** * Initialize the stream wrappers. * * @param Bootstrap $bootstrap * @return void */ public static function initializeResources(Bootstrap $bootstrap) { StreamWrapperAdapter::initializeStreamWrapper($bootstrap->getObjectManager()); }