/** * Returns the cache breaking string * * @return mixed */ public function get() { if (!$this->storage->has(self::STORAGE_KEY)) { $this->update(); } return $this->storage->get(self::STORAGE_KEY); }
/** * Set up test dependencies * * @return void */ public function setUp() { $this->cache = new StringFrontend('TestCache', new TransientMemoryBackend(new ApplicationContext('Testing'))); $this->cache->initializeObject(); $this->hashService = new HashService(); $this->inject($this->hashService, 'cache', $this->cache); }
/** * Redirects to the Neos backend on the given site, passing a one-time login token * * @param Site $site * @return void */ public function switchSiteAction($site) { $token = Algorithms::generateRandomToken(32); $this->loginTokenCache->set($token, $this->currentSession->getId()); $siteUri = $this->linkingService->createSiteUri($this->controllerContext, $site); $loginUri = $this->controllerContext->getUriBuilder()->reset()->uriFor('tokenLogin', ['token' => $token], 'Login', 'TYPO3.Neos'); $this->redirectToUri($siteUri . $loginUri); }
/** * @return string The current cache version identifier */ public function render() { $version = $this->configurationCache->get('ConfigurationVersion'); if ($version === false) { $version = time(); $this->configurationCache->set('ConfigurationVersion', (string) $version); } return $version; }
/** * Redirects to the Neos backend on the given hostname, passing a one-time login token * * @param string $hostname * @return void */ public function switchSiteAction($hostname) { $token = Algorithms::generateRandomToken(32); $this->loginTokenCache->set($token, $this->currentSession->getId()); $requestUri = $this->controllerContext->getRequest()->getHttpRequest()->getUri(); $baseUri = $this->controllerContext->getRequest()->getHttpRequest()->getBaseUri(); $uri = $this->controllerContext->getUriBuilder()->reset()->uriFor('tokenLogin', ['token' => $token], 'Login', 'TYPO3.Neos'); $uri = sprintf('%s://%s%s%s', $requestUri->getScheme(), $hostname, rtrim($baseUri->getPath(), '/'), $uri); $this->redirectToUri($uri); }
/** * Caches the directories and their files * * @return void */ public function shutdownObject() { if ($this->directoriesChanged === TRUE) { $this->cache->set($this->identifier . '_directoriesAndFiles', json_encode($this->directoriesAndFiles)); } $this->changeDetectionStrategy->shutdownObject(); }
/** * {@inheritdoc} */ public function getByTag($tag) { $entries = parent::getByTag($tag); foreach ($entries as $identifier => $content) { $entries[$identifier] = $this->extractMetadata($identifier, $content); } return $entries; }
/** * @test */ public function storeResolvedUriPathConvertsObjectsImplementingCacheAwareInterfaceToCacheEntryIdentifier() { $mockObject = $this->getMock(\TYPO3\Flow\Cache\CacheAwareInterface::class); $mockObject->expects($this->atLeastOnce())->method('getCacheEntryIdentifier')->will($this->returnValue('objectIdentifier')); $routeValues = array('b' => 'route values', 'someObject' => $mockObject); $cacheIdentifier = '264b593d59582adea4ccc52b33cc093f'; $matchingUriPath = 'uncached/matching/uri'; $this->mockResolveCache->expects($this->once())->method('set')->with($cacheIdentifier, $matchingUriPath); $this->routerCachingService->storeResolvedUriPath($matchingUriPath, $routeValues); }
/** * Prepares a mirror of public package resources that is accessible through * the web server directly. * * @param array $activePackages * @return void */ public function publishPublicPackageResources(array $activePackages) { if ($this->settings['resource']['publishing']['detectPackageResourceChanges'] === FALSE && $this->statusCache->has('packageResourcesPublished')) { return; } foreach ($activePackages as $packageKey => $package) { $this->resourcePublisher->publishStaticResources($package->getResourcesPath() . 'Public/', 'Packages/' . $packageKey . '/'); } if (!$this->statusCache->has('packageResourcesPublished')) { $this->statusCache->set('packageResourcesPublished', 'y', array(\TYPO3\Flow\Cache\Frontend\FrontendInterface::TAG_PACKAGE)); } }
/** * Set updated reflection data to caches. */ protected function updateReflectionData() { $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($this->produceCacheIdentifierFromClassName($className), ''); } $data = []; $propertyNames = ['classReflectionData', 'classSchemata', 'annotatedClasses', 'classesByMethodAnnotations']; foreach ($propertyNames as $propertyName) { $data[$propertyName] = $this->{$propertyName}; } $this->reflectionDataCompiletimeCache->set('ReflectionData', $data); }
/** * Logs a user in if a session identifier is available under the given token in the token cache. * * @param string $token * @return void */ public function tokenLoginAction($token) { $sessionId = $this->loginTokenCache->get($token); $this->loginTokenCache->remove($token); if ($sessionId === false) { $this->systemLogger->log(sprintf('Token-based login failed, non-existing or expired token %s', $token), LOG_WARNING); $this->redirect('index'); } else { $this->systemLogger->log(sprintf('Token-based login succeeded, token %s', $token), LOG_DEBUG); $this->replaceSessionCookie($sessionId); $this->redirect('index', 'Backend\\Backend'); } }
/** * Returns the encryption key from the persistent cache or Data/Persistent directory. If none exists, a new * encryption key will be generated and stored in the cache. * * @return string The configured encryption key stored in Data/Persistent/EncryptionKey */ protected function getEncryptionKey() { if ($this->encryptionKey === null) { $this->encryptionKey = $this->cache->get('encryptionKey'); } if ($this->encryptionKey === false && file_exists(FLOW_PATH_DATA . 'Persistent/EncryptionKey')) { $this->encryptionKey = file_get_contents(FLOW_PATH_DATA . 'Persistent/EncryptionKey'); } if ($this->encryptionKey === false) { $this->encryptionKey = UtilityAlgorithms::generateRandomToken(48); $this->cache->set('encryptionKey', $this->encryptionKey); } return $this->encryptionKey; }
/** * Returns the encryption key from the persistent cache or Data/Persistent directory. If none exists, a new * encryption key will be generated and stored in the cache. * * @return string The configured encryption key stored in Data/Persistent/EncryptionKey */ protected function getEncryptionKey() { if ($this->encryptionKey === NULL) { $this->encryptionKey = $this->cache->get('encryptionKey'); } if ($this->encryptionKey === FALSE && file_exists(FLOW_PATH_DATA . 'Persistent/EncryptionKey')) { $this->encryptionKey = file_get_contents(FLOW_PATH_DATA . 'Persistent/EncryptionKey'); } if ($this->encryptionKey === FALSE) { $this->encryptionKey = bin2hex(\TYPO3\Flow\Utility\Algorithms::generateRandomBytes(96)); $this->cache->set('encryptionKey', $this->encryptionKey); } return $this->encryptionKey; }
/** * 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); } } } }
/** * Loads all node types into memory. * * @return void */ protected function loadNodeTypes() { $this->fullNodeTypeConfigurations = $this->fullConfigurationCache->get('fullNodeTypeConfigurations'); $fillFullConfigurationCache = !is_array($this->fullNodeTypeConfigurations); $completeNodeTypeConfiguration = $this->configurationManager->getConfiguration('NodeTypes'); foreach (array_keys($completeNodeTypeConfiguration) as $nodeTypeName) { $nodeType = $this->loadNodeType($nodeTypeName, $completeNodeTypeConfiguration, isset($this->fullNodeTypeConfigurations[$nodeTypeName]) ? $this->fullNodeTypeConfigurations[$nodeTypeName] : null); if ($fillFullConfigurationCache) { $this->fullNodeTypeConfigurations[$nodeTypeName] = $nodeType->getFullConfiguration(); } } if ($fillFullConfigurationCache) { $this->fullConfigurationCache->set('fullNodeTypeConfigurations', $this->fullNodeTypeConfigurations); } $this->fullNodeTypeConfigurations = null; }
/** * Logs a user in if a session identifier is available under the given token in the token cache. * * @param string $token * @return void */ public function tokenLoginAction($token) { $newSessionId = $this->loginTokenCache->get($token); $this->loginTokenCache->remove($token); if ($newSessionId === false) { $this->systemLogger->log(sprintf('Token-based login failed, non-existing or expired token %s', $token), LOG_WARNING); $this->redirect('index'); } $this->systemLogger->log(sprintf('Token-based login succeeded, token %s', $token), LOG_DEBUG); $newSession = $this->sessionManager->getSession($newSessionId); if ($newSession->canBeResumed()) { $newSession->resume(); } if ($newSession->isStarted()) { $newSession->putData('lastVisitedNode', null); } else { $this->systemLogger->log(sprintf('Failed resuming or starting session %s which was referred to in the login token %s.', $newSessionId, $token), LOG_ERR); } $this->replaceSessionCookie($newSessionId); $this->redirect('index', 'Backend\\Backend'); }
/** * 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); }
/** * Flush all content cache entries * * @return void */ public function flush() { $this->cache->flush(); }
/** * Flushes 'findMatchResults' and 'resolve' caches for the given $tag * * @param string $tag * @return void */ public function flushCachesByTag($tag) { $this->findMatchResultsCache->flushByTag($tag); $this->resolveCache->flushByTag($tag); }
/** * Caches the file modification times * * @return void */ public function shutdownObject() { if ($this->modificationTimesChanged === true) { $this->cache->set($this->fileMonitor->getIdentifier() . '_filesAndModificationTimes', json_encode($this->filesAndModificationTimes)); } }
/** * Constructs the cache * * @param string $identifier A identifier which describes this cache * @param \TYPO3\Flow\Cache\Backend\PhpCapableBackendInterface $backend Backend to be used for this cache */ public function __construct($identifier, \TYPO3\Flow\Cache\Backend\PhpCapableBackendInterface $backend) { parent::__construct($identifier, $backend); }
/** * Store the changed directories and files back to the cache. * * @return void */ protected function saveDetectedDirectoriesAndFiles() { $this->cache->set($this->identifier . '_directoriesAndFiles', json_encode($this->directoriesAndFiles)); }
/** * @param string $token * @return void */ protected function storeToken($token) { $this->cache->set($this->tokenName, $token); }
/** * @param string $pathAndFilename * @return void * @throws \Exception */ public function optimizeFile($pathAndFilename) { try { $imageType = exif_imagetype($pathAndFilename); $fileExtension = strtolower(pathinfo($pathAndFilename, PATHINFO_EXTENSION)); if ($imageType !== FALSE && !in_array($imageType, [\IMAGETYPE_JPEG, \IMAGETYPE_PNG, \IMAGETYPE_GIF], TRUE) || $imageType === FALSE && $fileExtension !== 'svg') { return; } $pathAndFilename = realpath($pathAndFilename); $cacheIdentifier = md5($pathAndFilename); $lastModificationTime = \DateTime::createFromFormat('U', filemtime($pathAndFilename)); $cachedLastModificationTime = $this->processingCache->get($cacheIdentifier); if ($cachedLastModificationTime instanceof \DateTime && $lastModificationTime->getTimestamp() === $lastModificationTime->getTimestamp()) { return; } $useGlobalBinary = $this->settings['useGlobalBinary']; $binaryRootPath = 'Private/Library/node_modules/'; $file = escapeshellarg($pathAndFilename); if ($imageType !== FALSE) { switch ($imageType) { case \IMAGETYPE_JPEG: if ($this->settings['formats']['jpg']['enabled'] === FALSE) { return; } $library = 'jpegtran'; $binaryPath = sprintf('%1$s-bin/vendor/%s', $library); $arguments = sprintf('-copy none -optimize %s -outfile %s %s', $this->settings['formats']['jpg']['progressive'] === TRUE ? '-progressive' : '', $file, $file); if ($this->settings['formats']['jpg']['useGlobalBinary'] === TRUE) { $useGlobalBinary = TRUE; } break; case \IMAGETYPE_PNG: if ($this->settings['formats']['png']['enabled'] === FALSE) { return; } $library = 'optipng'; $binaryPath = sprintf('%1$s-bin/vendor/%s', $library); $arguments = sprintf('-o%u -strip all -out %s %s', $this->settings['formats']['png']['optimizationLevel'], $file, $file); if ($this->settings['formats']['png']['useGlobalBinary'] === TRUE) { $useGlobalBinary = TRUE; } break; case \IMAGETYPE_GIF: if ($this->settings['formats']['gif']['enabled'] === FALSE) { return; } $library = 'gifsicle'; $binaryPath = sprintf('%1$s/vendor/%1$s', $library); $arguments = sprintf('--batch -O%u %s ', $this->settings['formats']['gif']['optimizationLevel'], $file); if ($this->settings['formats']['gif']['useGlobalBinary'] === TRUE) { $useGlobalBinary = TRUE; } break; } } else { if ($this->settings['formats']['svg']['enabled'] === FALSE) { return; } $library = 'svgo'; $binaryPath = sprintf('%1$s/bin/%1$s', $library); $arguments = sprintf('%s %s', $this->settings['formats']['svg']['pretty'] === TRUE ? '--pretty' : '', $file); if ($this->settings['formats']['svg']['useGlobalBinary'] === TRUE) { $useGlobalBinary = TRUE; } } $binaryPath = $useGlobalBinary === TRUE ? $this->settings['globalBinaryPath'] . $library : $this->packageManager->getPackageOfObject($this)->getResourcesPath() . $binaryRootPath . $binaryPath; $cmd = escapeshellcmd($binaryPath) . ' ' . $arguments; $output = []; exec($cmd, $output, $result); $this->systemLogger->log($cmd . ' (' . ((int) $result === 0 ? 'OK' : 'Error: ' . $result) . ')', LOG_INFO, $output); $lastModificationTime = \DateTime::createFromFormat('U', filemtime($pathAndFilename)); $this->processingCache->set($cacheIdentifier, $lastModificationTime); } catch (\Exception $exception) { $this->systemLogger->logException($exception); } }
/** * @param string $key * @param string $value * @return boolean */ public function set($key, $value) { return $this->cache->set($key, $value); }
/** * Remove existing tokens * * @return void */ public function removeTokens() { $this->cache->remove('AccessToken'); $this->cache->remove('RefreshToken'); }
/** * Constructs the cache * * @param string $identifier A identifier which describes this cache * @param PhpCapableBackendInterface $backend Backend to be used for this cache */ public function __construct($identifier, PhpCapableBackendInterface $backend) { parent::__construct($identifier, $backend); }