Skip to content

Commit

Permalink
Accept 'connectOptions' in Router::mapResources()
Browse files Browse the repository at this point in the history
  • Loading branch information
rchavik committed Aug 17, 2013
1 parent 4e74b93 commit 8e5a9cd
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/Cake/Routing/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -500,11 +500,14 @@ public static function namedConfig() {
public static function mapResources($controller, $options = array()) {
$hasPrefix = isset($options['prefix']);
$options = array_merge(array(
'connectOptions' => array(),
'prefix' => '/',
'id' => self::ID . '|' . self::UUID
), $options);

$prefix = $options['prefix'];
$connectOptions = $options['connectOptions'];
unset($options['connectOptions']);

foreach ((array)$controller as $name) {
list($plugin, $name) = pluginSplit($name);
Expand All @@ -524,7 +527,10 @@ public static function mapResources($controller, $options = array()) {
'action' => $params['action'],
'[method]' => $params['method']
),
array('id' => $options['id'], 'pass' => array('id'))
array_merge(
array('id' => $options['id'], 'pass' => array('id')),
$connectOptions
)
);
}
self::$_resourceMapped[] = $urlName;
Expand Down
22 changes: 22 additions & 0 deletions lib/Cake/Test/Case/Routing/RouterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,28 @@ public function testPluginMapResources() {
$this->assertEquals($expected, $result);
}

/**
* testMapResources with custom connectOptions
*/
public function testMapResourcesConnectOptions() {
App::build(array(
'Plugin' => array(
CAKE . 'Test' . DS . 'test_app' . DS . 'Plugin' . DS
)
));
CakePlugin::load('TestPlugin');
App::uses('TestRoute', 'TestPlugin.Routing/Route');
$resources = Router::mapResources('Posts', array(
'connectOptions' => array(
'routeClass' => 'TestPlugin.TestRoute',
'foo' => '^(bar)$',
),
));
$route = end(Router::$routes);
$this->assertInstanceOf('TestRoute', $route);
$this->assertEquals('^(bar)$', $route->options['foo']);
}

/**
* Test mapResources with a plugin and prefix.
*
Expand Down

0 comments on commit 8e5a9cd

Please sign in to comment.