123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115 |
- <?php
- class sfCacheConfigHandler extends sfYamlConfigHandler
- {
- protected
- $cacheConfig = array();
-
- public function execute($configFiles)
- {
-
- $this->yamlConfig = self::getConfiguration($configFiles);
-
- $data = array();
- $first = true;
- foreach ($this->yamlConfig as $actionName => $values)
- {
- if ($actionName == 'all')
- {
- continue;
- }
- $data[] = $this->addCache($actionName);
- $first = false;
- }
-
- $data[] = $this->addCache('DEFAULT');
-
- $retval = sprintf("<?php\n".
- "// auto-generated by sfCacheConfigHandler\n".
- "// date: %s\n%s\n",
- date('Y/m/d H:i:s'), implode('', $data));
- return $retval;
- }
-
- protected function addCache($actionName = '')
- {
- $data = array();
-
- $enabled = $this->getConfigValue('enabled', $actionName);
-
- $withLayout = $this->getConfigValue('with_layout', $actionName) ? 'true' : 'false';
-
- $lifeTime = !$enabled ? '0' : $this->getConfigValue('lifetime', $actionName, '0');
-
- $clientLifetime = !$enabled ? '0' : $this->getConfigValue('client_lifetime', $actionName, $lifeTime, '0');
-
- $contextual = $this->getConfigValue('contextual', $actionName) ? 'true' : 'false';
-
- $vary = $this->getConfigValue('vary', $actionName, array());
- if (!is_array($vary))
- {
- $vary = array($vary);
- }
-
- $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);
- }
-
- static public function getConfiguration(array $configFiles)
- {
- return self::flattenConfiguration(self::parseYamls($configFiles));
- }
- }
|