mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Accept 'connectOptions' in Router::mapResources()
This commit is contained in:
parent
4e74b93106
commit
8e5a9cd7da
2 changed files with 29 additions and 1 deletions
|
@ -500,11 +500,14 @@ class Router {
|
||||||
public static function mapResources($controller, $options = array()) {
|
public static function mapResources($controller, $options = array()) {
|
||||||
$hasPrefix = isset($options['prefix']);
|
$hasPrefix = isset($options['prefix']);
|
||||||
$options = array_merge(array(
|
$options = array_merge(array(
|
||||||
|
'connectOptions' => array(),
|
||||||
'prefix' => '/',
|
'prefix' => '/',
|
||||||
'id' => self::ID . '|' . self::UUID
|
'id' => self::ID . '|' . self::UUID
|
||||||
), $options);
|
), $options);
|
||||||
|
|
||||||
$prefix = $options['prefix'];
|
$prefix = $options['prefix'];
|
||||||
|
$connectOptions = $options['connectOptions'];
|
||||||
|
unset($options['connectOptions']);
|
||||||
|
|
||||||
foreach ((array)$controller as $name) {
|
foreach ((array)$controller as $name) {
|
||||||
list($plugin, $name) = pluginSplit($name);
|
list($plugin, $name) = pluginSplit($name);
|
||||||
|
@ -524,7 +527,10 @@ class Router {
|
||||||
'action' => $params['action'],
|
'action' => $params['action'],
|
||||||
'[method]' => $params['method']
|
'[method]' => $params['method']
|
||||||
),
|
),
|
||||||
array('id' => $options['id'], 'pass' => array('id'))
|
array_merge(
|
||||||
|
array('id' => $options['id'], 'pass' => array('id')),
|
||||||
|
$connectOptions
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
self::$_resourceMapped[] = $urlName;
|
self::$_resourceMapped[] = $urlName;
|
||||||
|
|
|
@ -179,6 +179,28 @@ class RouterTest extends CakeTestCase {
|
||||||
$this->assertEquals($expected, $result);
|
$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.
|
* Test mapResources with a plugin and prefix.
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in a new issue