Subversion-Projekte lars-tiefland.php_share

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
1 lars 1
<?php
2
 
3
/*
4
 * This file is part of the symfony package.
5
 * (c) 2004-2006 Fabien Potencier <fabien.potencier@symfony-project.com>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
 
11
/**
12
 * sfCacheConfigHandler allows you to configure cache.
13
 *
14
 * @package    symfony
15
 * @subpackage config
16
 * @author     Fabien Potencier <fabien.potencier@symfony-project.com>
17
 * @version    SVN: $Id: sfCacheConfigHandler.class.php 23810 2009-11-12 11:07:44Z Kris.Wallsmith $
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
    // parse the yaml
38
    $this->yamlConfig = self::getConfiguration($configFiles);
39
 
40
    // iterate through all action names
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
    // general cache configuration
56
    $data[] = $this->addCache('DEFAULT');
57
 
58
    // compile data
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
    // enabled?
79
    $enabled = $this->getConfigValue('enabled', $actionName);
80
 
81
    // cache with or without loayout
82
    $withLayout = $this->getConfigValue('with_layout', $actionName) ? 'true' : 'false';
83
 
84
    // lifetime
85
    $lifeTime = !$enabled ? '0' : $this->getConfigValue('lifetime', $actionName, '0');
86
 
87
    // client_lifetime
88
    $clientLifetime = !$enabled ? '0' : $this->getConfigValue('client_lifetime', $actionName, $lifeTime, '0');
89
 
90
    // contextual
91
    $contextual = $this->getConfigValue('contextual', $actionName) ? 'true' : 'false';
92
 
93
    // vary
94
    $vary = $this->getConfigValue('vary', $actionName, array());
95
    if (!is_array($vary))
96
    {
97
      $vary = array($vary);
98
    }
99
 
100
    // add cache information to cache manager
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
}