Пример #1
0
 /**
  * Exports the internal reflection data into the ReflectionData cache
  *
  * This method is triggered by a signal which is connected to the bootstrap's
  * shutdown sequence.
  *
  * If the reflection data has previously been loaded from the runtime cache,
  * saving it is omitted as changes are not expected.
  *
  * In Production context the whole cache is written at once and then frozen in
  * order to be consistent. Frozen cache data in Development is only produced for
  * classes contained in frozen packages.
  *
  * @return void
  * @throws \TYPO3\Flow\Reflection\Exception if no cache has been injected
  */
 public function saveToCache()
 {
     if (!$this->initialized) {
         $this->initialize();
     }
     if ($this->loadFromClassSchemaRuntimeCache === TRUE) {
         return;
     }
     if (!$this->reflectionDataCompiletimeCache instanceof FrontendInterface) {
         throw new Exception('A cache must be injected before initializing the Reflection Service.', 1232044697);
     }
     if (count($this->updatedReflectionData) > 0) {
         $this->log(sprintf('Found %s classes whose reflection data was not cached previously.', count($this->updatedReflectionData)), LOG_DEBUG);
         foreach (array_keys($this->updatedReflectionData) as $className) {
             $this->statusCache->set(str_replace('\\', '_', $className), '');
         }
         $data = array();
         $propertyNames = array('classReflectionData', 'classSchemata', 'annotatedClasses', 'classesByMethodAnnotations');
         foreach ($propertyNames as $propertyName) {
             $data[$propertyName] = $this->{$propertyName};
         }
         $this->reflectionDataCompiletimeCache->set('ReflectionData', $data);
     }
     if ($this->context->isProduction()) {
         $this->reflectionDataRuntimeCache->flush();
         $classNames = array();
         foreach ($this->classReflectionData as $className => $reflectionData) {
             $classNames[$className] = TRUE;
             $this->reflectionDataRuntimeCache->set(str_replace('\\', '_', $className), $reflectionData);
             if (isset($this->classSchemata[$className])) {
                 $this->classSchemataRuntimeCache->set(str_replace('\\', '_', $className), $this->classSchemata[$className]);
             }
         }
         $this->reflectionDataRuntimeCache->set('__classNames', $classNames);
         $this->reflectionDataRuntimeCache->set('__annotatedClasses', $this->annotatedClasses);
         $this->reflectionDataRuntimeCache->getBackend()->freeze();
         $this->classSchemataRuntimeCache->getBackend()->freeze();
         $this->log(sprintf('Built and froze reflection runtime caches (%s classes).', count($this->classReflectionData)), LOG_INFO);
     } elseif ($this->context->isDevelopment()) {
         foreach (array_keys($this->packageManager->getFrozenPackages()) as $packageKey) {
             $pathAndFilename = $this->getPrecompiledReflectionStoragePath() . $packageKey . '.dat';
             if (!file_exists($pathAndFilename)) {
                 $this->log(sprintf('Rebuilding precompiled reflection data for frozen package %s.', $packageKey), LOG_INFO);
                 $this->freezePackageReflection($packageKey);
             }
         }
     }
 }
 /**
  * Save reflection data to cache in Production context.
  */
 protected function saveProductionData()
 {
     $this->reflectionDataRuntimeCache->flush();
     $classNames = [];
     foreach ($this->classReflectionData as $className => $reflectionData) {
         $classNames[$className] = true;
         $cacheIdentifier = $this->produceCacheIdentifierFromClassName($className);
         $this->reflectionDataRuntimeCache->set($cacheIdentifier, $reflectionData);
         if (isset($this->classSchemata[$className])) {
             $this->classSchemataRuntimeCache->set($cacheIdentifier, $this->classSchemata[$className]);
         }
     }
     $this->reflectionDataRuntimeCache->set('__classNames', $classNames);
     $this->reflectionDataRuntimeCache->set('__annotatedClasses', $this->annotatedClasses);
     $this->reflectionDataRuntimeCache->getBackend()->freeze();
     $this->classSchemataRuntimeCache->getBackend()->freeze();
     $this->log(sprintf('Built and froze reflection runtime caches (%s classes).', count($this->classReflectionData)), LOG_INFO);
 }
 /**
  * Flushes 'route' and 'resolve' caches.
  *
  * @return void
  */
 public function flushCaches()
 {
     $this->routeCache->flush();
     $this->resolveCache->flush();
 }
 /**
  * Flushes 'findMatchResults' and 'resolve' caches.
  *
  * @return void
  */
 public function flushCaches()
 {
     $this->findMatchResultsCache->flush();
     $this->resolveCache->flush();
 }
 /**
  * Reset processed node cache
  */
 public function flushCacheCommand()
 {
     $this->cache->flush();
     $this->downloadCache->flush();
 }
Пример #6
0
 /**
  * Creates a cache for testing
  *
  * @param string $name
  * @return VariableFrontend
  */
 protected function createCache($name)
 {
     $mockEnvironment = $this->getMock('TYPO3\\Flow\\Utility\\Environment', array(), array(), '', FALSE);
     $mockEnvironment->expects($this->any())->method('getMaximumPathLength')->will($this->returnValue(255));
     $mockEnvironment->expects($this->any())->method('getPathToTemporaryDirectory')->will($this->returnValue('vfs://Foo/'));
     $backend = new FileBackend(new ApplicationContext('Testing'));
     $backend->injectEnvironment($mockEnvironment);
     $cache = new VariableFrontend($name, $backend);
     $cache->flush();
     return $cache;
 }
 /**
  * Creates a cache for testing
  *
  * @param string $name
  * @return VariableFrontend
  */
 protected function createCache($name)
 {
     $mockEnvironment = $this->getMock(\TYPO3\Flow\Utility\Environment::class, array(), array(), '', FALSE);
     $mockEnvironment->expects($this->any())->method('getMaximumPathLength')->will($this->returnValue(255));
     $mockEnvironment->expects($this->any())->method('getPathToTemporaryDirectory')->will($this->returnValue('vfs://Foo/'));
     $mockCacheManager = $this->getMock(\TYPO3\Flow\Cache\CacheManager::class, array(), array(), '', FALSE);
     $mockCacheManager->expects($this->any())->method('isCachePersistent')->will($this->returnValue(FALSE));
     $backend = new FileBackend(new ApplicationContext('Testing'));
     $backend->injectCacheManager($mockCacheManager);
     $backend->injectEnvironment($mockEnvironment);
     $cache = new VariableFrontend($name, $backend);
     $cache->initializeObject();
     $cache->flush();
     return $cache;
 }