mirror of
https://github.com/kamilwylegala/cakephp2-php8.git
synced 2024-11-15 03:18:26 +00:00
Making Router throw exceptions when invalid route classes are used for routes.
This commit is contained in:
parent
e896901595
commit
797fa0009a
2 changed files with 17 additions and 5 deletions
|
@ -269,11 +269,9 @@ class Router {
|
|||
$routeClass = $options['routeClass'];
|
||||
unset($options['routeClass']);
|
||||
}
|
||||
//TODO 2.0 refactor this to use a string class name, throw exception, and then construct.
|
||||
$Route =& new $routeClass($route, $defaults, $options);
|
||||
if ($routeClass !== 'CakeRoute' && !is_subclass_of($Route, 'CakeRoute')) {
|
||||
trigger_error(__('Route classes must extend CakeRoute'), E_USER_WARNING);
|
||||
return false;
|
||||
$Route = new $routeClass($route, $defaults, $options);
|
||||
if (!$Route instanceof CakeRoute) {
|
||||
throw new Exception(__('Route classes must extend CakeRoute'));
|
||||
}
|
||||
$self->routes[] =& $Route;
|
||||
return $self->routes;
|
||||
|
|
|
@ -1910,6 +1910,20 @@ class RouterTest extends CakeTestCase {
|
|||
$this->assertEqual($result, $expected);
|
||||
}
|
||||
|
||||
/**
|
||||
* test that route classes must extend CakeRoute
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
function testCustomRouteException() {
|
||||
try {
|
||||
Router::connect('/:controller', array(), array('routeClass' => 'Object'));
|
||||
$this->$this->assertFalse(true, 'No exception thrown when an invalid class was used.');
|
||||
} catch (Exception $e) {
|
||||
$this->assertTrue(true, 'Exception correctly thrown');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* test reversing parameter arrays back into strings.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue