Development

Changeset 6363

You must first sign up to be able to contribute.

Changeset 6363

Show
Ignore:
Timestamp:
12/07/07 15:52:16 (7 months ago)
Author:
fabien
Message:

removed sfParameterHolder dependency for the cache framework

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lib/cache/sfAPCCache.class.php

    r6362 r6363  
    2424   * Initializes this sfCache instance. 
    2525   * 
    26    * Available parameters: 
     26   * Available options: 
    2727   * 
    28    * * see sfCache for default parameters available for all drivers 
     28   * * see sfCache for options available for all drivers 
    2929   * 
    3030   * @see sfCache 
    3131   */ 
    32   public function initialize($parameters = array()) 
     32  public function initialize($options = array()) 
    3333  { 
    34     parent::initialize($parameters); 
     34    parent::initialize($options); 
    3535 
    3636    if (!function_exists('apc_store') || !ini_get('apc.enabled')) 
  • trunk/lib/cache/sfCache.class.php

    r5016 r6363  
    2424 
    2525  protected 
    26     $parameterHolder = null
     26    $options = array()
    2727 
    2828  /** 
     
    3131   * @see initialize() 
    3232   */ 
    33   public function __construct($parameters = array()) 
    34   { 
    35     $this->initialize($parameters); 
     33  public function __construct($options = array()) 
     34  { 
     35    $this->initialize($options); 
    3636  } 
    3737 
     
    3939   * Initializes this sfCache instance. 
    4040   * 
    41    * @param  array An associative array of initialization parameters. 
    42    * 
    43    * Available parameters: 
     41   * @param  array An array of options. 
     42   * 
     43   * Available options: 
    4444   * 
    4545   * * automaticCleaningFactor (optional): The automatic cleaning process destroy too old (for the given life time) (default value: 1000) 
     
    5151   * * lifetime (optional): The default life time (default value: 86400) 
    5252   * 
    53    * @return bool true, if initialization completes successfully, otherwise false. 
    54    * 
    5553   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfCache instance. 
    5654   */ 
    57   public function initialize($parameters = array()) 
    58   { 
    59     $this->parameterHolder = new sfParameterHolder(); 
    60     $this->parameterHolder->add($parameters); 
    61  
    62     if (!$this->hasParameter('automaticCleaningFactor')) 
    63     { 
    64       $this->setParameter('automaticCleaningFactor', 1000); 
    65     } 
    66  
    67     if (!$this->hasParameter('lifetime')) 
    68     { 
    69       $this->setParameter('lifetime', 86400); 
    70     } 
     55  public function initialize($options = array()) 
     56  { 
     57    $this->options = array_merge(array('automaticCleaningFactor' => 1000, 'lifetime' => 86400), $options); 
    7158  } 
    7259 
     
    177164  public function getLifetime($lifetime) 
    178165  { 
    179     return is_null($lifetime) ? $this->getParameter('lifetime') : $lifetime; 
     166    return is_null($lifetime) ? $this->getOption('lifetime') : $lifetime; 
    180167  } 
    181168 
     
    191178 
    192179  /** 
    193    * Retrieves the parameters for the current request. 
    194    * 
    195    * @return sfParameterHolder The parameter holder 
    196    */ 
    197   public function getParameterHolder() 
    198   { 
    199     return $this->parameterHolder; 
    200   } 
    201  
    202   public function getParameter($name, $default = null) 
    203   { 
    204     return $this->parameterHolder->get($name, $default); 
    205   } 
    206  
    207   public function hasParameter($name) 
    208   { 
    209     return $this->parameterHolder->has($name); 
    210   } 
    211  
    212   public function setParameter($name, $value) 
    213   { 
    214     return $this->parameterHolder->set($name, $value); 
     180   * Gets an option value. 
     181   * 
     182   * @param  string The option name 
     183   * 
     184   * @return mixed  The option value 
     185   */ 
     186  public function getOption($name, $default = null) 
     187  { 
     188    return isset($this->options[$name]) ? $this->options[$name] : $default; 
     189  } 
     190 
     191  /** 
     192   * Sets an option value. 
     193   * 
     194   * @param string The option name 
     195   * @param mixed  The option value 
     196   */ 
     197  public function setOption($name, $value) 
     198  { 
     199    return $this->options[$name] = $value; 
    215200  } 
    216201 
  • trunk/lib/cache/sfEAcceleratorCache.class.php

    r6362 r6363  
    2424   * Initializes this sfCache instance. 
    2525   * 
    26    * Available parameters: 
     26   * Available options: 
    2727   * 
    28    * * see sfCache for default parameters available for all drivers 
     28   * * see sfCache for options available for all drivers 
    2929   * 
    3030   * @see sfCache 
    3131   */ 
    32   public function initialize($parameters = array()) 
     32  public function initialize($options = array()) 
    3333  { 
    34     parent::initialize($parameters); 
     34    parent::initialize($options); 
    3535 
    3636    if (!function_exists('eaccelerator_put') || !ini_get('eaccelerator.enable')) 
  • trunk/lib/cache/sfFileCache.class.php

    r5309 r6363  
    2828  * Initializes this sfCache instance. 
    2929  * 
    30   * Available parameters: 
     30  * Available options: 
    3131  * 
    3232  * * cacheDir: The directory where to put cache files 
    3333  * 
    34   * * see sfCache for default parameters available for all drivers 
    35   * 
    36   * @param  array An associative array of initialization parameters. 
    37   * 
    38   * @return bool  true, if initialization completes successfully, otherwise false. 
    39   * 
    40   * @throws <b>sfInitializationException</b> If an error occurs while initializing this sfCache. 
     34  * * see sfCache for options available for all drivers 
     35  * 
     36  * @see sfCache 
    4137  */ 
    42   public function initialize($parameters = array()) 
    43   { 
    44     parent::initialize($parameters); 
    45  
    46     if (!$this->getParameter('cacheDir')) 
    47     { 
    48       throw new sfInitializationException('You must pass a "cacheDir" parameter to initialize a sfFileCache object.'); 
    49     } 
    50  
    51     $this->setCacheDir($this->getParameter('cacheDir')); 
     38  public function initialize($options = array()) 
     39  { 
     40    parent::initialize($options); 
     41 
     42    if (!$this->getOption('cacheDir')) 
     43    { 
     44      throw new sfInitializationException('You must pass a "cacheDir" option to initialize a sfFileCache object.'); 
     45    } 
     46 
     47    $this->setCacheDir($this->getOption('cacheDir')); 
    5248  } 
    5349 
     
    7874  public function set($key, $data, $lifetime = null) 
    7975  { 
    80     if ($this->getParameter('automaticCleaningFactor') > 0 && rand(1, $this->getParameter('automaticCleaningFactor')) == 1) 
     76    if ($this->getOption('automaticCleaningFactor') > 0 && rand(1, $this->getOption('automaticCleaningFactor')) == 1) 
    8177    { 
    8278      $this->clean(sfCache::OLD); 
     
    105101      $regexp = self::patternToRegexp($pattern); 
    106102      $paths = array(); 
    107       foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->getParameter('cacheDir'))) as $path) 
     103      foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->getOption('cacheDir'))) as $path) 
    108104      { 
    109         if (preg_match($regexp, str_replace($this->getParameter('cacheDir').DIRECTORY_SEPARATOR, '', $path))) 
     105        if (preg_match($regexp, str_replace($this->getOption('cacheDir').DIRECTORY_SEPARATOR, '', $path))) 
    110106        { 
    111107          $paths[] = $path; 
     
    115111    else 
    116112    { 
    117       $paths = glob($this->getParameter('cacheDir').DIRECTORY_SEPARATOR.str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $pattern).self::EXTENSION); 
     113      $paths = glob($this->getOption('cacheDir').DIRECTORY_SEPARATOR.str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $pattern).self::EXTENSION); 
    118114    } 
    119115 
     
    136132  public function clean($mode = sfCache::ALL) 
    137133  { 
    138     if (!is_dir($this->getParameter('cacheDir'))) 
     134    if (!is_dir($this->getOption('cacheDir'))) 
    139135    { 
    140136      return true; 
     
    142138 
    143139    $result = true; 
    144     foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->getParameter('cacheDir'))) as $file) 
     140    foreach (new RecursiveIteratorIterator(new RecursiveDirectoryIterator($this->getOption('cacheDir'))) as $file) 
    145141    { 
    146142      if (sfCache::ALL == $mode || time() > $this->read($file, self::READ_TIMEOUT)) 
     
    194190  protected function getFilePath($key) 
    195191  { 
    196     return $this->getParameter('cacheDir').DIRECTORY_SEPARATOR.str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $key).self::EXTENSION; 
     192    return $this->getOption('cacheDir').DIRECTORY_SEPARATOR.str_replace(sfCache::SEPARATOR, DIRECTORY_SEPARATOR, $key).self::EXTENSION; 
    197193  } 
    198194 
  • trunk/lib/cache/sfMemcacheCache.class.php

    r6362 r6363  
    2626   * Initializes this sfCache instance. 
    2727   * 
    28    * Available parameters: 
    29    * 
    30    * Available parameters: 
     28   * Available options: 
    3129   * 
    3230   * * memcache: A memcache object (optional) 
     
    3836   * * servers:    An array of additional servers (keys: host, port, persistent) 
    3937   * 
    40    * * see sfCache for default parameters available for all drivers 
    41    * 
    42    * @see sfCache 
    43    */ 
    44   public function initialize($parameters = array()) 
    45   { 
    46     parent::initialize($parameters); 
     38   * * see sfCache for options available for all drivers 
     39   * 
     40   * @see sfCache 
     41   */ 
     42  public function initialize($options = array()) 
     43  { 
     44    parent::initialize($options); 
    4745 
    4846    if (!class_exists('Memcache')) 
     
    5351    $this->prefix = md5(sfConfig::get('sf_app_dir')).self::SEPARATOR; 
    5452 
    55     if ($this->getParameter('memcache')) 
    56     { 
    57       $this->memcache = $this->getParameter('memcache'); 
     53    if ($this->getOption('memcache')) 
     54    { 
     55      $this->memcache = $this->getOption('memcache'); 
    5856    } 
    5957    else 
    6058    { 
    6159      $this->memcache = new Memcache(); 
    62       $method = $this->getParameter('persistent', true) ? 'pconnect' : 'connect'; 
    63       if (!$this->memcache->$method($this->getParameter('host', 'localhost'), $this->getParameter('port', 11211), $this->getParameter('timeout', 1))) 
     60      $method = $this->getOption('persistent', true) ? 'pconnect' : 'connect'; 
     61      if (!$this->memcache->$method($this->getOption('host', 'localhost'), $this->getOption('port', 11211), $this->getOption('timeout', 1))) 
    6462      { 
    65         throw new sfInitializationException(sprintf('Unable to connect to the memcache server (%s:%s).', $this->getParameter('host', 'localhost'), $this->getParameter('port', 11211))); 
     63        throw new sfInitializationException(sprintf('Unable to connect to the memcache server (%s:%s).', $this->getOption('host', 'localhost'), $this->getOption('port', 11211))); 
    6664      } 
    6765 
    68       if ($this->getParameter('servers')) 
     66      if ($this->getOption('servers')) 
    6967      { 
    70         foreach ($this->getParameter('servers') as $server) 
     68        foreach ($this->getOption('servers') as $server) 
    7169        { 
    7270          $port = isset($server['port']) ? $server['port'] : 11211; 
     
    111109  public function set($key, $data, $lifetime = null) 
    112110  { 
    113     $lifetime = is_null($lifetime) ? $this->getParameter('lifetime') : $lifetime; 
     111    $lifetime = is_null($lifetime) ? $this->getOption('lifetime') : $lifetime; 
    114112 
    115113    // save metadata 
     
    117115 
    118116    // save key for removePattern() 
    119     if ($this->getParameter('storeCacheInfo', false)) 
     117    if ($this->getOption('storeCacheInfo', false)) 
    120118    { 
    121119      $this->setCacheInfo($key); 
     
    177175  public function removePattern($pattern) 
    178176  { 
    179     if (!$this->getParameter('storeCacheInfo', false)) 
    180     { 
    181       throw new sfCacheException('To use the "removePattern" method, you must set the "storeCacheInfo" parameter to "true".'); 
     177    if (!$this->getOption('storeCacheInfo', false)) 
     178    { 
     179      throw new sfCacheException('To use the "removePattern" method, you must set the "storeCacheInfo" option to "true".'); 
    182180    } 
    183181 
  • trunk/lib/cache/sfSQLiteCache.class.php

    r4586 r6363  
    2626   * Initializes this sfCache instance. 
    2727   * 
    28    * Available parameters: 
     28   * Available options: 
    2929   * 
    3030   * * database: File where to put the cache database (or :memory: to store cache in memory) 
    3131   * 
    32    * * see sfCache for default parameters available for all drivers 
    33    * 
    34    * @see sfCache 
    35    */ 
    36   public function initialize($parameters = array()) 
     32   * * see sfCache for options available for all drivers 
     33   * 
     34   * @see sfCache 
     35   */ 
     36  public function initialize($options = array()) 
    3737  { 
    3838    if (!extension_loaded('sqlite')) 
     
    4141    } 
    4242 
    43     parent::initialize($parameters); 
    44  
    45     if (!$this->getParameter('database')) 
    46     { 
    47       throw new sfInitializationException('You must pass a "database" parameter to initialize a sfSQLiteCache object.'); 
    48     } 
    49  
    50     $this->setDatabase($this->getParameter('database')); 
     43    parent::initialize($options); 
     44 
     45    if (!$this->getOption('database')) 
     46    { 
     47      throw new sfInitializationException('You must pass a "database" option to initialize a sfSQLiteCache object.'); 
     48    } 
     49 
     50    $this->setDatabase($this->getOption('database')); 
    5151  } 
    5252 
     
    8282  public function set($key, $data, $lifetime = null) 
    8383  { 
    84     if ($this->getParameter('automaticCleaningFactor') > 0 && rand(1, $this->getParameter('automaticCleaningFactor')) == 1) 
     84    if ($this->getOption('automaticCleaningFactor') > 0 && rand(1, $this->getOption('automaticCleaningFactor')) == 1) 
    8585    { 
    8686      $this->clean(sfCache::OLD); 
  • trunk/lib/cache/sfXCacheCache.class.php

    r6362 r6363  
    2424   * Initializes this sfCache instance. 
    2525   * 
    26    * Available parameters: 
     26   * Available options: 
    2727   * 
    28    * * see sfCache for default parameters available for all drivers 
     28   * * see sfCache for options available for all drivers 
    2929   * 
    3030   * @see sfCache 
    3131   */ 
    32   public function initialize($parameters = array()) 
     32  public function initialize($options = array()) 
    3333  { 
    34     parent::initialize($parameters); 
     34    parent::initialize($options); 
    3535 
    3636    if (!function_exists('xcache_set')) 
  • trunk/test/unit/cache/sfCacheDriverTests.class.php

    r4579 r6363  
    6464 
    6565    $cache->clean(); 
    66     $cache->setParameter('automaticCleaningFactor', 1); 
     66    $cache->setOption('automaticCleaningFactor', 1); 
    6767    $cache->set('foo', $data); 
    6868    $cache->set('foo', $data); 
    6969    $cache->set('foo', $data); 
    70     $cache->setParameter('automaticCleaningFactor', 1000); 
     70    $cache->setOption('automaticCleaningFactor', 1000); 
    7171 
    7272    // ->remove() 
     
    128128    foreach (array(86400, 10) as $lifetime) 
    129129    { 
    130       $cache->getParameterHolder()->set('lifetime', $lifetime); 
     130      $cache->setOption('lifetime', $lifetime); 
    131131      $cache->set('foo', 'bar'); 
    132132 
     
    152152    foreach (array(86400, 10) as $lifetime) 
    153153    { 
    154       $cache->getParameterHolder()->set('lifetime', $lifetime); 
     154      $cache->setOption('lifetime', $lifetime); 
    155155      $cache->set('bar', 'foo'); 
    156156 
  • trunk/test/unit/cache/sfCacheTest.php

    r4957 r6363  
    3333$cache = new myCache(); 
    3434$cache->initialize(array('foo' => 'bar')); 
    35 $t->is($cache->getParameterHolder()->get('foo'), 'bar', '->initialize() takes an array of parameters as its first argument'); 
     35$t->is($cache->getOption('foo'), 'bar', '->initialize() takes an array of options as its first argument');