Skip to content

Commit

Permalink
Remove use of RouterException.
Browse files Browse the repository at this point in the history
* It was never really needed and just using the basic exception will
  work just fine.
* Update the doc blocks for a few methods.
  • Loading branch information
markstory committed Jul 10, 2012
1 parent ac87e5c commit bae8a9b
Showing 1 changed file with 41 additions and 18 deletions.
59 changes: 41 additions & 18 deletions lib/Cake/Routing/Router.php
@@ -1,9 +1,5 @@
<?php
/**
* Parses the request URL into controller, action, and parameters.
*
* PHP 5
*
* CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
* Copyright 2005-2012, Cake Software Foundation, Inc. (http://cakefoundation.org)
*
Expand Down Expand Up @@ -148,7 +144,7 @@ class Router {
*
* @param string $routeClass to set as default
* @return mixed void|string
* @throws RouterException
* @throws Cake\Error\Exception
*/
public static function defaultRouteClass($routeClass = null) {
if (is_null($routeClass)) {
Expand All @@ -163,11 +159,11 @@ public static function defaultRouteClass($routeClass = null) {
*
* @param $routeClass
* @return string
* @throws RouterException
* @throws Cake\Error\Exception
*/
protected static function _validateRouteClass($routeClass) {
if (!class_exists($routeClass) || !is_subclass_of($routeClass, 'Cake\Routing\Route\Route')) {
throw new Error\RouterException(__d('cake_dev', 'Route classes must extend Cake\Routing\Route\Route'));
throw new Error\Exception(__d('cake_dev', 'Route classes must extend Cake\Routing\Route\Route'));
}
return $routeClass;
}
Expand All @@ -185,7 +181,7 @@ protected static function _setPrefixes() {
}

/**
* Gets the named route elements for use in app/Config/routes.php
* Gets the named route patterns for use in app/Config/routes.php
*
* @return array Named route elements
* @see Router::$_namedExpressions
Expand All @@ -197,6 +193,9 @@ public static function getNamedExpressions() {
/**
* Resource map getter & setter.
*
* Allows you to define the default route configuration for REST routing and
* Router::mapResources()
*
* @param array $resourceMap Resource map
* @return mixed
* @see Router::$_resourceMap
Expand Down Expand Up @@ -263,7 +262,7 @@ public static function resourceMap($resourceMap = null) {
* custom routing class.
* @see routes
* @return void
* @throws RouterException
* @throws Cake\Error\Exception
*/
public static function connect($route, $defaults = array(), $options = array()) {
if (!empty($defaults['prefix'])) {
Expand Down Expand Up @@ -333,9 +332,35 @@ public static function redirect($route, $url, $options = array()) {
}

/**
* Creates REST resource routes for the given controller(s). When creating resource routes
* for a plugin, by default the prefix will be changed to the lower_underscore version of the plugin
* name. By providing a prefix you can override this behavior.
* Creates REST resource routes for the given controller(s).
*
* ### Usage
*
* Connect resource routes for an app controller:
*
* {{{
* Router::mapResources('Posts');
* }}}
*
* Connect resource routes for the Comment controller in the
* Comments plugin:
*
* {{{
* Router::mapResources('Comments.Comment');
* }}}
*
* Plugins will create lower_case underscored resource routes. e.g
* `/comments/comment`
*
* Connect resource routes for the Posts controller in the
* Admin prefix:
*
* {{{
* Router::mapResources('Posts', ['prefix' => 'admin']);
* }}}
*
* Prefixes will create lower_case underscored resource routes. e.g
* `/admin/posts`
*
* ### Options:
*
Expand All @@ -354,7 +379,6 @@ public static function mapResources($controller, $options = array()) {
'id' => static::ID . '|' . static::UUID
), $options);


foreach ((array)$controller as $name) {
list($plugin, $name) = pluginSplit($name);
$urlName = Inflector::underscore($name);
Expand Down Expand Up @@ -637,8 +661,6 @@ public static function url($url = null, $options = array()) {
$hasLeadingSlash = isset($url[0]) ? $url[0] === '/' : false;
}

// TODO refactor so there is less overhead
// incurred on each URL generated.
$request = static::getRequest(true);
if ($request) {
$params = $request->params;
Expand Down Expand Up @@ -754,9 +776,10 @@ public static function url($url = null, $options = array()) {
* This will strip out 'autoRender', 'bare', 'requested', and 'return' param names as those
* are used for CakePHP internals and should not normally be part of an output url.
*
* @param Cake\Network\Request|array $params The params array or Cake\Network\Request object that needs to be reversed.
* @param boolean $full Set to true to include the full url including the protocol when reversing
* the url.
* @param Cake\Network\Request|array $params The params array or
* Cake\Network\Request object that needs to be reversed.
* @param boolean $full Set to true to include the full url including the
* protocol when reversing the url.
* @return string The string that is the reversed result of the array
*/
public static function reverse($params, $full = false) {
Expand Down

0 comments on commit bae8a9b

Please sign in to comment.