* * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. */ /** * sfCacheConfigHandler allows you to configure cache. * * @package symfony * @subpackage config * @author Fabien Potencier * @version SVN: $Id: sfCacheConfigHandler.class.php 3203 2007-01-09 18:32:54Z fabien $ */ class sfCacheConfigHandler extends sfYamlConfigHandler { protected $cacheConfig = array(); /** * Executes this configuration handler. * * @param array An array of absolute filesystem path to a configuration file * * @return string Data to be written to a cache file * * @throws sfConfigurationException If a requested configuration file does not exist or is not readable * @throws sfParseException If a requested configuration file is improperly formatted * @throws sfInitializationException If a cache.yml key check fails */ public function execute($configFiles) { // set our required categories list and initialize our handler $categories = array('required_categories' => array()); $this->initialize($categories); // parse the yaml $myConfig = $this->parseYamls($configFiles); $myConfig['all'] = sfToolkit::arrayDeepMerge( isset($myConfig['default']) && is_array($myConfig['default']) ? $myConfig['default'] : array(), isset($myConfig['all']) && is_array($myConfig['all']) ? $myConfig['all'] : array() ); unset($myConfig['default']); $this->yamlConfig = $myConfig; // iterate through all action names $data = array(); $first = true; foreach ($this->yamlConfig as $actionName => $values) { if ($actionName == 'all') { continue; } $data[] = $this->addCache($actionName); $first = false; } // general cache configuration $data[] = $this->addCache('DEFAULT'); // compile data $retval = sprintf("getConfigValue('enabled', $actionName); // cache with or without loayout $withLayout = $this->getConfigValue('with_layout', $actionName) ? 'true' : 'false'; // lifetime $lifeTime = !$enabled ? '0' : $this->getConfigValue('lifetime', $actionName, '0'); // client_lifetime $clientLifetime = !$enabled ? '0' : $this->getConfigValue('client_lifetime', $actionName, $lifeTime, '0'); // contextual $contextual = $this->getConfigValue('contextual', $actionName) ? 'true' : 'false'; // vary $vary = $this->getConfigValue('vary', $actionName, array()); if (!is_array($vary)) { $vary = array($vary); } // add cache information to cache manager $data[] = sprintf("\$this->addCache(\$moduleName, '%s', array('withLayout' => %s, 'lifeTime' => %s, 'clientLifeTime' => %s, 'contextual' => %s, 'vary' => %s));\n", $actionName, $withLayout, $lifeTime, $clientLifetime, $contextual, str_replace("\n", '', var_export($vary, true))); return implode("\n", $data); } }