Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Accept 'connectOptions' in Router::mapResources()

  • Loading branch information...
commit 8e5a9cd7da8ca1be6168493ba5148e4aea0024e9 1 parent 4e74b93
@rchavik rchavik authored
View
8 lib/Cake/Routing/Router.php
@@ -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);
@@ -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;
View
22 lib/Cake/Test/Case/Routing/RouterTest.php
@@ -180,6 +180,28 @@ public function testPluginMapResources() {
}
/**
+ * 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.
*
* @return void
Please sign in to comment.
Something went wrong with that request. Please try again.