[ Index ]
 

Code source de Symfony 1.0.0

Accédez au Source d'autres logiciels libresSoutenez Angelica Josefina !

title

Body

[fermer]

/lib/config/ -> sfCacheConfigHandler.class.php (source)

   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 3203 2007-01-09 18:32:54Z fabien $
  18   */
  19  class sfCacheConfigHandler extends sfYamlConfigHandler
  20  {
  21    protected
  22      $cacheConfig = array();
  23  
  24    /**
  25     * Executes this configuration handler.
  26     *
  27     * @param array 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      // set our required categories list and initialize our handler
  38      $categories = array('required_categories' => array());
  39      $this->initialize($categories);
  40  
  41      // parse the yaml
  42      $myConfig = $this->parseYamls($configFiles);
  43  
  44      $myConfig['all'] = sfToolkit::arrayDeepMerge(
  45        isset($myConfig['default']) && is_array($myConfig['default']) ? $myConfig['default'] : array(),
  46        isset($myConfig['all']) && is_array($myConfig['all']) ? $myConfig['all'] : array()
  47      );
  48  
  49      unset($myConfig['default']);
  50  
  51      $this->yamlConfig = $myConfig;
  52  
  53      // iterate through all action names
  54      $data  = array();
  55      $first = true;
  56      foreach ($this->yamlConfig as $actionName => $values)
  57      {
  58        if ($actionName == 'all')
  59        {
  60          continue;
  61        }
  62  
  63        $data[] = $this->addCache($actionName);
  64  
  65        $first = false;
  66      }
  67  
  68      // general cache configuration
  69      $data[] = $this->addCache('DEFAULT');
  70  
  71      // compile data
  72      $retval = sprintf("<?php\n".
  73                        "// auto-generated by sfCacheConfigHandler\n".
  74                        "// date: %s\n%s\n",
  75                        date('Y/m/d H:i:s'), implode('', $data));
  76  
  77      return $retval;
  78    }
  79  
  80    /**
  81     * Returns a single addCache statement.
  82     *
  83     * @param string The action name
  84     *
  85     * @return string PHP code for the addCache statement
  86     */
  87    protected function addCache($actionName = '')
  88    {
  89      $data = array();
  90  
  91      // enabled?
  92      $enabled = $this->getConfigValue('enabled', $actionName);
  93  
  94      // cache with or without loayout
  95      $withLayout = $this->getConfigValue('with_layout', $actionName) ? 'true' : 'false';
  96  
  97      // lifetime
  98      $lifeTime = !$enabled ? '0' : $this->getConfigValue('lifetime', $actionName, '0');
  99  
 100      // client_lifetime
 101      $clientLifetime = !$enabled ? '0' : $this->getConfigValue('client_lifetime', $actionName, $lifeTime, '0');
 102  
 103      // contextual
 104      $contextual = $this->getConfigValue('contextual', $actionName) ? 'true' : 'false';
 105  
 106      // vary
 107      $vary = $this->getConfigValue('vary', $actionName, array());
 108      if (!is_array($vary))
 109      {
 110        $vary = array($vary);
 111      }
 112  
 113      // add cache information to cache manager
 114      $data[] = sprintf("\$this->addCache(\$moduleName, '%s', array('withLayout' => %s, 'lifeTime' => %s, 'clientLifeTime' => %s, 'contextual' => %s, 'vary' => %s));\n",
 115                        $actionName, $withLayout, $lifeTime, $clientLifetime, $contextual, str_replace("\n", '', var_export($vary, true)));
 116  
 117      return implode("\n", $data);
 118    }
 119  }


Généré le : Fri Mar 16 22:42:14 2007 par Balluche grâce à PHPXref 0.7