Neos\Flow\Monitor\FileMonitor::createFileMonitorAtBoot PHP Метод

createFileMonitorAtBoot() публичный статический Метод

Helper method to create a FileMonitor instance during boot sequence as injections have to be done manually.
public static createFileMonitorAtBoot ( string $identifier, Bootstrap $bootstrap ) : FileMonitor
$identifier string
$bootstrap Neos\Flow\Core\Bootstrap
Результат 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;
    }

Usage Example

Пример #1
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() === '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');
             }
         });
     }
 }
All Usage Examples Of Neos\Flow\Monitor\FileMonitor::createFileMonitorAtBoot