Accept 'connectOptions' in Router::mapResources()

This commit is contained in:
Rachman Chavik 2013-07-26 20:12:20 +07:00
parent 4e74b93106
commit 8e5a9cd7da
2 changed files with 29 additions and 1 deletions

View file

@ -500,11 +500,14 @@ class Router {
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);
@ -524,7 +527,10 @@ class Router {
'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;

View file

@ -179,6 +179,28 @@ class RouterTest extends CakeTestCase {
$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.
*