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);
}