/**
  * Saves data in a cache file.
  *
  * @param string $entryIdentifier An identifier for this specific cache entry
  * @param string $data The data to be stored
  * @param array $tags Ignored in this type of cache backend
  * @param integer $lifetime Ignored in this type of cache backend
  * @return void
  * @throws Exception if the directory does not exist or is not writable or exceeds the maximum allowed path length, or if no cache frontend has been set.
  * @throws InvalidDataException
  * @throws \InvalidArgumentException
  * @api
  */
 public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
 {
     if (!is_string($data)) {
         throw new InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1334756734);
     }
     if ($entryIdentifier !== basename($entryIdentifier)) {
         throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1334756735);
     }
     if ($entryIdentifier === '') {
         throw new \InvalidArgumentException('The specified entry identifier must not be empty.', 1334756736);
     }
     $cacheEntryPathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
     $result = $this->writeCacheFile($cacheEntryPathAndFilename, $data);
     if ($result !== false) {
         if ($this->cacheEntryFileExtension === '.php') {
             OpcodeCacheHelper::clearAllActive($cacheEntryPathAndFilename);
         }
         return;
     }
     $this->throwExceptionIfPathExceedsMaximumLength($cacheEntryPathAndFilename);
     throw new Exception('The cache file "' . $cacheEntryPathAndFilename . '" could not be written.', 1334756737);
 }
 /**
  * Saves the current configuration into a cache file and creates a cache inclusion script
  * in the context's Configuration directory.
  *
  * @return void
  * @throws Exception
  */
 protected function saveConfigurationCache()
 {
     // Make sure that all configuration types are loaded before writing configuration caches.
     foreach (array_keys($this->configurationTypes) as $configurationType) {
         $this->getConfiguration($configurationType);
     }
     if ($this->temporaryDirectoryPath === null) {
         return;
     }
     $cachePathAndFilename = $this->constructConfigurationCachePath();
     if (!file_exists(dirname($cachePathAndFilename))) {
         Files::createDirectoryRecursively(dirname($cachePathAndFilename));
     }
     file_put_contents($cachePathAndFilename, '<?php return ' . var_export($this->configurations, true) . ';');
     OpcodeCacheHelper::clearAllActive($cachePathAndFilename);
 }
 /**
  * Runs the compile step if necessary
  *
  * @param Bootstrap $bootstrap
  * @return void
  * @throws FlowException
  */
 public static function initializeProxyClasses(Bootstrap $bootstrap)
 {
     $objectConfigurationCache = $bootstrap->getEarlyInstance(CacheManager::class)->getCache('Flow_Object_Configuration');
     $configurationManager = $bootstrap->getEarlyInstance(ConfigurationManager::class);
     $settings = $configurationManager->getConfiguration(ConfigurationManager::CONFIGURATION_TYPE_SETTINGS, 'Neos.Flow');
     // The compile sub command will only be run if the code cache is completely empty:
     if ($objectConfigurationCache->has('allCompiledCodeUpToDate') === false) {
         OpcodeCacheHelper::clearAllActive(FLOW_PATH_CONFIGURATION);
         OpcodeCacheHelper::clearAllActive(FLOW_PATH_DATA);
         self::executeCommand('neos.flow:core:compile', $settings);
         if (isset($settings['persistence']['doctrine']['enable']) && $settings['persistence']['doctrine']['enable'] === true) {
             self::compileDoctrineProxies($bootstrap);
         }
         // As the available proxy classes were already loaded earlier we need to refresh them if the proxies where recompiled.
         $classLoader = $bootstrap->getEarlyInstance(ClassLoader::class);
         $classLoader->initializeAvailableProxyClasses($bootstrap->getContext());
     }
     // Check if code was updated, if not something went wrong
     if ($objectConfigurationCache->has('allCompiledCodeUpToDate') === false) {
         if (DIRECTORY_SEPARATOR === '/') {
             $phpBinaryPathAndFilename = '"' . escapeshellcmd(Files::getUnixStylePath($settings['core']['phpBinaryPathAndFilename'])) . '"';
         } else {
             $phpBinaryPathAndFilename = escapeshellarg(Files::getUnixStylePath($settings['core']['phpBinaryPathAndFilename']));
         }
         $command = sprintf('%s -c %s -v', $phpBinaryPathAndFilename, escapeshellarg(php_ini_loaded_file()));
         exec($command, $output, $result);
         if ($result !== 0) {
             if (!file_exists($phpBinaryPathAndFilename)) {
                 throw new FlowException(sprintf('It seems like the PHP binary "%s" cannot be executed by Flow. Set the correct path to the PHP executable in Configuration/Settings.yaml, setting Neos.Flow.core.phpBinaryPathAndFilename.', $settings['core']['phpBinaryPathAndFilename']), 1315561483);
             }
             throw new FlowException(sprintf('It seems like the PHP binary "%s" cannot be executed by Flow. The command executed was "%s" and returned the following: %s', $settings['core']['phpBinaryPathAndFilename'], $command, PHP_EOL . implode(PHP_EOL, $output)), 1354704332);
         }
         echo PHP_EOL . 'Flow: The compile run failed. Please check the error output or system log for more information.' . PHP_EOL;
         exit(1);
     }
 }
 /**
  * Saves data in a cache file.
  *
  * @param string $entryIdentifier An identifier for this specific cache entry
  * @param string $data The data to be stored
  * @param array $tags Tags to associate with this cache entry
  * @param integer $lifetime Lifetime of this cache entry in seconds. If NULL is specified, the default lifetime is used. "0" means unlimited lifetime.
  * @return void
  * @throws \RuntimeException
  * @throws InvalidDataException
  * @throws Exception if the directory does not exist or is not writable or exceeds the maximum allowed path length, or if no cache frontend has been set.
  * @throws \InvalidArgumentException
  * @api
  */
 public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
 {
     if (!is_string($data)) {
         throw new InvalidDataException('The specified data is of type "' . gettype($data) . '" but a string is expected.', 1204481674);
     }
     if ($entryIdentifier !== basename($entryIdentifier)) {
         throw new \InvalidArgumentException('The specified entry identifier must not contain a path segment.', 1282073032);
     }
     if ($entryIdentifier === '') {
         throw new \InvalidArgumentException('The specified entry identifier must not be empty.', 1298114280);
     }
     if ($this->frozen === true) {
         throw new \RuntimeException(sprintf('Cannot add or modify cache entry because the backend of cache "%s" is frozen.', $this->cacheIdentifier), 1323344192);
     }
     $cacheEntryPathAndFilename = $this->cacheDirectory . $entryIdentifier . $this->cacheEntryFileExtension;
     $lifetime = $lifetime === null ? $this->defaultLifetime : $lifetime;
     $expiryTime = $lifetime === 0 ? 0 : time() + $lifetime;
     $metaData = str_pad($expiryTime, self::EXPIRYTIME_LENGTH) . implode(' ', $tags) . str_pad(strlen($data), self::DATASIZE_DIGITS);
     $result = $this->writeCacheFile($cacheEntryPathAndFilename, $data . $metaData);
     if ($result !== false) {
         if ($this->cacheEntryFileExtension === '.php') {
             OpcodeCacheHelper::clearAllActive($cacheEntryPathAndFilename);
         }
         return;
     }
     $this->throwExceptionIfPathExceedsMaximumLength($cacheEntryPathAndFilename);
     throw new Exception('The cache file "' . $cacheEntryPathAndFilename . '" could not be written.', 1222361632);
 }
示例#5
0
 /**
  * Saves the current configuration into a cache file and creates a cache inclusion script
  * in the context's Configuration directory.
  *
  * @return void
  * @throws Exception
  */
 protected function saveConfigurationCache()
 {
     // Make sure that all configuration types are loaded before writing configuration caches.
     foreach (array_keys($this->configurationTypes) as $configurationType) {
         if (!isset($this->configurations[$configurationType]) || !is_array($this->configurations[$configurationType])) {
             $this->loadConfiguration($configurationType, $this->packages);
         }
     }
     if ($this->temporaryDirectoryPath === null) {
         return;
     }
     $cachePathAndFilename = $this->constructConfigurationCachePath();
     if (!file_exists(dirname($cachePathAndFilename))) {
         Files::createDirectoryRecursively(dirname($cachePathAndFilename));
     }
     file_put_contents($cachePathAndFilename, '<?php return ' . $this->replaceVariablesInPhpString(var_export($this->unprocessedConfiguration, true)) . ';');
     OpcodeCacheHelper::clearAllActive($cachePathAndFilename);
     $this->cacheNeedsUpdate = false;
 }
 /**
  * Save the given (ordered) array of package states data
  *
  * @param array $orderedPackageStates
  * @throws Exception\PackageStatesFileNotWritableException
  */
 protected function savePackageStates(array $orderedPackageStates)
 {
     $orderedPackageStates['version'] = static::PACKAGESTATE_FORMAT_VERSION;
     $fileDescription = "# PackageStates.php\n\n";
     $fileDescription .= "# This file is maintained by Flow's package management. You shouldn't edit it manually\n";
     $fileDescription .= "# manually, you should rather use the command line commands for maintaining packages.\n";
     $fileDescription .= "# You'll find detailed information about the neos.flow:package:* commands in their\n";
     $fileDescription .= "# respective help screens.\n\n";
     $fileDescription .= "# This file will be regenerated automatically if it doesn't exist. Deleting this file\n";
     $fileDescription .= "# should, however, never become necessary if you use the package commands.\n";
     $packageStatesCode = "<?php\n" . $fileDescription . "\nreturn " . var_export($orderedPackageStates, true) . ';';
     $result = @file_put_contents($this->packageStatesPathAndFilename, $packageStatesCode);
     if ($result === false) {
         throw new Exception\PackageStatesFileNotWritableException(sprintf('Flow could not update the list of installed packages because the file %s is not writable. Please, check the file system permissions and make sure that the web server can write to it.', $this->packageStatesPathAndFilename), 1382449759);
     }
     OpcodeCacheHelper::clearAllActive($this->packageStatesPathAndFilename);
     $this->emitPackageStatesUpdated();
 }