Returns the context this bootstrap was started in.
public getContext ( ) : |
||
return | The context encapsulated in an object, for example "Development" or "Development/MyDeployment" |
/** * 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(); $context = $bootstrap->getContext(); if (!$context->isProduction()) { $dispatcher->connect(Sequence::class, 'afterInvokeStep', function ($step) use($bootstrap, $dispatcher) { if ($step->getIdentifier() === 'typo3.flow:systemfilemonitor') { $typoScriptFileMonitor = FileMonitor::createFileMonitorAtBoot('TypoScript_Files', $bootstrap); $packageManager = $bootstrap->getEarlyInstance(PackageManagerInterface::class); foreach ($packageManager->getActivePackages() as $packageKey => $package) { if ($packageManager->isPackageFrozen($packageKey)) { continue; } $typoScriptPaths = array($package->getResourcesPath() . 'Private/TypoScript', $package->getResourcesPath() . 'Private/TypoScripts'); foreach ($typoScriptPaths as $typoScriptPath) { if (is_dir($typoScriptPath)) { $typoScriptFileMonitor->monitorDirectory($typoScriptPath); } } } $typoScriptFileMonitor->detectChanges(); $typoScriptFileMonitor->shutdownObject(); } if ($step->getIdentifier() === 'typo3.flow:cachemanagement') { $cacheManager = $bootstrap->getEarlyInstance(CacheManager::class); $listener = new FileMonitorListener($cacheManager); $dispatcher->connect(FileMonitor::class, 'filesHaveChanged', $listener, 'flushContentCacheOnFileChanges'); } }); } }
/** * Tells if a package is frozen * * @param string $packageKey The package to check * @return boolean */ public function isPackageFrozen($packageKey) { if (!isset($this->packages[$packageKey])) { return false; } $composerName = $this->packages[$packageKey]->getComposerName(); return $this->bootstrap->getContext()->isDevelopment() && isset($this->packageStatesConfiguration['packages'][$composerName]['frozen']) && $this->packageStatesConfiguration['packages'][$composerName]['frozen'] === true; }
/** * @return void */ protected function displayHelpIndex() { $context = $this->bootstrap->getContext(); $applicationPackage = $this->packageManager->getPackage($this->applicationPackageKey); $this->outputLine('<b>%s %s ("%s" context)</b>', [$applicationPackage->getComposerManifest('description'), $applicationPackage->getInstalledVersion() ?: 'dev', $context]); $this->outputLine('<i>usage: %s <command identifier></i>', [$this->getFlowInvocationString()]); $this->outputLine(); $this->outputLine('The following commands are currently available:'); $this->displayShortHelpForCommands($this->commandManager->getAvailableCommands()); $this->outputLine('* = compile time command'); $this->outputLine(); $this->outputLine('See "%s help <commandidentifier>" for more information about a specific command.', [$this->getFlowInvocationString()]); $this->outputLine(); }
/** * Launch sub process * * @return array The new sub process and its STDIN, STDOUT, STDERR pipes – or FALSE if an error occurred. * @throws \RuntimeException */ protected function launchSubProcess() { $systemCommand = 'FLOW_ROOTPATH=' . FLOW_PATH_ROOT . ' FLOW_PATH_TEMPORARY_BASE=' . FLOW_PATH_TEMPORARY_BASE . ' ' . 'FLOW_CONTEXT=' . $this->bootstrap->getContext() . ' ' . PHP_BINDIR . '/php -c ' . php_ini_loaded_file() . ' ' . FLOW_PATH_FLOW . 'Scripts/flow.php' . ' --start-slave'; $descriptorSpecification = [['pipe', 'r'], ['pipe', 'w'], ['pipe', 'a']]; $subProcess = proc_open($systemCommand, $descriptorSpecification, $pipes); if (!is_resource($subProcess)) { throw new \RuntimeException('Could not execute sub process.'); } $read = [$pipes[1]]; $write = null; $except = null; $readTimeout = 30; stream_select($read, $write, $except, $readTimeout); $subProcessStatus = proc_get_status($subProcess); return $subProcessStatus['running'] === true ? [$subProcess, $pipes] : false; }
/** * @return string */ public function render() { $configuration = array('window.T3Configuration = {};', 'window.T3Configuration.UserInterface = ' . json_encode($this->settings['userInterface']) . ';', 'window.T3Configuration.nodeTypes = {};', 'window.T3Configuration.nodeTypes.groups = ' . json_encode($this->getNodeTypeGroupsSettings()) . ';', 'window.T3Configuration.requirejs = {};', 'window.T3Configuration.neosStaticResourcesBaseUri = ' . json_encode($this->resourceManager->getPublicPackageResourceUri('Neos.Neos', '')) . ';', 'window.T3Configuration.requirejs.paths = ' . json_encode($this->getRequireJsPathMapping()) . ';', 'window.T3Configuration.maximumFileUploadSize = ' . $this->renderMaximumFileUploadSize()); $neosJavaScriptBasePath = $this->getStaticResourceWebBaseUri('resource://Neos.Neos/Public/JavaScript'); $configuration[] = 'window.T3Configuration.neosJavascriptBasePath = ' . json_encode($neosJavaScriptBasePath) . ';'; if ($this->backendAssetsUtility->shouldLoadMinifiedJavascript()) { $configuration[] = 'window.T3Configuration.neosJavascriptVersion = ' . json_encode($this->backendAssetsUtility->getJavascriptBuiltVersion()) . ';'; } if ($this->bootstrap->getContext()->isDevelopment()) { $configuration[] = 'window.T3Configuration.DevelopmentMode = true;'; } if ($activeDomain = $this->domainRepository->findOneByActiveRequest()) { $configuration[] = 'window.T3Configuration.site = "' . $activeDomain->getSite()->getNodeName() . '";'; } return implode("\n", $configuration); }
/** * Refreeze a package * * Refreezes a currently frozen package: all precompiled information is removed * and file monitoring will consider the package exactly once, on the next * request. After that request, the package remains frozen again, just with the * updated data. * * By specifying <b>all</b> as a package key, all currently frozen packages are * refrozen (the default). * * @param string $packageKey Key of the package to refreeze, or 'all' * @return void * @see neos.flow:package:freeze * @see neos.flow:cache:flush */ public function refreezeCommand($packageKey = 'all') { if (!$this->bootstrap->getContext()->isDevelopment()) { $this->outputLine('Package freezing is only supported in Development context.'); $this->quit(3); } $packagesToRefreeze = []; if ($packageKey === 'all') { foreach (array_keys($this->packageManager->getAvailablePackages()) as $packageKey) { if ($this->packageManager->isPackageFrozen($packageKey)) { $packagesToRefreeze[] = $packageKey; } } if ($packagesToRefreeze === []) { $this->outputLine('Nothing to do, no packages were frozen.'); $this->quit(0); } } else { if ($packageKey === null) { $this->outputLine('You must specify a package to refreeze.'); $this->quit(1); } if (!$this->packageManager->isPackageAvailable($packageKey)) { $this->outputLine('Package "%s" is not available.', [$packageKey]); $this->quit(2); } if (!$this->packageManager->isPackageFrozen($packageKey)) { $this->outputLine('Package "%s" was not frozen.', [$packageKey]); $this->quit(0); } $packagesToRefreeze = [$packageKey]; } foreach ($packagesToRefreeze as $packageKey) { $this->packageManager->refreezePackage($packageKey); $this->outputLine('Refroze package "%s".', [$packageKey]); } Scripts::executeCommand('neos.flow:cache:flush', $this->settings, false); $this->sendAndExit(0); }
/** * Flushes a particular cache by its identifier * * Given a cache identifier, this flushes just that one cache. To find * the cache identifiers, you can use the configuration:show command with * the type set to "Caches". * * Note that this does not have a force-flush option since it's not * meant to remove temporary code data, resulting into a broken state if * code files lack. * * @param string $identifier Cache identifier to flush cache for * @return void * @see neos.flow:cache:flush * @see neos.flow:configuration:show */ public function flushOneCommand($identifier) { if (!$this->cacheManager->hasCache($identifier)) { $this->outputLine('The cache "%s" does not exist.', [$identifier]); $cacheConfigurations = $this->cacheManager->getCacheConfigurations(); $shortestDistance = -1; foreach (array_keys($cacheConfigurations) as $existingIdentifier) { $distance = levenshtein($existingIdentifier, $identifier); if ($distance <= $shortestDistance || $shortestDistance < 0) { $shortestDistance = $distance; $closestIdentifier = $existingIdentifier; } } if (isset($closestIdentifier)) { $this->outputLine('Did you mean "%s"?', [$closestIdentifier]); } $this->quit(1); } $this->cacheManager->getCache($identifier)->flush(); $this->outputLine('Flushed "%s" cache for "%s" context.', [$identifier, $this->bootstrap->getContext()]); $this->sendAndExit(0); }
/** * 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(); $context = $bootstrap->getContext(); if (!$context->isProduction()) { $dispatcher->connect(Sequence::class, 'afterInvokeStep', function ($step) use($bootstrap, $dispatcher) { if ($step->getIdentifier() === 'neos.flow:systemfilemonitor') { $templateFileMonitor = FileMonitor::createFileMonitorAtBoot('Fluid_TemplateFiles', $bootstrap); $packageManager = $bootstrap->getEarlyInstance(PackageManagerInterface::class); foreach ($packageManager->getActivePackages() as $packageKey => $package) { if ($packageManager->isPackageFrozen($packageKey)) { continue; } foreach (array('Templates', 'Partials', 'Layouts') as $path) { $templatesPath = $package->getResourcesPath() . 'Private/' . $path; if (is_dir($templatesPath)) { $templateFileMonitor->monitorDirectory($templatesPath); } } } $templateFileMonitor->detectChanges(); $templateFileMonitor->shutdownObject(); } }); } // Use a closure to invoke the TemplateCompiler, since the object is not registered during compiletime $flushTemplates = function ($identifier, $changedFiles) use($bootstrap) { if ($identifier !== 'Fluid_TemplateFiles') { return; } if ($changedFiles === []) { return; } $templateCache = $bootstrap->getObjectManager()->get(CacheManager::class)->getCache('Fluid_TemplateCache'); $templateCache->flush(); }; $dispatcher->connect(FileMonitor::class, 'filesHaveChanged', $flushTemplates); }
/** * 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(); } }); } }
/** * 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); }
/** * 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'); }); }
/** * This request handler can handle requests in Testing Context. * * @return boolean If the context is Testing, TRUE otherwise FALSE */ public function canHandleRequest() { return $this->bootstrap->getContext()->isTesting(); }