/**
  * 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('TYPO3\\Flow\\Core\\Booting\\Sequence', 'afterInvokeStep', function ($step) use($bootstrap, $dispatcher) {
             if ($step->getIdentifier() === 'typo3.flow:systemfilemonitor') {
                 $typoScriptFileMonitor = \TYPO3\Flow\Monitor\FileMonitor::createFileMonitorAtBoot('TypoScript_Files', $bootstrap);
                 $packageManager = $bootstrap->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManagerInterface');
                 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('TYPO3\\Flow\\Cache\\CacheManager');
                 $listener = new \TYPO3\TypoScript\Core\Cache\FileMonitorListener($cacheManager);
                 $dispatcher->connect('TYPO3\\Flow\\Monitor\\FileMonitor', 'filesHaveChanged', $listener, 'flushContentCacheOnFileChanges');
             }
         });
     }
 }
 /**
  * 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;
 }
 /**
  * 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('TYPO3\\Flow\\Core\\Booting\\Sequence', 'afterInvokeStep', function ($step) use($bootstrap, $dispatcher) {
             if ($step->getIdentifier() === 'typo3.flow:systemfilemonitor') {
                 $templateFileMonitor = \TYPO3\Flow\Monitor\FileMonitor::createFileMonitorAtBoot('Fluid_TemplateFiles', $bootstrap);
                 $packageManager = $bootstrap->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManagerInterface');
                 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 !== 'Flow_ClassFiles') {
             return;
         }
         $objectManager = $bootstrap->getObjectManager();
         if ($objectManager->isRegistered('TYPO3\\Fluid\\Core\\Compiler\\TemplateCompiler')) {
             $templateCompiler = $objectManager->get('TYPO3\\Fluid\\Core\\Compiler\\TemplateCompiler');
             $templateCompiler->flushTemplatesOnViewHelperChanges($changedFiles);
         }
     };
     $dispatcher->connect('TYPO3\\Flow\\Monitor\\FileMonitor', 'filesHaveChanged', $flushTemplates);
 }
 /**
  * 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');
     });
 }
 /**
  * Let the given file monitor track changes of the specified directory if it exists.
  *
  * @param FileMonitor $fileMonitor
  * @param string $path
  * @return void
  */
 protected static function monitorDirectoryIfItExists(FileMonitor $fileMonitor, $path)
 {
     if (is_dir($path)) {
         $fileMonitor->monitorDirectory($path);
     }
 }
 /**
  * Let the given file monitor track changes of the specified directory if it exists.
  *
  * @param FileMonitor $fileMonitor
  * @param string $path
  * @param string $filenamePattern Optional pattern for filenames to consider for file monitoring (regular expression). @see FileMonitor::monitorDirectory()
  * @return void
  */
 protected static function monitorDirectoryIfItExists(FileMonitor $fileMonitor, $path, $filenamePattern = null)
 {
     if (is_dir($path)) {
         $fileMonitor->monitorDirectory($path, $filenamePattern);
     }
 }
 /**
  * Caches the file modification times
  *
  * @return void
  */
 public function shutdownObject()
 {
     if ($this->modificationTimesChanged === true) {
         $this->cache->set($this->fileMonitor->getIdentifier() . '_filesAndModificationTimes', json_encode($this->filesAndModificationTimes));
     }
 }