Skip to content

Commit 8e5a9cd

Browse files
committed
Accept 'connectOptions' in Router::mapResources()
1 parent 4e74b93 commit 8e5a9cd

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

lib/Cake/Routing/Router.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -500,11 +500,14 @@ public static function namedConfig() {
500500
public static function mapResources($controller, $options = array()) {
501501
$hasPrefix = isset($options['prefix']);
502502
$options = array_merge(array(
503+
'connectOptions' => array(),
503504
'prefix' => '/',
504505
'id' => self::ID . '|' . self::UUID
505506
), $options);
506507

507508
$prefix = $options['prefix'];
509+
$connectOptions = $options['connectOptions'];
510+
unset($options['connectOptions']);
508511

509512
foreach ((array)$controller as $name) {
510513
list($plugin, $name) = pluginSplit($name);
@@ -524,7 +527,10 @@ public static function mapResources($controller, $options = array()) {
524527
'action' => $params['action'],
525528
'[method]' => $params['method']
526529
),
527-
array('id' => $options['id'], 'pass' => array('id'))
530+
array_merge(
531+
array('id' => $options['id'], 'pass' => array('id')),
532+
$connectOptions
533+
)
528534
);
529535
}
530536
self::$_resourceMapped[] = $urlName;

lib/Cake/Test/Case/Routing/RouterTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -179,6 +179,28 @@ public function testPluginMapResources() {
179179
$this->assertEquals($expected, $result);
180180
}
181181

182+
/**
183+
* testMapResources with custom connectOptions
184+
*/
185+
public function testMapResourcesConnectOptions() {
186+
App::build(array(
187+
'Plugin' => array(
188+
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
189+
)
190+
));
191+
CakePlugin::load('TestPlugin');
192+
App::uses('TestRoute', 'TestPlugin.Routing/Route');
193+
$resources = Router::mapResources('Posts', array(
194+
'connectOptions' => array(
195+
'routeClass' => 'TestPlugin.TestRoute',
196+
'foo' => '^(bar)$',
197+
),
198+
));
199+
$route = end(Router::$routes);
200+
$this->assertInstanceOf('TestRoute', $route);
201+
$this->assertEquals('^(bar)$', $route->options['foo']);
202+
}
203+
182204
/**
183205
* Test mapResources with a plugin and prefix.
184206
*

0 commit comments

Comments
 (0)