mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Fixed typo in DocBlock
Router::defaultRouteClass will return the current routeClass if null is passed Router::connect and Router::defaultRouteClass both validate the routeClass now using Router::_validateRouteClass
This commit is contained in:
parent
b14072aa6f
commit
f5b62eb84c
2 changed files with 73 additions and 13 deletions
|
@ -160,13 +160,32 @@ class Router {
|
|||
protected static $_routeClass = 'CakeRoute';
|
||||
|
||||
/**
|
||||
* Set the default rotue class to use
|
||||
* Set the default route class to use or return the current one
|
||||
*
|
||||
* @param sting $routeClass to set as default
|
||||
* @return void
|
||||
* @param string $routeClass to set as default
|
||||
* @return mixed void|string
|
||||
* @throws RouterException
|
||||
*/
|
||||
public static function defaultRouteClass($routeClass) {
|
||||
self::$_routeClass = $routeClass;
|
||||
public static function defaultRouteClass($routeClass = null) {
|
||||
if (is_null($routeClass)) {
|
||||
return self::$_routeClass;
|
||||
}
|
||||
|
||||
self::$_routeClass = self::_validateRouteClass($routeClass);
|
||||
}
|
||||
|
||||
/**
|
||||
* Validates that the passed route class exists and is a subclass of CakeRoute
|
||||
*
|
||||
* @param $routeClass
|
||||
* @return string
|
||||
* @throws RouterException
|
||||
*/
|
||||
protected static function _validateRouteClass($routeClass) {
|
||||
if (!class_exists($routeClass) || !is_subclass_of($routeClass, 'CakeRoute')) {
|
||||
throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute'));
|
||||
}
|
||||
return $routeClass;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -278,15 +297,12 @@ class Router {
|
|||
}
|
||||
$routeClass = self::$_routeClass;
|
||||
if (isset($options['routeClass'])) {
|
||||
$routeClass = $options['routeClass'];
|
||||
if (!is_subclass_of($routeClass, 'CakeRoute')) {
|
||||
throw new RouterException(__d('cake_dev', 'Route classes must extend CakeRoute'));
|
||||
}
|
||||
$routeClass = self::_validateRouteClass($options['routeClass']);
|
||||
unset($options['routeClass']);
|
||||
}
|
||||
if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) {
|
||||
$defaults = $defaults['redirect'];
|
||||
}
|
||||
}
|
||||
self::$routes[] = new $routeClass($route, $defaults, $options);
|
||||
return self::$routes;
|
||||
}
|
||||
|
|
|
@ -2519,4 +2519,48 @@ class RouterTest extends CakeTestCase {
|
|||
$this->assertInstanceOf('TestDefaultRouteClass', $result[0]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Test getting the default route class
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function testDefaultRouteClassGetter() {
|
||||
$routeClass = 'TestDefaultRouteClass';
|
||||
Router::defaultRouteClass($routeClass);
|
||||
|
||||
$this->assertEqual($routeClass, Router::defaultRouteClass());
|
||||
$this->assertEqual($routeClass, Router::defaultRouteClass(null));
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that route classes must extend CakeRoute
|
||||
*
|
||||
* @expectedException RouterException
|
||||
* @return void
|
||||
*/
|
||||
public function testDefaultRouteException() {
|
||||
Router::defaultRouteClass('');
|
||||
Router::connect('/:controller', array());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that route classes must extend CakeRoute
|
||||
*
|
||||
* @expectedException RouterException
|
||||
* @return void
|
||||
*/
|
||||
public function testSettingInvalidDefaultRouteException() {
|
||||
Router::defaultRouteClass('Object');
|
||||
}
|
||||
|
||||
/**
|
||||
* Test that class must exist
|
||||
*
|
||||
* @expectedException RouterException
|
||||
* @return void
|
||||
*/
|
||||
public function testSettingNonExistentDefaultRouteException() {
|
||||
Router::defaultRouteClass('NonExistentClass');
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue