Skip to content
Permalink
Browse files

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
  • Loading branch information...
tigrang committed Jan 13, 2012
1 parent b14072a commit f5b62eb84c5f854c4d0dda337b950dbffc482685
Showing with 73 additions and 13 deletions.
  1. +29 −13 lib/Cake/Routing/Router.php
  2. +44 −0 lib/Cake/Test/Case/Routing/RouterTest.php
@@ -160,14 +160,33 @@ 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;
}
/**
* Sets the Routing prefixes.
@@ -278,14 +297,11 @@ public static function connect($route, $defaults = array(), $options = array())
}
$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'];
}
}
if ($routeClass == 'RedirectRoute' && isset($defaults['redirect'])) {
$defaults = $defaults['redirect'];
}
self::$routes[] = new $routeClass($route, $defaults, $options);
return self::$routes;
@@ -2519,4 +2519,48 @@ public function testDefaultRouteClass() {
$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');
}
}

0 comments on commit f5b62eb

Please sign in to comment.
You can’t perform that action at this time.