mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Add Router::defaultRouteClass()
Apply patch from 'Tigran Gabrielyan'. Allows you to set the default route class used for all future routes. Fixes #2435
This commit is contained in:
parent
b76f8f8832
commit
b14072aa6f
2 changed files with 31 additions and 1 deletions
|
@ -152,6 +152,23 @@ class Router {
|
||||||
*/
|
*/
|
||||||
protected static $_initialState = array();
|
protected static $_initialState = array();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Default route class to use
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected static $_routeClass = 'CakeRoute';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the default rotue class to use
|
||||||
|
*
|
||||||
|
* @param sting $routeClass to set as default
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function defaultRouteClass($routeClass) {
|
||||||
|
self::$_routeClass = $routeClass;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the Routing prefixes.
|
* Sets the Routing prefixes.
|
||||||
*
|
*
|
||||||
|
@ -259,7 +276,7 @@ class Router {
|
||||||
if (empty($options['action'])) {
|
if (empty($options['action'])) {
|
||||||
$defaults += array('action' => 'index');
|
$defaults += array('action' => 'index');
|
||||||
}
|
}
|
||||||
$routeClass = 'CakeRoute';
|
$routeClass = self::$_routeClass;
|
||||||
if (isset($options['routeClass'])) {
|
if (isset($options['routeClass'])) {
|
||||||
$routeClass = $options['routeClass'];
|
$routeClass = $options['routeClass'];
|
||||||
if (!is_subclass_of($routeClass, 'CakeRoute')) {
|
if (!is_subclass_of($routeClass, 'CakeRoute')) {
|
||||||
|
|
|
@ -2506,4 +2506,17 @@ class RouterTest extends CakeTestCase {
|
||||||
$this->assertEquals(Router::$routes[0]->response->header(), array());
|
$this->assertEquals(Router::$routes[0]->response->header(), array());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test setting the default route class
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function testDefaultRouteClass() {
|
||||||
|
$this->getMock('CakeRoute', array(), array('/test'), 'TestDefaultRouteClass');
|
||||||
|
Router::defaultRouteClass('TestDefaultRouteClass');
|
||||||
|
|
||||||
|
$result = Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
|
||||||
|
$this->assertInstanceOf('TestDefaultRouteClass', $result[0]);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue