| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
|
|---|
| 15 |
|
|---|
| 16 |
|
|---|
| 17 |
|
|---|
| 18 |
|
|---|
| 19 |
class sfCacheConfigHandler extends sfYamlConfigHandler |
|---|
| 20 |
{ |
|---|
| 21 |
protected |
|---|
| 22 |
$cacheConfig = array(); |
|---|
| 23 |
|
|---|
| 24 |
|
|---|
| 25 |
* Executes this configuration handler. |
|---|
| 26 |
* |
|---|
| 27 |
* @param array $configFiles An array of absolute filesystem path to a configuration file |
|---|
| 28 |
* |
|---|
| 29 |
* @return string Data to be written to a cache file |
|---|
| 30 |
* |
|---|
| 31 |
* @throws <b>sfConfigurationException</b> If a requested configuration file does not exist or is not readable |
|---|
| 32 |
* @throws <b>sfParseException</b> If a requested configuration file is improperly formatted |
|---|
| 33 |
* @throws <b>sfInitializationException</b> If a cache.yml key check fails |
|---|
| 34 |
*/ |
|---|
| 35 |
public function execute($configFiles) |
|---|
| 36 |
{ |
|---|
| 37 |
|
|---|
| 38 |
$this->yamlConfig = self::getConfiguration($configFiles); |
|---|
| 39 |
|
|---|
| 40 |
|
|---|
| 41 |
$data = array(); |
|---|
| 42 |
$first = true; |
|---|
| 43 |
foreach ($this->yamlConfig as $actionName => $values) |
|---|
| 44 |
{ |
|---|
| 45 |
if ($actionName == 'all') |
|---|
| 46 |
{ |
|---|
| 47 |
continue; |
|---|
| 48 |
} |
|---|
| 49 |
|
|---|
| 50 |
$data[] = $this->addCache($actionName); |
|---|
| 51 |
|
|---|
| 52 |
$first = false; |
|---|
| 53 |
} |
|---|
| 54 |
|
|---|
| 55 |
|
|---|
| 56 |
$data[] = $this->addCache('DEFAULT'); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
$retval = sprintf("<?php\n". |
|---|
| 60 |
"// auto-generated by sfCacheConfigHandler\n". |
|---|
| 61 |
"// date: %s\n%s\n", |
|---|
| 62 |
date('Y/m/d H:i:s'), implode('', $data)); |
|---|
| 63 |
|
|---|
| 64 |
return $retval; |
|---|
| 65 |
} |
|---|
| 66 |
|
|---|
| 67 |
|
|---|
| 68 |
* Returns a single addCache statement. |
|---|
| 69 |
* |
|---|
| 70 |
* @param string $actionName The action name |
|---|
| 71 |
* |
|---|
| 72 |
* @return string PHP code for the addCache statement |
|---|
| 73 |
*/ |
|---|
| 74 |
protected function addCache($actionName = '') |
|---|
| 75 |
{ |
|---|
| 76 |
$data = array(); |
|---|
| 77 |
|
|---|
| 78 |
|
|---|
| 79 |
$enabled = $this->getConfigValue('enabled', $actionName); |
|---|
| 80 |
|
|---|
| 81 |
|
|---|
| 82 |
$withLayout = $this->getConfigValue('with_layout', $actionName) ? 'true' : 'false'; |
|---|
| 83 |
|
|---|
| 84 |
|
|---|
| 85 |
$lifeTime = !$enabled ? '0' : $this->getConfigValue('lifetime', $actionName, '0'); |
|---|
| 86 |
|
|---|
| 87 |
|
|---|
| 88 |
$clientLifetime = !$enabled ? '0' : $this->getConfigValue('client_lifetime', $actionName, $lifeTime, '0'); |
|---|
| 89 |
|
|---|
| 90 |
|
|---|
| 91 |
$contextual = $this->getConfigValue('contextual', $actionName) ? 'true' : 'false'; |
|---|
| 92 |
|
|---|
| 93 |
|
|---|
| 94 |
$vary = $this->getConfigValue('vary', $actionName, array()); |
|---|
| 95 |
if (!is_array($vary)) |
|---|
| 96 |
{ |
|---|
| 97 |
$vary = array($vary); |
|---|
| 98 |
} |
|---|
| 99 |
|
|---|
| 100 |
|
|---|
| 101 |
$data[] = sprintf("\$this->addCache(\$moduleName, '%s', array('withLayout' => %s, 'lifeTime' => %s, 'clientLifeTime' => %s, 'contextual' => %s, 'vary' => %s));\n", |
|---|
| 102 |
$actionName, $withLayout, $lifeTime, $clientLifetime, $contextual, str_replace("\n", '', var_export($vary, true))); |
|---|
| 103 |
|
|---|
| 104 |
return implode("\n", $data); |
|---|
| 105 |
} |
|---|
| 106 |
|
|---|
| 107 |
|
|---|
| 108 |
* @see sfConfigHandler |
|---|
| 109 |
*/ |
|---|
| 110 |
static public function getConfiguration(array $configFiles) |
|---|
| 111 |
{ |
|---|
| 112 |
return self::flattenConfiguration(self::parseYamls($configFiles)); |
|---|
| 113 |
} |
|---|
| 114 |
} |
|---|
| 115 |
|
|---|