Changeset 7616
- Timestamp:
- 02/26/08 22:25:26 (8 months ago)
- Files:
-
- branches/1.1/lib/config/config/factories.yml (modified) (1 diff)
- branches/1.1/lib/config/sfFactoryConfigHandler.class.php (modified) (1 diff)
- branches/1.1/lib/config/sfRoutingConfigHandler.class.php (modified) (2 diffs)
- branches/1.1/lib/routing/sfPatternRouting.class.php (modified) (3 diffs)
- branches/1.1/lib/routing/sfRouting.class.php (modified) (3 diffs)
- branches/1.1/test/unit/routing/sfPatternRoutingTest.php (modified) (2 diffs)
- branches/1.1/test/unit/sfContextMock.class.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/1.1/lib/config/config/factories.yml
r7518 r7616 49 49 default_module: default 50 50 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% 51 58 52 59 logger: branches/1.1/lib/config/sfFactoryConfigHandler.class.php
r7614 r7616 162 162 163 163 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)); 165 175 if (isset($parameters['load_configuration']) && $parameters['load_configuration']) 166 176 { branches/1.1/lib/config/sfRoutingConfigHandler.class.php
r4435 r7616 25 25 * 26 26 * @throws sfConfigurationException If a requested configuration file does not exist or is not readable 27 * @throws sfParseException If a requested configuration file is improperly formatted27 * @throws sfParseException If a requested configuration file is improperly formatted 28 28 */ 29 29 public function execute($configFiles) … … 33 33 34 34 // connect routes 35 $ routes = sfContext::getInstance()->getRouting();35 $data = array(); 36 36 foreach ($config as $name => $params) 37 37 { 38 $ routes->connect(38 $data[] = sprintf('$this->connect(\'%s\', \'%s\', %s, %s);', 39 39 $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()' 43 43 ); 44 44 } 45 45 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 ); 53 50 } 54 51 } branches/1.1/lib/routing/sfPatternRouting.class.php
r7614 r7616 40 40 * @see sfRouting 41 41 */ 42 public function initialize(sfEventDispatcher $dispatcher, $options = array())42 public function initialize(sfEventDispatcher $dispatcher, sfCache $cache = null, $options = array()) 43 43 { 44 44 if (!isset($options['variable_prefixes'])) … … 61 61 $options['variable_content_regex'] = '[^'.implode('', array_map(create_function('$a', 'return str_replace(\'-\', \'\-\', preg_quote($a, \'#\'));'), $options['segment_separators'])).']+'; 62 62 63 parent::initialize($dispatcher, $ options);63 parent::initialize($dispatcher, $cache, $options); 64 64 65 65 $this->setDefaultSuffix(isset($options['suffix']) ? $options['suffix'] : ''); … … 71 71 public function loadConfiguration() 72 72 { 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 } 79 88 } 80 89 branches/1.1/lib/routing/sfRouting.class.php
r7525 r7616 21 21 protected 22 22 $dispatcher = null, 23 $cache = null, 23 24 $defaultParameters = array(), 24 25 $defaultModule = 'default', … … 31 32 * @see initialize() 32 33 */ 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); 36 37 37 38 if (isset($this->options['auto_shutdown']) && $this->options['auto_shutdown']) … … 44 45 * Initializes this sfRouting instance. 45 46 * 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()) 50 52 { 51 53 $this->dispatcher = $dispatcher; 54 $this->cache = $cache; 52 55 53 56 if (isset($options['default_module'])) branches/1.1/test/unit/routing/sfPatternRoutingTest.php
r7611 r7616 303 303 // separators 304 304 $t->diag('separators'); 305 $r = new sfPatternRoutingTest(new sfEventDispatcher(), array('segment_separators' => array('/', ';', ':', '|', '.', '-', '+')));305 $r = new sfPatternRoutingTest(new sfEventDispatcher(), null, array('segment_separators' => array('/', ';', ':', '|', '.', '-', '+'))); 306 306 $r->clearRoutes(); 307 307 $r->connect('test', '/:module/:action;:foo::baz+static+:toto|:hip-:zozo.:format', array()); … … 345 345 $t->is($r->parse($url), $params, '->parse() recognizes parameters separated by mixed separators'); 346 346 $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(':', '$'))); 348 348 349 349 // token names branches/1.1/test/unit/sfContextMock.class.php
r6463 r7616 105 105 { 106 106 case 'routing': 107 $object = new $class($this->dispatcher, null, $parameters); 108 break; 107 109 case 'response': 108 110 $object = new $class($this->dispatcher, $parameters);