Development

Changeset 7616

You must first sign up to be able to contribute.

Changeset 7616

Show
Ignore:
Timestamp:
02/26/08 22:25:26 (5 years ago)
Author:
fabien
Message:

added a cache argument to the sfRouting constructor

  • sfRouting classes now takes a cache object as the second constructor parameter
  • modified factories.yml to enable the cache by default (via sfFileCache)
  • removed sfContext dependency in sfRoutingConfigHandler
  • modified sfRoutingConfigHandler to connect routes the same way plugins connect routes
  • plugin routes are now cached automatically (if you use the routing.load_configuration event)
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/1.1/lib/config/config/factories.yml

    r7518 r7616  
    4949      default_module:     default 
    5050      default_action:     index 
     51      cache: 
     52        class: sfFileCache 
     53        param: 
     54          automatic_cleaning_factor: 0 
     55          cache_dir:                 %SF_CONFIG_CACHE_DIR%/routing 
     56          lifetime:                  31556926 
     57          prefix:                    %SF_APP_DIR% 
    5158 
    5259  logger: 
  • branches/1.1/lib/config/sfFactoryConfigHandler.class.php

    r7614 r7616  
    162162 
    163163        case 'routing': 
    164           $instances[] = sprintf("  \$class = sfConfig::get('sf_factory_routing', '%s');\n  \$this->factories['routing'] = new \$class(\$this->dispatcher, array_merge(array('auto_shutdown' => false, 'logging' => sfConfig::get('sf_logging_enabled')), sfConfig::get('sf_factory_routing_parameters', %s)));", $class, var_export(is_array($parameters) ? $parameters : array(), true)); 
     164          if (isset($parameters['cache'])) 
     165          { 
     166            $cache = sprintf("    \$cache = new %s(%s);\n", $parameters['cache']['class'], var_export($parameters['cache']['param'], true)); 
     167            unset($parameters['cache']); 
     168          } 
     169          else 
     170          { 
     171            $cache = "    \$cache = null;\n"; 
     172          } 
     173 
     174          $instances[] = sprintf("  \$class = sfConfig::get('sf_factory_routing', '%s');\n  %s\n\$this->factories['routing'] = new \$class(\$this->dispatcher, \$cache, array_merge(array('auto_shutdown' => false, 'logging' => sfConfig::get('sf_logging_enabled')), sfConfig::get('sf_factory_routing_parameters', %s)));", $class, $cache, var_export(is_array($parameters) ? $parameters : array(), true)); 
    165175          if (isset($parameters['load_configuration']) && $parameters['load_configuration']) 
    166176          { 
  • branches/1.1/lib/config/sfRoutingConfigHandler.class.php

    r4435 r7616  
    2525   * 
    2626   * @throws sfConfigurationException If a requested configuration file does not exist or is not readable 
    27    * @throws sfParseException If a requested configuration file is improperly formatted 
     27   * @throws sfParseException         If a requested configuration file is improperly formatted 
    2828   */ 
    2929  public function execute($configFiles) 
     
    3333 
    3434    // connect routes 
    35     $routes = sfContext::getInstance()->getRouting(); 
     35    $data = array(); 
    3636    foreach ($config as $name => $params) 
    3737    { 
    38       $routes->connect( 
     38      $data[] = sprintf('$this->connect(\'%s\', \'%s\', %s, %s);', 
    3939        $name, 
    40         ($params['url'] ? $params['url'] : '/')
    41         (isset($params['param']) ? $params['param'] : array())
    42         (isset($params['requirements']) ? $params['requirements'] : array()) 
     40        $params['url'] ? $params['url'] : '/'
     41        isset($params['param']) ? var_export($params['param'], true) : 'array()'
     42        isset($params['requirements']) ? var_export($params['requirements'], true) : 'array()' 
    4343      ); 
    4444    } 
    4545 
    46     // compile data 
    47     $retval = sprintf("<?php\n". 
    48                       "// auto-generated by sfRoutingConfigHandler\n". 
    49                       "// date: %s\n\$this->setRoutes(\n%s\n);\n", 
    50                       date('Y/m/d H:i:s'), var_export($routes->getRoutes(), 1)); 
    51  
    52     return $retval; 
     46    return sprintf("<?php\n". 
     47                   "// auto-generated by sfRoutingConfigHandler\n". 
     48                   "// date: %s\n%s\n", date('Y/m/d H:i:s'), implode("\n", $data) 
     49    ); 
    5350  } 
    5451} 
  • branches/1.1/lib/routing/sfPatternRouting.class.php

    r7614 r7616  
    4040   * @see sfRouting 
    4141   */ 
    42   public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
     42  public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array()) 
    4343  { 
    4444    if (!isset($options['variable_prefixes'])) 
     
    6161    $options['variable_content_regex']   = '[^'.implode('', array_map(create_function('$a', 'return str_replace(\'-\', \'\-\', preg_quote($a, \'#\'));'), $options['segment_separators'])).']+'; 
    6262 
    63     parent::initialize($dispatcher, $options); 
     63    parent::initialize($dispatcher, $cache, $options); 
    6464 
    6565    $this->setDefaultSuffix(isset($options['suffix']) ? $options['suffix'] : ''); 
     
    7171  public function loadConfiguration() 
    7272  { 
    73     if ($config = sfContext::getInstance()->getConfigCache()->checkConfig('config/routing.yml', true)) 
    74     { 
    75       include($config); 
    76     } 
    77  
    78     parent::loadConfiguration(); 
     73    if ($routes = $this->cache->get('configuration')) 
     74    { 
     75      $this->routes = unserialize($routes); 
     76    } 
     77    else 
     78    { 
     79      if ($config = sfContext::getInstance()->getConfigCache()->checkConfig('config/routing.yml', true)) 
     80      { 
     81        include($config); 
     82      } 
     83 
     84      parent::loadConfiguration(); 
     85 
     86      $this->cache->set('configuration', serialize($this->routes)); 
     87    } 
    7988  } 
    8089 
  • branches/1.1/lib/routing/sfRouting.class.php

    r7525 r7616  
    2121  protected 
    2222    $dispatcher        = null, 
     23    $cache             = null, 
    2324    $defaultParameters = array(), 
    2425    $defaultModule     = 'default', 
     
    3132   * @see initialize() 
    3233   */ 
    33   public function __construct(sfEventDispatcher $dispatcher, $options = array()) 
    34   { 
    35     $this->initialize($dispatcher, $options); 
     34  public function __construct(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array()) 
     35  { 
     36    $this->initialize($dispatcher, $cache, $options); 
    3637 
    3738    if (isset($this->options['auto_shutdown']) && $this->options['auto_shutdown']) 
     
    4445   * Initializes this sfRouting instance. 
    4546   * 
    46    * @param  sfEventDispatcher A sfEventDispatcher instance 
    47    * @param  array             An associative array of initialization options. 
    48    */ 
    49   public function initialize(sfEventDispatcher $dispatcher, $options = array()) 
     47   * @param sfEventDispatcher A sfEventDispatcher instance 
     48   * @param sfCache           A sfCache instance 
     49   * @param array             An associative array of initialization options. 
     50   */ 
     51  public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array()) 
    5052  { 
    5153    $this->dispatcher = $dispatcher; 
     54    $this->cache      = $cache; 
    5255 
    5356    if (isset($options['default_module'])) 
  • branches/1.1/test/unit/routing/sfPatternRoutingTest.php

    r7611 r7616  
    303303// separators 
    304304$t->diag('separators'); 
    305 $r = new sfPatternRoutingTest(new sfEventDispatcher(), array('segment_separators' => array('/', ';', ':', '|', '.', '-', '+'))); 
     305$r = new sfPatternRoutingTest(new sfEventDispatcher(), null, array('segment_separators' => array('/', ';', ':', '|', '.', '-', '+'))); 
    306306$r->clearRoutes(); 
    307307$r->connect('test', '/:module/:action;:foo::baz+static+:toto|:hip-:zozo.:format', array()); 
     
    345345$t->is($r->parse($url), $params, '->parse()    recognizes parameters separated by mixed separators'); 
    346346$t->is($r->generate('', $params), $url, '->generate() creates routes with mixed separators'); 
    347 $r = new sfPatternRoutingTest(new sfEventDispatcher(), array('variable_prefixes' => array(':', '$'))); 
     347$r = new sfPatternRoutingTest(new sfEventDispatcher(), null, array('variable_prefixes' => array(':', '$'))); 
    348348 
    349349// token names 
  • branches/1.1/test/unit/sfContextMock.class.php

    r6463 r7616  
    105105    { 
    106106      case 'routing': 
     107        $object = new $class($this->dispatcher, null, $parameters); 
     108        break; 
    107109      case 'response': 
    108110        $object = new $class($this->dispatcher, $parameters);