/**
  * This method walks through the view configuration and applies
  * matching configurations in the order of their specifity score.
  * Possible options are currently the viewObjectName to specify
  * a different class that will be used to create the view and
  * an array of options that will be set on the view object.
  *
  * @param ActionRequest $request
  * @return array
  */
 public function getViewConfiguration(ActionRequest $request)
 {
     $cacheIdentifier = $this->createCacheIdentifier($request);
     $viewConfiguration = $this->cache->get($cacheIdentifier);
     if ($viewConfiguration === false) {
         $configurations = $this->configurationManager->getConfiguration('Views');
         $requestMatcher = new RequestMatcher($request);
         $context = new Context($requestMatcher);
         $viewConfiguration = [];
         $highestWeight = -1;
         foreach ($configurations as $order => $configuration) {
             $requestMatcher->resetWeight();
             if (!isset($configuration['requestFilter'])) {
                 $weight = $order;
             } else {
                 $result = $this->eelEvaluator->evaluate($configuration['requestFilter'], $context);
                 if ($result === false) {
                     continue;
                 }
                 $weight = $requestMatcher->getWeight() + $order;
             }
             if ($weight > $highestWeight) {
                 $viewConfiguration = $configuration;
                 $highestWeight = $weight;
             }
         }
         $this->cache->set($cacheIdentifier, $viewConfiguration);
     }
     return $viewConfiguration;
 }
 /**
  * Lifecycle method, called after all dependencies have been injected.
  * Here, the typeConverter array gets initialized.
  *
  * @return void
  */
 public function initializeObject()
 {
     if ($this->cache->has('typeConverterMap')) {
         $this->typeConverters = $this->cache->get('typeConverterMap');
         return;
     }
     $this->typeConverters = $this->prepareTypeConverterMap();
     $this->cache->set('typeConverterMap', $this->typeConverters);
 }
Exemplo n.º 3
0
 /**
  * Initializes the locale service
  *
  * @return void
  */
 public function initializeObject()
 {
     $this->configuration = new Configuration($this->settings['defaultLocale']);
     $this->configuration->setFallbackRule($this->settings['fallbackRule']);
     if ($this->cache->has('availableLocales')) {
         $this->localeCollection = $this->cache->get('availableLocales');
     } else {
         $this->generateAvailableLocalesCollectionByScanningFilesystem();
         $this->cache->set('availableLocales', $this->localeCollection);
     }
 }
 /**
  * @Flow\Around("setting(Neos.Neos.typoScript.enableObjectTreeCache) && method(Neos\Neos\Domain\Service\TypoScriptService->getMergedTypoScriptObjectTree())")
  * @param JoinPointInterface $joinPoint The current join point
  * @return mixed
  */
 public function cacheGetMergedTypoScriptObjectTree(JoinPointInterface $joinPoint)
 {
     $currentSiteNode = $joinPoint->getMethodArgument('startNode');
     $cacheIdentifier = str_replace('.', '_', $currentSiteNode->getContext()->getCurrentSite()->getSiteResourcesPackageKey());
     if ($this->typoScriptCache->has($cacheIdentifier)) {
         $typoScriptObjectTree = $this->typoScriptCache->get($cacheIdentifier);
     } else {
         $typoScriptObjectTree = $joinPoint->getAdviceChain()->proceed($joinPoint);
         $this->typoScriptCache->set($cacheIdentifier, $typoScriptObjectTree);
     }
     return $typoScriptObjectTree;
 }
 /**
  * Save the found matches to the cache.
  *
  * @return void
  */
 public function savePolicyCache()
 {
     $tags = ['TYPO3_Flow_Aop'];
     if (!$this->methodPermissionCache->has('methodPermission')) {
         $this->methodPermissionCache->set('methodPermission', $this->methodPermissions, $tags);
     }
 }
 /**
  * @return integer The current cache version identifier
  */
 public function getCacheVersion()
 {
     $version = $this->xliffToJsonTranslationsCache->get('ConfigurationVersion');
     if ($version === false) {
         $version = time();
         $this->xliffToJsonTranslationsCache->set('ConfigurationVersion', (string) $version);
     }
     return $version;
 }
 /**
  * Returns all sessions which are tagged by the specified tag.
  *
  * @param string $tag A valid Cache Frontend tag
  * @return array A collection of Session objects or an empty array if tag did not match
  * @api
  */
 public function getSessionsByTag($tag)
 {
     $taggedSessions = [];
     foreach ($this->metaDataCache->getByTag(Session::TAG_PREFIX . $tag) as $sessionIdentifier => $sessionInfo) {
         $session = new Session($sessionIdentifier, $sessionInfo['storageIdentifier'], $sessionInfo['lastActivityTimestamp'], $sessionInfo['tags']);
         $taggedSessions[] = $session;
     }
     return $taggedSessions;
 }
 /**
  * When it's called, XML file is parsed (using parser set in $xmlParser)
  * or cache is loaded, if available.
  *
  * @return void
  */
 public function initializeObject()
 {
     if ($this->cache->has(md5($this->sourcePath))) {
         $this->xmlParsedData = $this->cache->get(md5($this->sourcePath));
     } else {
         $this->xmlParsedData = $this->xmlParser->getParsedData($this->sourcePath);
         $this->cache->set(md5($this->sourcePath), $this->xmlParsedData);
     }
 }
 /**
  * When it's called, CLDR file is parsed or cache is loaded, if available.
  *
  * @return void
  */
 public function initializeObject()
 {
     if ($this->cache->has($this->cacheKey)) {
         $this->parsedData = $this->cache->get($this->cacheKey);
     } else {
         $this->parsedData = $this->parseFiles($this->sourcePaths);
         $this->parsedData = $this->resolveAliases($this->parsedData, '');
         $this->cache->set($this->cacheKey, $this->parsedData);
     }
 }
 /**
  * Constructs the reader, loading parsed data from cache if available.
  *
  * @return void
  */
 public function initializeObject()
 {
     if ($this->cache->has('rulesets') && $this->cache->has('rulesetsIndices')) {
         $this->rulesets = $this->cache->get('rulesets');
         $this->rulesetsIndices = $this->cache->get('rulesetsIndices');
     } else {
         $this->generateRulesets();
         $this->cache->set('rulesets', $this->rulesets);
         $this->cache->set('rulesetsIndices', $this->rulesetsIndices);
     }
 }
Exemplo n.º 11
0
 /**
  * This checks if a given hash is known and still valid before returning the associated Token.
  *
  * If no valid Token is found for the hash, NULL is returned.
  *
  * @param $tokenHash
  * @return Token
  */
 public function validateTokenHash($tokenHash)
 {
     $tokenData = $this->tokenCache->get($tokenHash);
     if ($tokenData === FALSE) {
         $this->logger->log(sprintf('Validation of token hash %s failed', $tokenHash), LOG_INFO);
         return NULL;
     }
     $this->tokenCache->remove($tokenHash);
     $this->logger->log(sprintf('Validated token hash %s for identifier %s', $tokenHash, $tokenData['identifier']), LOG_INFO);
     return new Token($tokenHash, $tokenData['identifier'], $this->getPreset($tokenData['presetName']), $tokenData['meta']);
 }
 public function setUp()
 {
     $this->viewConfigurationManager = new ViewConfigurationManager();
     // eel evaluator
     $eelEvaluator = new CompilingEvaluator();
     $this->inject($this->viewConfigurationManager, 'eelEvaluator', $eelEvaluator);
     // a dummy configuration manager is prepared
     $this->mockConfigurationManager = $this->getMockBuilder(ConfigurationManager::class)->disableOriginalConstructor()->getMock();
     $this->inject($this->viewConfigurationManager, 'configurationManager', $this->mockConfigurationManager);
     // caching is deactivated
     $this->mockCache = $this->getMockBuilder(VariableFrontend::class)->disableOriginalConstructor()->getMock();
     $this->mockCache->expects($this->any())->method('get')->will($this->returnValue(false));
     $this->inject($this->viewConfigurationManager, 'cache', $this->mockCache);
     // a dummy request is prepared
     $this->mockActionRequest = $this->getMockBuilder(ActionRequest::class)->disableOriginalConstructor()->getMock();
     $this->mockActionRequest->expects($this->any())->method('getControllerPackageKey')->will($this->returnValue('Neos.Flow'));
     $this->mockActionRequest->expects($this->any())->method('getControllerSubpackageKey')->will($this->returnValue(''));
     $this->mockActionRequest->expects($this->any())->method('getControllerName')->will($this->returnValue('Standard'));
     $this->mockActionRequest->expects($this->any())->method('getControllerActionName')->will($this->returnValue('index'));
     $this->mockActionRequest->expects($this->any())->method('getFormat')->will($this->returnValue('html'));
     $this->mockActionRequest->expects($this->any())->method('getParentRequest')->will($this->returnValue(null));
 }
 /**
  * Builds proxy class code which weaves advices into the respective target classes.
  *
  * The object configurations provided by the Compiler are searched for possible aspect
  * annotations. If an aspect class is found, the pointcut expressions are parsed and
  * a new aspect with one or more advisors is added to the aspect registry of the AOP framework.
  * Finally all advices are woven into their target classes by generating proxy classes.
  *
  * In general, the command neos.flow:core:compile is responsible for compilation
  * and calls this method to do so.
  *
  * In order to distinguish between an emerged / changed possible target class and
  * a class which has been matched previously but just didn't have to be proxied,
  * the latter are kept track of by an "unproxiedClass-*" cache entry.
  *
  * @return void
  */
 public function build()
 {
     $allAvailableClassNamesByPackage = $this->objectManager->getRegisteredClassNames();
     $possibleTargetClassNames = $this->getProxyableClasses($allAvailableClassNamesByPackage);
     $actualAspectClassNames = $this->reflectionService->getClassNamesByAnnotation(Flow\Aspect::class);
     sort($possibleTargetClassNames);
     sort($actualAspectClassNames);
     $this->aspectContainers = $this->buildAspectContainers($actualAspectClassNames);
     $rebuildEverything = false;
     if ($this->objectConfigurationCache->has('allAspectClassesUpToDate') === false) {
         $rebuildEverything = true;
         $this->systemLogger->log('Aspects have been modified, therefore rebuilding all target classes.', LOG_INFO);
         $this->objectConfigurationCache->set('allAspectClassesUpToDate', true);
     }
     $possibleTargetClassNameIndex = new ClassNameIndex();
     $possibleTargetClassNameIndex->setClassNames($possibleTargetClassNames);
     $targetClassNameCandidates = new ClassNameIndex();
     foreach ($this->aspectContainers as $aspectContainer) {
         $targetClassNameCandidates->applyUnion($aspectContainer->reduceTargetClassNames($possibleTargetClassNameIndex));
     }
     $targetClassNameCandidates->sort();
     $treatedSubClasses = new ClassNameIndex();
     foreach ($targetClassNameCandidates->getClassNames() as $targetClassName) {
         $isUnproxied = $this->objectConfigurationCache->has('unproxiedClass-' . str_replace('\\', '_', $targetClassName));
         $hasCacheEntry = $this->compiler->hasCacheEntryForClass($targetClassName) || $isUnproxied;
         if ($rebuildEverything === true || $hasCacheEntry === false) {
             $proxyBuildResult = $this->buildProxyClass($targetClassName, $this->aspectContainers);
             if ($proxyBuildResult === false) {
                 // In case the proxy was not build because there was nothing adviced,
                 // it might be an advice in the parent and so we need to try to treat this class.
                 $treatedSubClasses = $this->addBuildMethodsAndAdvicesCodeToClass($targetClassName, $treatedSubClasses);
             }
             $treatedSubClasses = $this->proxySubClassesOfClassToEnsureAdvices($targetClassName, $targetClassNameCandidates, $treatedSubClasses);
             if ($proxyBuildResult !== false) {
                 if ($isUnproxied) {
                     $this->objectConfigurationCache->remove('unproxiedClass-' . str_replace('\\', '_', $targetClassName));
                 }
                 $this->systemLogger->log(sprintf('Built AOP proxy for class "%s".', $targetClassName), LOG_DEBUG);
             } else {
                 $this->objectConfigurationCache->set('unproxiedClass-' . str_replace('\\', '_', $targetClassName), true);
             }
         }
     }
 }
 /**
  * Get the size of a Flow PersistentResource that contains an image file.
  *
  * @param PersistentResource $resource
  * @return array width and height as keys
  * @throws ImageFileException
  */
 public function getImageSize(PersistentResource $resource)
 {
     $cacheIdentifier = $resource->getCacheEntryIdentifier();
     $imageSize = $this->imageSizeCache->get($cacheIdentifier);
     if ($imageSize !== false) {
         return $imageSize;
     }
     // TODO: Special handling for SVG should be refactored at a later point.
     if ($resource->getMediaType() === 'image/svg+xml') {
         $imageSize = ['width' => null, 'height' => null];
     } else {
         try {
             $imagineImage = $this->imagineService->read($resource->getStream());
             $sizeBox = $imagineImage->getSize();
             $imageSize = array('width' => $sizeBox->getWidth(), 'height' => $sizeBox->getHeight());
         } catch (\Exception $e) {
             throw new ImageFileException(sprintf('The given resource was not an image file your choosen driver can open. The original error was: %s', $e->getMessage()), 1336662898);
         }
     }
     $this->imageSizeCache->set($cacheIdentifier, $imageSize);
     return $imageSize;
 }
 /**
  * Builds the  objects array which contains information about the registered objects,
  * their scope, class, built method etc.
  *
  * @return array
  */
 protected function buildObjectsArray()
 {
     $objects = [];
     foreach ($this->objectConfigurations as $objectConfiguration) {
         $objectName = $objectConfiguration->getObjectName();
         $objects[$objectName] = ['l' => strtolower($objectName), 's' => $objectConfiguration->getScope(), 'p' => $objectConfiguration->getPackageKey()];
         if ($objectConfiguration->getClassName() !== $objectName) {
             $objects[$objectName]['c'] = $objectConfiguration->getClassName();
         }
         if ($objectConfiguration->getFactoryObjectName() !== '') {
             $objects[$objectName]['f'] = [$objectConfiguration->getFactoryObjectName(), $objectConfiguration->getFactoryMethodName()];
             $objects[$objectName]['fa'] = [];
             $factoryMethodArguments = $objectConfiguration->getArguments();
             if (count($factoryMethodArguments) > 0) {
                 foreach ($factoryMethodArguments as $index => $argument) {
                     $objects[$objectName]['fa'][$index] = ['t' => $argument->getType(), 'v' => $argument->getValue()];
                 }
             }
         }
     }
     $this->configurationCache->set('objects', $objects);
     return $objects;
 }
 /**
  * @test
  * @requires extension igbinary
  */
 public function getByTagUsesIgBinaryIfAvailable()
 {
     $tag = 'sometag';
     $identifiers = ['one', 'two'];
     $entries = ['one' => 'one value', 'two' => 'two value'];
     $backend = $this->prepareDefaultBackend();
     $backend->expects($this->once())->method('findIdentifiersByTag')->with($this->equalTo($tag))->will($this->returnValue($identifiers));
     $backend->expects($this->exactly(2))->method('get')->will($this->onConsecutiveCalls(igbinary_serialize('one value'), igbinary_serialize('two value')));
     $cache = new VariableFrontend('VariableFrontend', $backend);
     $cache->initializeObject();
     $this->assertEquals($entries, $cache->getByTag($tag), 'Did not receive the expected entries');
 }
 /**
  * @test
  */
 public function flushCachesResetsBothRoutingCaches()
 {
     $this->mockRouteCache->expects($this->once())->method('flush');
     $this->mockResolveCache->expects($this->once())->method('flush');
     $this->routerCachingService->flushCaches();
 }
Exemplo n.º 18
0
 /**
  * @return boolean
  */
 protected function hasFrozenCacheInProduction()
 {
     return $this->environment->getContext()->isProduction() && $this->reflectionDataRuntimeCache->getBackend()->isFrozen();
 }
 /**
  * Shutdowns the object, saving parsed format strings to the cache.
  *
  * @return void
  */
 public function shutdownObject()
 {
     $this->cache->set('parsedFormats', $this->parsedFormats);
     $this->cache->set('parsedFormatsIndices', $this->parsedFormatsIndices);
     $this->cache->set('localizedLiterals', $this->localizedLiterals);
 }
 /**
  * Creates a cache for testing
  *
  * @param string $name
  * @return VariableFrontend
  */
 protected function createCache($name)
 {
     $backend = new FileBackend(new EnvironmentConfiguration('Session Testing', 'vfs://Foo/', PHP_MAXPATHLEN));
     $cache = new VariableFrontend($name, $backend);
     $cache->initializeObject();
     $backend->setCache($cache);
     $cache->flush();
     return $cache;
 }
Exemplo n.º 21
0
 /**
  * Removes the session info cache entry for the specified session.
  *
  * Note that this function does only remove the "head" cache entry, not the
  * related data referred to by the storage identifier.
  *
  * @param string $sessionIdentifier
  * @return void
  */
 protected function removeSessionMetaDataCacheEntry($sessionIdentifier)
 {
     $this->metaDataCache->remove($sessionIdentifier);
 }
 /**
  * Flushes 'findMatchResults' and 'resolve' caches for the given $tag
  *
  * @param string $tag
  * @return void
  */
 public function flushCachesByTag($tag)
 {
     $this->routeCache->flushByTag($tag);
     $this->resolveCache->flushByTag($tag);
 }