/**
  * 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();
 }
 /**
  * Stores the $uriPath in the cache together with the $routeValues
  *
  * @param string $uriPath
  * @param array $routeValues
  * @return void
  */
 public function storeResolvedUriPath($uriPath, array $routeValues)
 {
     $routeValues = $this->convertObjectsToHashes($routeValues);
     if ($routeValues === NULL) {
         return;
     }
     $cacheIdentifier = $this->buildResolveCacheIdentifier($routeValues);
     if ($cacheIdentifier !== NULL) {
         $this->resolveCache->set($cacheIdentifier, $uriPath, $this->extractUuids($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));
     }
 }
 /**
  * Stores the $uriPath in the cache together with the $routeValues
  *
  * @param string $uriPath
  * @param array $routeValues
  * @return void
  */
 public function storeResolvedUriPath($uriPath, array $routeValues)
 {
     $uriPath = trim($uriPath, '/');
     $routeValues = $this->convertObjectsToHashes($routeValues);
     if ($routeValues === null) {
         return;
     }
     $cacheIdentifier = $this->buildResolveCacheIdentifier($routeValues);
     if ($cacheIdentifier !== null) {
         $tags = $this->generateRouteTags($uriPath, $routeValues);
         $this->resolveCache->set($cacheIdentifier, $uriPath, $tags);
     }
 }
 /**
  * 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);
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * Takes a string of content which includes cache segment markers, extracts the marked segments, writes those
  * segments which can be cached to the actual cache and returns the cleaned up original content without markers.
  *
  * This method is called by the TypoScript Runtime while rendering a TypoScript object.
  *
  * @param string $content The content with an outer cache segment
  * @param boolean $storeCacheEntries Whether to store extracted cache segments in the cache
  * @return string The (pure) content without cache segment markers
  */
 public function processCacheSegments($content, $storeCacheEntries = true)
 {
     $this->parser->extractRenderedSegments($content);
     if ($storeCacheEntries) {
         $segments = $this->parser->getCacheSegments();
         foreach ($segments as $segment) {
             $metadata = explode(';', $segment['metadata']);
             $tagsValue = $metadata[0] === '' ? array() : ($metadata[0] === '*' ? false : explode(',', $metadata[0]));
             // FALSE means we do not need to store the cache entry again (because it was previously fetched)
             if ($tagsValue !== false) {
                 $lifetime = isset($metadata[1]) ? (int) $metadata[1] : null;
                 $this->cache->set($segment['identifier'], $segment['content'], $this->sanitizeTags($tagsValue), $lifetime);
             }
         }
     }
     return $this->parser->getOutput();
 }
 /**
  * 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));
     }
 }
 /**
  * Set a cache entry and store additional metadata (tags and lifetime)
  *
  * {@inheritdoc}
  */
 public function set($entryIdentifier, $content, array $tags = array(), $lifetime = NULL)
 {
     $content = $this->insertMetadata($content, $entryIdentifier, $tags, $lifetime);
     parent::set($entryIdentifier, $content, $tags, $lifetime);
 }
 /**
  * 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);
 }
 /**
  * Updates the cache breaking string
  */
 public function update()
 {
     $this->storage->set(self::STORAGE_KEY, md5(time()));
 }
 /**
  * @param string $key
  * @param string $value
  * @return boolean
  */
 public function set($key, $value)
 {
     return $this->cache->set($key, $value);
 }
 /**
  * @param string $refreshToken
  * @return void
  */
 public function storeRefreshToken($refreshToken)
 {
     $this->cache->set('RefreshToken', $refreshToken);
 }
 /**
  * @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);
     }
 }