/**
  * 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 typo3.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();
 }
 /**
  * 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 \TYPO3\Flow\Cache\Exception\InvalidDataException
  * @throws \TYPO3\Flow\Cache\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 = array(), $lifetime = NULL)
 {
     if (!is_string($data)) {
         throw new \TYPO3\Flow\Cache\Exception\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);
     $lock = new Lock($cacheEntryPathAndFilename);
     $result = file_put_contents($cacheEntryPathAndFilename, $data . $metaData);
     $lock->release();
     if ($result === FALSE) {
         throw new \TYPO3\Flow\Cache\Exception('The cache file "' . $cacheEntryPathAndFilename . '" could not be written.', 1222361632);
     }
     if ($this->cacheEntryFileExtension === '.php') {
         OpcodeCacheHelper::clearAllActive($cacheEntryPathAndFilename);
     }
 }
 /**
  * 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 \TYPO3\Flow\Cache\Exception\InvalidDataException
  * @throws \InvalidArgumentException
  * @api
  */
 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = null)
 {
     if (!is_string($data)) {
         throw new \TYPO3\Flow\Cache\Exception\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()
    {
        $configurationCachePath = $this->environment->getPathToTemporaryDirectory() . 'Configuration/';
        if (!file_exists($configurationCachePath)) {
            Files::createDirectoryRecursively($configurationCachePath);
        }
        $cachePathAndFilename = $configurationCachePath . str_replace('/', '_', (string) $this->context) . 'Configurations.php';
        $flowRootPath = FLOW_PATH_ROOT;
        $includeCachedConfigurationsCode = <<<EOD
<?php
if (FLOW_PATH_ROOT !== '{$flowRootPath}' || !file_exists('{$cachePathAndFilename}')) {
\tunlink(__FILE__);
\treturn array();
}
return require '{$cachePathAndFilename}';
EOD;
        file_put_contents($cachePathAndFilename, '<?php return ' . var_export($this->configurations, true) . ';');
        OpcodeCacheHelper::clearAllActive($cachePathAndFilename);
        if (!is_dir(dirname($this->includeCachedConfigurationsPathAndFilename)) && !is_link(dirname($this->includeCachedConfigurationsPathAndFilename))) {
            Files::createDirectoryRecursively(dirname($this->includeCachedConfigurationsPathAndFilename));
        }
        file_put_contents($this->includeCachedConfigurationsPathAndFilename, $includeCachedConfigurationsCode);
        if (!is_file($this->includeCachedConfigurationsPathAndFilename)) {
            throw new Exception(sprintf('Could not write configuration cache file "%s". Check file permissions for the parent directory.', $this->includeCachedConfigurationsPathAndFilename), 1323339284);
        }
        OpcodeCacheHelper::clearAllActive($this->includeCachedConfigurationsPathAndFilename);
    }
 /**
  * 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);
 }
 /**
  * Saves the current content of $this->packageStatesConfiguration to the
  * PackageStates.php file.
  *
  * @return void
  * @throws Exception\PackageStatesFileNotWritableException
  */
 protected function sortAndSavePackageStates()
 {
     $this->sortAvailablePackagesByDependencies();
     $this->packageStatesConfiguration['version'] = 4;
     $fileDescription = "# PackageStates.php\n\n";
     $fileDescription .= "# This file is maintained by Flow's package management. Although you can edit it\n";
     $fileDescription .= "# manually, you should rather use the command line commands for maintaining packages.\n";
     $fileDescription .= "# You'll find detailed information about the typo3.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($this->packageStatesConfiguration, 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();
 }
 /**
  * Runs the compile step if necessary
  *
  * @param Bootstrap $bootstrap
  * @return void
  * @throws \TYPO3\Flow\Exception
  */
 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, 'TYPO3.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('typo3.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('TYPO3\\Flow\\Core\\ClassLoader');
         $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 \TYPO3\Flow\Exception(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 TYPO3.Flow.core.phpBinaryPathAndFilename.', $settings['core']['phpBinaryPathAndFilename']), 1315561483);
             }
             throw new \TYPO3\Flow\Exception(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 Ignored in this type of cache backend
  * @param integer $lifetime Ignored in this type of cache backend
  * @return void
  * @throws \TYPO3\Flow\Cache\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 \TYPO3\Flow\Cache\Exception\InvalidDataException
  * @throws \InvalidArgumentException
  * @api
  */
 public function set($entryIdentifier, $data, array $tags = array(), $lifetime = NULL)
 {
     if (!is_string($data)) {
         throw new \TYPO3\Flow\Cache\Exception\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;
     $lock = new Lock($cacheEntryPathAndFilename);
     $result = file_put_contents($cacheEntryPathAndFilename, $data);
     $lock->release();
     if ($result === FALSE) {
         throw new \TYPO3\Flow\Cache\Exception('The cache file "' . $cacheEntryPathAndFilename . '" could not be written.', 1334756737);
     }
     if ($this->cacheEntryFileExtension === '.php') {
         OpcodeCacheHelper::clearAllActive($cacheEntryPathAndFilename);
     }
 }