/** * 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; }
/** * Checks the cache for the route path given in the Request and returns the result * * @param Request $httpRequest * @return array|boolean the cached route values or FALSE if no cache entry was found */ public function getCachedMatchResults(Request $httpRequest) { $cachedResult = $this->routeCache->get($this->buildRouteCacheIdentifier($httpRequest)); if ($cachedResult !== false) { $this->systemLogger->log(sprintf('Router route(): A cached Route with the cache identifier "%s" matched the path "%s".', $this->buildRouteCacheIdentifier($httpRequest), $httpRequest->getRelativePath()), LOG_DEBUG); } return $cachedResult; }
/** * 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); }
/** * 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; }
/** * Returns the specified session. If no session with the given identifier exists, * NULL is returned. * * @param string $sessionIdentifier The session identifier * @return SessionInterface * @api */ public function getSession($sessionIdentifier) { if ($this->currentSession !== null && $this->currentSession->isStarted() && $this->currentSession->getId() === $sessionIdentifier) { return $this->currentSession; } if (isset($this->remoteSessions[$sessionIdentifier])) { return $this->remoteSessions[$sessionIdentifier]; } if ($this->metaDataCache->has($sessionIdentifier)) { $sessionInfo = $this->metaDataCache->get($sessionIdentifier); $this->remoteSessions[$sessionIdentifier] = new Session($sessionIdentifier, $sessionInfo['storageIdentifier'], $sessionInfo['lastActivityTimestamp'], $sessionInfo['tags']); return $this->remoteSessions[$sessionIdentifier]; } }
/** * Returns the data associated with the given key. * * @param string $key An identifier for the content stored in the session. * @return mixed The contents associated with the given key * @throws Exception\SessionNotStartedException */ public function getData($key) { if ($this->started !== true) { throw new Exception\SessionNotStartedException('Tried to get session data, but the session has not been started yet.', 1351162255); } return $this->storageCache->get($this->storageIdentifier . md5($key)); }
/** * Constructs the reader, loading parsed data from cache if available. * * @return void */ public function initializeObject() { if ($this->cache->has('parsedFormats') && $this->cache->has('parsedFormatsIndices') && $this->cache->has('localizedSymbols')) { $this->parsedFormats = $this->cache->get('parsedFormats'); $this->parsedFormatsIndices = $this->cache->get('parsedFormatsIndices'); $this->localizedSymbols = $this->cache->get('localizedSymbols'); } }
/** * 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); } }
/** * @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; }
/** * 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); } }
/** * 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']); }
/** * 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; }
/** * @test * @requires extension igbinary */ public function getUsesIgBinaryIfAvailable() { $theArray = ['Just some value', 'and another one.']; $backend = $this->prepareDefaultBackend(); $backend->expects($this->once())->method('get')->will($this->returnValue(igbinary_serialize($theArray))); $cache = new VariableFrontend('VariableFrontend', $backend); $cache->initializeObject(); $this->assertEquals($theArray, $cache->get('VariableCacheTest'), 'The returned value was not the expected unserialized array.'); }
/** * @return void */ public function initializeObject() { if ($this->methodPermissionCache->has('methodPermission')) { $this->methodPermissions = $this->methodPermissionCache->get('methodPermission'); } }
/** * Loads reflection data from the cache or reflects the class if needed. * * If the class is completely unknown, this method won't try to load or reflect * it. If it is known and reflection data has been loaded already, it won't be * loaded again. * * In Production context, with frozen caches, this method will load reflection * data for the specified class from the runtime cache. * * @param string $className Name of the class to load data for * @return void */ protected function loadOrReflectClassIfNecessary($className) { if (!isset($this->classReflectionData[$className]) || is_array($this->classReflectionData[$className])) { return; } if ($this->loadFromClassSchemaRuntimeCache === true) { $this->classReflectionData[$className] = $this->reflectionDataRuntimeCache->get($this->produceCacheIdentifierFromClassName($className)); return; } $this->reflectClass($className); }