Provider that creates config from environment variables.

@param $cacheLimit
@return callable
769975
public static function env($cacheLimit = self::DEFAULT_CACHE_LIMIT)
    {
        return function () use ($cacheLimit) {
            // Use config from environment variables, if available
            $enabled = getenv(self::ENV_ENABLED);
            if ($enabled === false || $enabled === '') {
                $enabled = getenv(self::ENV_ENABLED_ALT);
            }
            if ($enabled !== false && $enabled !== '') {
                return Promise\promise_for(
                    new Configuration($enabled, $cacheLimit)
                );
            }

            return self::reject('Could not find environment variable config'
                . ' in ' . self::ENV_ENABLED);
        };
    }
63184
private function configCache(): ConfigCache
    {
        if (null === $this->configCache)
        {
            $this->configCache = new ConfigCache($this->getContainerClassPath(), $this->environment->isDebug());
        }

        return $this->configCache;
    }
15933
public function addCache(CacheItemPoolInterface $cachePool, array $config = [])
    {
        $this->setCachePlugin($cachePool, $config['generator'] ?? null, $config['lifetime'] ?? null);

        $this->setPropertyValue('httpClientModified', true);
    }
531503
private String buildConfiguration(Object cache) {
		final StringBuilder sb = new StringBuilder();
		// getCacheConfiguration() et getMaxElementsOnDisk() n'existent pas en ehcache 1.2
		final CacheConfiguration config = ((Ehcache) cache).getCacheConfiguration();
		sb.append("ehcache [maxElementsInMemory = ").append(config.getMaxElementsInMemory());
		final boolean overflowToDisk = config.isOverflowToDisk();
		sb.append(", overflowToDisk = ").append(overflowToDisk);
		if (overflowToDisk) {
			sb.append(", maxElementsOnDisk = ").append(config.getMaxElementsOnDisk());
		}
		final boolean eternal = config.isEternal();
		sb.append(", eternal = ").append(eternal);
		if (!eternal) {
			sb.append(", timeToLiveSeconds = ").append(config.getTimeToLiveSeconds());
			sb.append(", timeToIdleSeconds = ").append(config.getTimeToIdleSeconds());
			sb.append(", memoryStoreEvictionPolicy = ")
					.append(config.getMemoryStoreEvictionPolicy());
		}
		sb.append(", diskPersistent = ").append(config.isDiskPersistent());
		sb.append(']');
		return sb.toString();
	}
1018981
public static function simple(array $config = []): CacheInterface
    {
        [$hash, $config] = static::getKey($config, 'cache.simple');

        if (isset(static::$pool[$hash])) {
            return static::$pool[$hash];
        }

        if (isset($config['drivers'])) {
            $drivers = $config['drivers'];
            if (\count($drivers) > 1) {
                return static::$pool[$hash] = new Chain($config);
            }

            unset($config['drivers']);

            $driver = \key($drivers);
            $config += $drivers[$driver];
        } else {
            $driver = $config['driver'] ?? 'void';
            unset($config['driver']);
        }

        switch ($driver) {
            case 'array':
            case 'zend':
                $driver = \ucfirst($driver) . 'Data';
                break;
            case 'apc':
                $driver = 'Apcu';
                break;
            default:
                $driver = \ucfirst($driver);
        }

        $class = 'Hail\\Cache\\Simple\\' . $driver;

        return static::$pool[$hash] = new $class($config);
    }
225955
protected function getExtensionConfiguration()
    {
        $cacheInstance = CacheService::get()->getCacheInstance();
        $hash = $this->getContextHash();

        if ($cacheInstance->has($hash)) {
            $result = $cacheInstance->get($hash);
        } else {
            $result = $this->getFullConfiguration();
            $result = (ArrayUtility::isValidPath($result, self::EXTENSION_CONFIGURATION_PATH, '.'))
                ? ArrayUtility::getValueByPath($result, self::EXTENSION_CONFIGURATION_PATH, '.')
                : [];

            if (ArrayUtility::isValidPath($result, 'settings.typoScriptIncluded', '.')) {
                $cacheInstance->set($hash, $result);
            }
        }

        return $result;
    }
639695
public function setRetryLimit($retryLimit = null)
    {
        if (! is_numeric($retryLimit) && ! is_null($retryLimit)) {
            throw new InvalidArgumentException('Retry limit must be a number or null.');
        }

        if (is_string($retryLimit)) {
            $retryLimit = (int) $retryLimit;
        }

        $this->retryLimit = $retryLimit;

        return $this;
    }
533791
function createOverrideCache()
    {
        if ( isset( $GLOBALS['eZSiteBasics'] ) )
        {
            if ( isset( $GLOBALS['eZSiteBasics']['no-cache-adviced'] ) and
                 $GLOBALS['eZSiteBasics']['no-cache-adviced'] )
                return false;
        }
        global $eZTemplateOverrideCacheNoPermission;
        if ( $eZTemplateOverrideCacheNoPermission == "nocache" )
        {
            return false;
        }

        $ini = eZINI::instance( 'site.ini' );
        $useOverrideCache = true;
        if ( $ini->hasVariable( 'OverrideSettings', 'Cache' ) )
            $useOverrideCache = $ini->variable( 'OverrideSettings', 'Cache' ) == 'enabled';

        $standardBase = eZTemplateDesignResource::designSetting( 'standard' );
        $siteBase = eZTemplateDesignResource::designSetting( 'site' );

        $overrideKeys = $this->overrideKeys();

        $overrideKey = md5( implode( ',', $overrideKeys ) . $siteBase . $standardBase );
        $cacheDir = eZSys::cacheDirectory();

        $overrideCacheFile = $cacheDir.'/override/override_'.$overrideKey.'.php';

        // Build matching cache only of it does not already exists,
        // or override file has been updated
        if ( !$useOverrideCache or
             !file_exists( $overrideCacheFile ) )
        {
            $matchFileArray = eZTemplateDesignResource::overrideArray( $this->OverrideSiteAccess );

            // Generate PHP compiled cache file.
            $phpCache = new eZPHPCreator( "$cacheDir/override", "override_$overrideKey.php" );

            $phpCode = "\$GLOBALS['eZOverrideTemplateCacheMap'] = array (\n";
            $numMatchFiles = count ( $matchFileArray );
            $countMatchFiles = 0;
//            $phpCode .= "switch ( \$matchFile )\n{\n    ";
            foreach ( array_keys( $matchFileArray ) as $matchKey )
            {
                $countMatchFiles++;
                $phpCode .= '\'' . md5( $matchKey ) . '\' => ';
                if ( isset( $matchFileArray[$matchKey]['custom_match'] ) )
                {
                    $baseDir = isset( $matchFileArray[$matchKey]['base_dir'] ) ? $matchFileArray[$matchKey]['base_dir'] : '';
                    $defaultMatchFile = $baseDir . $matchKey;
                    // Custom override matching
//                    $phpCode .= "    case  \"$matchKey\":\n    {\n";

                    $matchConditionArray = array();
                    foreach ( $matchFileArray[$matchKey]['custom_match'] as $customMatch )
                    {
                        $matchCondition = "";
                        $condCount = 0;
                        if ( is_array( $customMatch['conditions'] ) )
                        {
                            foreach ( array_keys( $customMatch['conditions'] ) as $conditionKey )
                            {
                                if ( $condCount > 0 )
                                    $matchCondition .= " and ";

                                // Have a special substring match for subtree matching

                                $matchCondition .= "( isset( \$matchKeys[\\'$conditionKey\\'] ) and ";
                                if ( $conditionKey == 'url_alias' )
                                {
                                    $matchCondition .=
                                        "( strpos( \$matchKeys[\\'url_alias\\'],  \\'" . $customMatch['conditions']['url_alias'] . "\\' ) === 0 ) )";
                                }
                                else
                                {
                                    $matchCondition .=
                                        "( is_array( \$matchKeys[\\'$conditionKey\\'] ) ? " .
                                        "in_array( \\'" . $customMatch['conditions'][$conditionKey] . "\\', \$matchKeys[\\'$conditionKey\\'] ) : " .
                                        "\$matchKeys[\\'$conditionKey\\'] == \\'" . $customMatch['conditions'][$conditionKey] . "\\') )";
                                }

                                $condCount++;
                            }
                        }

                        // Only create custom match if conditions are defined
                        if ( $matchCondition != "" )
                        {
//                            $phpCode .= "        if ( $matchCondition )\n        {\n";
//                            $phpCode .= "            return '" . $customMatch['match_file'] . "';\n        }\n";
                            if ( $condCount > 1 )
                                $matchConditionArray[] = array( 'condition' => '(' . $matchCondition . ')',
                                                                'matchFile' => $customMatch['match_file'] );
                            else
                                $matchConditionArray[] = array( 'condition' => $matchCondition,
                                                                'matchFile' => $customMatch['match_file'] );
                        }
                        else
                        {
                            // No override conditions defined. Override default match file
                            $defaultMatchFile = $customMatch['match_file'];
                        }
                    }

                    $phpCode .= "array ( 'eval' => 1, 'code' => ";

                    $phpCode .= "'";

                    foreach ( array_keys( $matchConditionArray ) as $key )
                    {
                        $phpCode .= '(' . $matchConditionArray[$key]['condition'] . ' ? ' . "\\'" .  $matchConditionArray[$key]['matchFile'] . "\\'" . ' : ';
                    }

                    $phpCode .= "\\'" . $defaultMatchFile . "\\'";

                    for ( $condCount = 0; $condCount < count( $matchConditionArray ); $condCount++)
                    {
                        $phpCode .= ')';
                    }

                    $phpCode .= "' )";
                }
                else
                {
                    $phpCode .= "'". $matchFileArray[$matchKey]['base_dir'] . $matchKey . "'";
                }

                if ( $countMatchFiles < $numMatchFiles )
                {
                    $phpCode .= ",\n";
                }
                else
                {
                    $phpCode .= ");\n";
                }
            }

            $phpCache->addCodePiece( $phpCode );
            if ( $useOverrideCache and
                 $phpCache->store() )
            {

            }
            else
            {
                if ( $useOverrideCache )
                {
                    eZDebug::writeError( "Could not write template override cache file, check permissions in $cacheDir/override/.\nRunning eZ Publish without this cache will have a performance impact.", __METHOD__ );
                }
                $eZTemplateOverrideCacheNoPermission = 'nocache';
                $overrideCacheFile = false;
            }
        }

        return $overrideCacheFile;
    }
1300250
public static function create($config = null)
    {
        if ($config === null) {
            return self::getStandard();
        }
        if (is_array($config) || ($config instanceof Config)) {
            return new Env($config);
        }
        if ($config instanceof Env) {
            return $config;
        }
        $message = 'Factory accepts Env, Config, array or NULL';
        throw new InvalidConfig('Env', $message, 0, null, __NAMESPACE__);
    }
385874
public function setPreFlightCacheMaxAge(int $cacheMaxAge): self
    {
        \assert($cacheMaxAge >= 0);

        $this->preFlightCacheMaxAge   = $cacheMaxAge;
        $this->isPreFlightCanBeCached = $cacheMaxAge > 0;

        return $this;
    }
1300362
public static CacheConfiguration build(ConfigMap<String, String> cacheConfigMap) {

		if (cacheConfigMap == null || cacheConfigMap.size() == 0) {
			return new SynchronizedCacheConfiguration();
		}
		if ("ENABLE".equals(cacheConfigMap.getString("cache", "ENABLE").toUpperCase())) {
			
			String cacheAdapter = cacheConfigMap.getString("cache.adapter", "SYN").toUpperCase();
			
			if (cacheAdapter.equals("SYN")) {
				return new SynchronizedCacheConfiguration(cacheConfigMap);
			} else if (cacheAdapter.equals("EHCACHE")) {
				return new EhCacheConfiguration(cacheConfigMap);
			} else if (cacheAdapter.equals("MEMCACHED")) {
				return new MemcachedCacheConfiguration(cacheConfigMap);
			}
		}
		return null;
	}
1185512
protected function setUpSpecificConfigurations(Configuration $config)
    {
        $config->setQueryCacheImpl($this->getQueryCacheDriver());
        $config->setResultCacheImpl($this->getResultCacheDriver());
        $config->setHydrationCacheImpl($this->getHydratorCacheDriver());

        $config->setNamingStrategy($this->getNamingStrategy());
        $config->setQuoteStrategy($this->getQuoteStrategy());

        if ($this->getSecondLevelCacheConfiguration() !== null) {
            $config->setSecondLevelCacheEnabled(true);
            $config->setSecondLevelCacheConfiguration($this->getSecondLevelCacheConfiguration());
        }

        $config->setSQLLogger($this->getSQLLogger());
        $config->setCustomStringFunctions($this->getCustomStringFunctions());
        $config->setCustomNumericFunctions($this->getCustomNumericFunctions());
        $config->setCustomDatetimeFunctions($this->getCustomDateTimeFunctions());

        foreach ($this->getCustomFilters() as $name => $filterClass) {
            $config->addFilter($name, $filterClass);
        }
    }
721669
private function init()
    {
        if (!is_dir($this->options['path'])) {
            if (mkdir($this->options['path'], 0755, true) && chmod($this->options['path'], 0755)) {
                return true;
            }
        }

        if (!is_writeable($this->options['path'])) {
            throw new CacheException('Cache Path: '.$this->options['path'].' is not writable');
        }

        return false;
    }
205492
protected function _setupCacheProvider()
	{
		//  If something should be cached
		if ($this->isSettingSet(self::SET_CACHE_PROVIDER) == false
			|| ($this->getSetting(self::SET_CACHE_PROVIDER) == self::CACHE_PROVIDER_FILE && $this->isSettingSet(self::SET_CACHE_PROVIDER_PARAMS) == false))
		{
			//  Set default cache provider if not already set
			$this->setSettings([
				self::SET_CACHE_PROVIDER        => self::CACHE_PROVIDER_FILE,
				self::SET_CACHE_PROVIDER_PARAMS => [
					__DIR__ . DIRECTORY_SEPARATOR . 'cache' . DIRECTORY_SEPARATOR,
				],
			]);
		}

		try
		{
			//  Creates reflection of specified cache provider (can be user-made)
			$cacheProvider = new \ReflectionClass($this->getSetting(self::SET_CACHE_PROVIDER));
			//  Checks if this cache provider implements required interface
			if ($cacheProvider->implementsInterface(ICacheProvider::class) == false)
				throw new SettingsException("Provided CacheProvider does not implement ICacheProvider interface.");

			//  Gets default parameters
			$params = $this->getSetting(self::SET_CACHE_PROVIDER_PARAMS, []);
			//  and creates new instance of this cache provider
			$this->cache = $cacheProvider->newInstanceArgs($params);
		}
		catch (\ReflectionException $ex)
		{
			//  probably problem when instantiating the class
			throw new SettingsException("Failed to initialize CacheProvider class: " . $ex->getMessage() . ".", 0, $ex);
		}
		catch (\Exception $ex)
		{
			//  something went wrong when initializing the class - invalid settings, etc.
			throw new SettingsException("CacheProvider class failed to be initialized: " . $ex->getMessage() . ".", 0, $ex);
		}

		//  Loads existing cache or creates new storages
		$this->loadCache();
	}
1340897
public function buildTwigEnvironmentOptions(TwigConfig $config) {
        $options = [
            'debug' => $config->getDebug(),
        ];

        if ($config->getCharset() !== null) {
            $options['charset'] = $config->getCharset();
        }

        if ($config->getBaseTemplateClass() !== null) {
            $options['base_template_class'] = $config->getBaseTemplateClass();
        }

        if ($config->getCache() !== null) {
            $options['cache'] = $config->getCache();
        }

        if ($config->getAutoReload() !== null) {
            $options['auto_reload'] = $config->getAutoReload();
        }

        if ($config->getAutoEscape() !== null) {
            $options['autoescape'] = $config->getAutoEscape();
        }

        if ($config->getStrictVariables() !== null) {
            $options['strict_variables'] = $config->getStrictVariables();
        }

        if ($config->getOptimizations() !== null) {
            $options['optimizations'] = $config->getOptimizations();
        }

        return $options;
    }
990340
private function getConfigCacheFactory(): ConfigCacheFactoryInterface
    {
        if (!$this->configCacheFactory) {
            $this->configCacheFactory = new ConfigCacheFactory($this->debug);
        }

        return $this->configCacheFactory;
    }
500616
public function create(): ConfigurationInterface
    {
        $config = $this->detectConfig();
        $config->set('env', $this->environment);

        return $config;
    }