1. sfCacheConfigHandler.class.php
  2. /** * sfCacheConfigHandler allows you to configure cache. * * @package symfony * @subpackage config * @author Fabien Potencier * @version SVN: $Id: sfCacheConfigHandler.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $ */
  3. class sfCacheConfigHandler extends sfYamlConfigHandler
  4. {
  5. protected
  6. $cacheConfig = array();
  7. /**
  8. * Executes this configuration handler.
  9. *
  10. * @param array $configFiles An array of absolute filesystem path to a configuration file
  11. *
  12. * @return string Data to be written to a cache file
  13. *
  14. * @throws <b>sfConfigurationException</b> If a requested configuration file does not exist or is not readable
  15. * @throws <b>sfParseException</b> If a requested configuration file is improperly formatted
  16. * @throws <b>sfInitializationException</b> If a cache.yml key check fails
  17. */
  18. public function execute($configFiles)
  19. {
  20. // parse the yaml
  21. $this->yamlConfig = self::getConfiguration($configFiles);
  22. // iterate through all action names
  23. $data = array();
  24. $first = true;
  25. foreach ($this->yamlConfig as $actionName => $values)
  26. {
  27. if ($actionName == 'all')
  28. {
  29. continue;
  30. }
  31. $data[] = $this->addCache($actionName);
  32. $first = false;
  33. }
  34. // general cache configuration
  35. $data[] = $this->addCache('DEFAULT');
  36. // compile data
  37. $retval = sprintf("<?php\n".
  38. "// auto-generated by sfCacheConfigHandler\n".
  39. "// date: %s\n%s\n",
  40. date('Y/m/d H:i:s'), implode('', $data));
  41. return $retval;
  42. }
  43. /**
  44. * Returns a single addCache statement.
  45. *
  46. * @param string $actionName The action name
  47. *
  48. * @return string PHP code for the addCache statement
  49. */
  50. protected function addCache($actionName = '')
  51. {
  52. $data = array();
  53. // enabled?
  54. $enabled = $this->getConfigValue('enabled', $actionName);
  55. // cache with or without loayout
  56. $withLayout = $this->getConfigValue('with_layout', $actionName) ? 'true' : 'false';
  57. // lifetime
  58. $lifeTime = !$enabled ? '0' : $this->getConfigValue('lifetime', $actionName, '0');
  59. // client_lifetime
  60. $clientLifetime = !$enabled ? '0' : $this->getConfigValue('client_lifetime', $actionName, $lifeTime, '0');
  61. // contextual
  62. $contextual = $this->getConfigValue('contextual', $actionName) ? 'true' : 'false';
  63. // vary
  64. $vary = $this->getConfigValue('vary', $actionName, array());
  65. if (!is_array($vary))
  66. {
  67. $vary = array($vary);
  68. }
  69. // add cache information to cache manager
  70. $data[] = sprintf("\$this->addCache(\$moduleName, '%s', array('withLayout' => %s, 'lifeTime' => %s, 'clientLifeTime' => %s, 'contextual' => %s, 'vary' => %s));\n",
  71. $actionName, $withLayout, $lifeTime, $clientLifetime, $contextual, str_replace("\n", '', var_export($vary, true)));
  72. return implode("\n", $data);
  73. }
  74. /**
  75. * @see sfConfigHandler
  76. */
  77. static public function getConfiguration(array $configFiles)
  78. {
  79. return self::flattenConfiguration(self::parseYamls($configFiles));
  80. }
  81. }

Debug toolbar