示例#1
0
    public function writeCache($config, $namespace, $environment = TPV_MODE, $force = false)
    {
        if (!$force && !$this->_useWriteCache($environment)) {
            return false;
        }
        $key = $this->_getCacheKey($namespace, $environment);
        Ak::setStaticVar($key, $config);
        $var_export = var_export($config, true);
        $cache = <<<CACHE
<?php
/**
 * Auto-generated config cache from {$namespace} in environment {$environment}
 */
\$config = {$var_export};
return \$config;

CACHE;
        $cache_file_name = $this->getCacheFileName($namespace, $environment);
        if (!Ak::file_put_contents($cache_file_name, $cache, array('base_path' => AkConfig::getCacheBasePath()))) {
            trigger_error(Ak::t('Could not create config cache file %file', array('%file' => $cache_file_name)) . ' ' . Ak::getFileAndNumberTextForError(1), E_USER_ERROR);
            return false;
        } else {
            return true;
        }
    }