Ejemplo n.º 1
0
 /**
  * @param Locale $locale
  * @param Language $language
  * @return string
  */
 public function getLanguageLocalizedName(Locale $locale, Language $language)
 {
     $cacheIdentifier = 'language-labels-' . $locale->getLanguage();
     $labelsFromCache = $this->languageCache->get($cacheIdentifier);
     if ($labelsFromCache) {
         return $labelsFromCache[$language->getKey()];
     }
     try {
         $raw = $this->cldrRepository->getModelForLocale($locale)->getRawArray('localeDisplayNames/languages');
     } catch (\Exception $e) {
         return 'Problem reading data for ' . $language->getKey();
     }
     $languages = $this->getLanguages();
     $labels = array();
     /** @var Language $currentLanguage */
     foreach ($languages as $currentLanguage) {
         try {
             $key = 'language[@type="' . $currentLanguage->getKey() . '"]';
             if (is_array($raw)) {
                 if (array_key_exists($key, $raw)) {
                     $labels[$currentLanguage->getKey()] = $raw[$key];
                 } else {
                     $labels[$currentLanguage->getKey()] = $currentLanguage->getName();
                 }
             } else {
                 $labels[$currentLanguage->getKey()] = 'Nothing found for ' . $currentLanguage->getKey();
             }
         } catch (\Exception $e) {
             // not found
             // $labels[$key] = 'Nothing found for ' . $language->getKey();
         }
     }
     $this->languageCache->set($cacheIdentifier, $labels);
     return $labels[$language->getKey()];
 }
 /**
  * Return the json array for a given locale, sourceCatalog, xliffPath and package.
  * The json will be cached.
  *
  * @param Locale $locale The locale
  * @throws \TYPO3\Flow\I18n\Exception
  * @return \TYPO3\Flow\Error\Result
  */
 public function getCachedJson(Locale $locale)
 {
     $cacheIdentifier = md5($locale);
     if ($this->xliffToJsonTranslationsCache->has($cacheIdentifier)) {
         $json = $this->xliffToJsonTranslationsCache->get($cacheIdentifier);
     } else {
         $labels = [];
         $localeChain = $this->localizationService->getLocaleChain($locale);
         foreach ($this->packagesRegisteredForAutoInclusion as $packageKey => $sourcesToBeIncluded) {
             if (!is_array($sourcesToBeIncluded)) {
                 continue;
             }
             $translationBasePath = Files::concatenatePaths([$this->packageManager->getPackage($packageKey)->getResourcesPath(), $this->xliffBasePath]);
             // We merge labels in the chain from the worst choice to best choice
             foreach (array_reverse($localeChain) as $allowedLocale) {
                 $localeSourcePath = Files::getNormalizedPath(Files::concatenatePaths([$translationBasePath, $allowedLocale]));
                 foreach ($sourcesToBeIncluded as $sourceName) {
                     foreach (glob($localeSourcePath . $sourceName . '.xlf') as $xliffPathAndFilename) {
                         $xliffPathInfo = pathinfo($xliffPathAndFilename);
                         $sourceName = str_replace($localeSourcePath, '', $xliffPathInfo['dirname'] . '/' . $xliffPathInfo['filename']);
                         $labels = Arrays::arrayMergeRecursiveOverrule($labels, $this->parseXliffToArray($xliffPathAndFilename, $packageKey, $sourceName));
                     }
                 }
             }
         }
         $json = json_encode($labels);
         $this->xliffToJsonTranslationsCache->set($cacheIdentifier, $json);
     }
     return $json;
 }
 /**
  * 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 \TYPO3\Flow\Mvc\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);
         $matchingConfigurations = array();
         foreach ($configurations as $order => $configuration) {
             $requestMatcher->resetWeight();
             if (!isset($configuration['requestFilter'])) {
                 $matchingConfigurations[$order]['configuration'] = $configuration;
                 $matchingConfigurations[$order]['weight'] = $order;
             } else {
                 $result = $this->eelEvaluator->evaluate($configuration['requestFilter'], $context);
                 if ($result === false) {
                     continue;
                 }
                 $matchingConfigurations[$order]['configuration'] = $configuration;
                 $matchingConfigurations[$order]['weight'] = $requestMatcher->getWeight() + $order;
             }
         }
         usort($matchingConfigurations, function ($configuration1, $configuration2) {
             return $configuration1['weight'] > $configuration2['weight'];
         });
         $viewConfiguration = array();
         foreach ($matchingConfigurations as $key => $matchingConfiguration) {
             $viewConfiguration = Arrays::arrayMergeRecursiveOverrule($viewConfiguration, $matchingConfiguration['configuration']);
         }
         $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;
 }
Ejemplo n.º 5
0
 /**
  * Initialize the object and load caches
  */
 public function initializeObject()
 {
     if (!$this->cache->get('systemNodeIdentifiers')) {
         $this->initializeSystemNodes();
     } else {
         $this->systemNodeIdentifiers = $this->cache->get('systemNodeIdentifiers');
     }
 }
 /**
  * Lifecycle method, called after all dependencies have been injected.
  * Here, the typeConverter array gets initialized.
  *
  * @return void
  * @throws Exception\DuplicateTypeConverterException
  */
 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);
 }
Ejemplo n.º 7
0
 /**
  * @param string $cacheKey
  *
  * @return mixed
  */
 protected function getItem($cacheKey)
 {
     if (array_key_exists($cacheKey, $this->objectCache)) {
         return $this->objectCache[$cacheKey];
     }
     $item = $this->apiCache->get($cacheKey);
     $this->objectCache[$cacheKey] = $item;
     return $item;
 }
Ejemplo n.º 8
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(TYPO3.Neos.typoScript.enableObjectTreeCache) && method(TYPO3\Neos\Domain\Service\TypoScriptService->getMergedTypoScriptObjectTree())")
  * @param \TYPO3\Flow\Aop\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 \TYPO3\Flow\Session\Session
  * @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];
     }
 }
Ejemplo n.º 11
0
 /**
  * @Flow\Around("setting(Ttree.Embedly.logApiRequest) && within(Ttree\Embedly\Embedly) && method(public .*->(oembed|preview|objectify|extract|services)())")
  * @param JoinPointInterface $joinPoint The current join point
  * @return mixed
  */
 public function getResponseFromCache(JoinPointInterface $joinPoint)
 {
     $proxy = $joinPoint->getProxy();
     $key = ObjectAccess::getProperty($proxy, 'key');
     $params = $joinPoint->getMethodArgument('params');
     $cacheKey = md5($joinPoint->getClassName() . $joinPoint->getMethodName() . $key . json_encode($params));
     if ($this->responseCache->has($cacheKey)) {
         $this->systemLogger->log(sprintf('   cache hit Embedly::%s', $joinPoint->getMethodName()), LOG_DEBUG);
         return $this->responseCache->get($cacheKey);
     } else {
         $this->systemLogger->log(sprintf('   cache miss Embedly::%s', $joinPoint->getMethodName()), LOG_DEBUG);
     }
     $response = $joinPoint->getAdviceChain()->proceed($joinPoint);
     $this->responseCache->set($cacheKey, $response);
     return $response;
 }
 /**
  * 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 \TYPO3\Flow\Session\Exception\SessionNotStartedException
  */
 public function getData($key)
 {
     if ($this->started !== true) {
         throw new \TYPO3\Flow\Session\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('localizedLiterals')) {
         $this->parsedFormats = $this->cache->get('parsedFormats');
         $this->parsedFormatsIndices = $this->cache->get('parsedFormatsIndices');
         $this->localizedLiterals = $this->cache->get('localizedLiterals');
     }
 }
 /**
  * @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, 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);
     }
 }
 /**
  * Validate that all required assertion steps of a badge were completed and remove the stored assertion steps for all tokens
  *
  * @param BadgeClass $badgeClass
  * @param array $tokens
  * @return boolean
  */
 public function validateAndClearAssertionSteps(BadgeClass $badgeClass, array $tokens)
 {
     $completedAssertionSteps = array();
     foreach ($tokens as $token) {
         $assertionStep = $this->assertionStepStore->get($token);
         if ($assertionStep instanceof AssertionStep && $assertionStep->getBadgeClass() === $badgeClass) {
             $completedAssertionSteps[$assertionStep->getIdentifier()] = $assertionStep;
         }
     }
     foreach ($badgeClass->getAssertionSteps() as $stepIdentifier) {
         if (!isset($completedAssertionSteps[$stepIdentifier])) {
             return FALSE;
         }
     }
     foreach ($tokens as $token) {
         $this->assertionStepStore->remove($token);
     }
     return TRUE;
 }
 /**
  * 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);
     }
 }
Ejemplo n.º 18
0
 /**
  * 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(str_replace('\\', '_', $className));
     } else {
         $this->reflectClass($className);
     }
 }
 /**
  * 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);
     }
 }
 /**
  * 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);
 }
 /**
  * Initializes this Policy Service
  *
  * @return void
  */
 public function initializeObject()
 {
     $this->policy = $this->configurationManager->getConfiguration(\TYPO3\Flow\Configuration\ConfigurationManager::CONFIGURATION_TYPE_POLICY);
     $this->setAclsForEverybodyRole();
     if ($this->cache->has('acls')) {
         $this->acls = $this->cache->get('acls');
     } else {
         $this->parseEntityAcls();
     }
     if ($this->cache->has('entityResourcesConstraints')) {
         $this->entityResourcesConstraints = $this->cache->get('entityResourcesConstraints');
     } else {
         if (array_key_exists('resources', $this->policy) && array_key_exists('entities', $this->policy['resources'])) {
             $this->entityResourcesConstraints = $this->policyExpressionParser->parseEntityResources($this->policy['resources']['entities']);
         }
     }
 }
Ejemplo n.º 22
0
 /**
  * @param boolean
  * @return array
  */
 public function getDynamicTasks($dueOnly = FALSE)
 {
     $tasks = array();
     $now = new Now();
     foreach (self::getAllDynamicTaskImplementations($this->objectManager) as $dynamicTask) {
         $task = new Task($dynamicTask['expression'], $dynamicTask['implementation']);
         $cacheKey = md5($dynamicTask['implementation']);
         $lastExecution = $this->dynamicTaskLastExecutionCache->get($cacheKey);
         if ($dueOnly && ($lastExecution instanceof \DateTime && $now < $task->getNextExecution($lastExecution))) {
             continue;
         }
         $task->enable();
         $taskDecriptor = $this->getTaskDescriptor(TaskInterface::TYPE_DYNAMIC, $task);
         $taskDecriptor['lastExecution'] = $lastExecution instanceof \DateTime ? $lastExecution->format(\DateTime::ISO8601) : '';
         $taskDecriptor['identifier'] = '';
         $tasks[] = $taskDecriptor;
     }
     return $tasks;
 }
 /**
  * Get the size of a Flow Resource object that contains an image file.
  *
  * @param FlowResource $resource
  * @return array width and height as keys
  * @throws ImageFileException
  */
 public function getImageSize(FlowResource $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;
 }
 /**
  * Shows the methods represented by the given security resource
  *
  * @param string $resourceName The name of the resource as stated in the policy
  * @return void
  */
 public function showMethodsForResourceCommand($resourceName)
 {
     if ($this->policyCache->has('acls')) {
         $classes = array();
         $acls = $this->policyCache->get('acls');
         foreach ($acls as $classAndMethodName => $aclEntry) {
             if (strpos($classAndMethodName, '->') === FALSE) {
                 continue;
             }
             list($className, $methodName) = explode('->', $classAndMethodName);
             $className = $this->objectManager->getCaseSensitiveObjectName($className);
             $reflectionClass = new \ReflectionClass($className);
             foreach ($reflectionClass->getMethods() as $casSensitiveMethodName) {
                 if ($methodName === strtolower($casSensitiveMethodName->getName())) {
                     $methodName = $casSensitiveMethodName->getName();
                     break;
                 }
             }
             foreach ($aclEntry as $resources) {
                 if (array_key_exists($resourceName, $resources)) {
                     $classes[$className][$methodName] = $methodName;
                     break;
                 }
             }
         }
         if (count($classes) === 0) {
             $this->outputLine('The given Resource did not match any method or is unknown.');
             $this->quit(1);
         }
         foreach ($classes as $className => $methods) {
             $this->outputLine(PHP_EOL . $className);
             foreach ($methods as $methodName) {
                 $this->outputLine('  ' . $methodName);
             }
         }
     } else {
         $this->outputLine('Could not find any policy entries, please warmup caches!');
     }
 }
 /**
  * @param string $importerClassName
  * @param string $externalIdentifier
  * @return ProcessedNodeDefinition
  */
 public function get($importerClassName, $externalIdentifier)
 {
     $entryIdentifier = $this->getEntryIdentifier($importerClassName, $externalIdentifier);
     return $this->cache->get($entryIdentifier);
 }
 /**
  * Initialize the object and load caches
  */
 public function initializeObject()
 {
     $this->postalCodeCoordinates = $this->cache->get('postalCodeCoordinates') ?: [];
     $this->addressCoordinates = $this->cache->get('addressCoordinates') ?: [];
 }
 /**
  * @return void
  */
 public function initializeObject()
 {
     if ($this->methodPermissionCache->has('methodPermission')) {
         $this->methodPermissions = $this->methodPermissionCache->get('methodPermission');
     }
 }