Browse Source

Routing\Error -> Routing\Exception

Jose Lorenzo Rodriguez 11 years ago
parent
commit
5840bf2a7b

+ 3 - 3
src/Routing/Dispatcher.php

@@ -20,13 +20,13 @@ use Cake\Event\EventListener;
 use Cake\Event\EventManagerTrait;
 use Cake\Network\Request;
 use Cake\Network\Response;
-use Cake\Routing\Error\MissingControllerException;
+use Cake\Routing\Exception\MissingControllerException;
 use LogicException;
 
 /**
  * Dispatcher converts Requests into controller actions. It uses the dispatched Request
  * to locate and load the correct controller. If found, the requested action is called on
- * the controller.
+ * the controller
  *
  */
 class Dispatcher {
@@ -55,7 +55,7 @@ class Dispatcher {
  * @param \Cake\Network\Request $request Request object to dispatch.
  * @param \Cake\Network\Response $response Response object to put the results of the dispatch into.
  * @return string|void if `$request['return']` is set then it returns response body, null otherwise
- * @throws \Cake\Routing\Error\MissingControllerException When the controller is missing.
+ * @throws \Cake\Routing\Exception\MissingControllerException When the controller is missing.
  */
 	public function dispatch(Request $request, Response $response) {
 		$beforeEvent = new Event('Dispatcher.beforeDispatch', $this, compact('request', 'response'));

+ 2 - 2
src/Routing/DispatcherFactory.php

@@ -16,7 +16,7 @@ namespace Cake\Routing;
 
 use Cake\Core\App;
 use Cake\Routing\Dispatcher;
-use Cake\Routing\Error\MissingDispatcherFilterException;
+use Cake\Routing\Exception\MissingDispatcherFilterException;
 
 /**
  * A factory for creating dispatchers with all the desired middleware
@@ -58,7 +58,7 @@ class DispatcherFactory {
  * @param string $name The name of the filter to build.
  * @param array $options Constructor arguments/options for the filter.
  * @return \Cake\Routing\DispatcherFilter
- * @throws \Cake\Routing\Error\MissingDispatcherFilterException When filters cannot be found.
+ * @throws \Cake\Routing\Exception\MissingDispatcherFilterException When filters cannot be found.
  */
 	protected static function _createFilter($name, $options) {
 		$className = App::className($name, 'Routing/Filter', 'Filter');

+ 3 - 3
src/Routing/DispatcherFilter.php

@@ -14,10 +14,10 @@
  */
 namespace Cake\Routing;
 
-use Cake\Core\Exception\Exception;
 use Cake\Core\InstanceConfigTrait;
 use Cake\Event\Event;
 use Cake\Event\EventListener;
+use InvalidArgumentException;
 
 /**
  * This abstract class represents a filter to be applied to a dispatcher cycle. It acts as as
@@ -94,7 +94,7 @@ class DispatcherFilter implements EventListener {
  * Constructor.
  *
  * @param array $config Settings for the filter.
- * @throws \Cake\Core\Exception\Exception When 'when' conditions are not callable.
+ * @throws \InvalidArgumentException When 'when' conditions are not callable.
  */
 	public function __construct($config = []) {
 		if (!isset($config['priority'])) {
@@ -102,7 +102,7 @@ class DispatcherFilter implements EventListener {
 		}
 		$this->config($config);
 		if (isset($config['when']) && !is_callable($config['when'])) {
-			throw new Exception('"when" conditions must be a callable.');
+			throw new InvalidArgumentException('"when" conditions must be a callable.');
 		}
 	}
 

+ 1 - 1
src/Routing/Error/MissingControllerException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\Routing\Error;
+namespace Cake\Routing\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/Routing/Error/MissingDispatcherFilterException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\Routing\Error;
+namespace Cake\Routing\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 1 - 1
src/Routing/Error/MissingRouteException.php

@@ -11,7 +11,7 @@
  * @since         3.0.0
  * @license       http://www.opensource.org/licenses/mit-license.php MIT License
  */
-namespace Cake\Routing\Error;
+namespace Cake\Routing\Exception;
 
 use Cake\Core\Exception\Exception;
 

+ 12 - 7
src/Routing/RouteBuilder.php

@@ -14,11 +14,12 @@
  */
 namespace Cake\Routing;
 
+use BadMethodCallException;
 use Cake\Core\App;
-use Cake\Core\Exception\Exception;
-use Cake\Routing\Router;
 use Cake\Routing\Route\Route;
+use Cake\Routing\Router;
 use Cake\Utility\Inflector;
+use InvalidArgumentException;
 
 /**
  * Provides features for building routes inside scopes.
@@ -310,7 +311,8 @@ class RouteBuilder {
  *   shifted into the passed arguments, supplying patterns for routing parameters and supplying the name of a
  *   custom routing class.
  * @return void
- * @throws \Cake\Core\Exception\Exception
+ * @throws \InvalidArgumentException
+ * @throws \BadMethodCallException
  */
 	public function connect($route, array $defaults = [], $options = []) {
 		if (empty($options['action'])) {
@@ -332,7 +334,8 @@ class RouteBuilder {
  * @param array $defaults Default parameters.
  * @param array $options Additional options parameters.
  * @return \Cake\Routing\Route\Route
- * @throws \Cake\Core\Exception\Exception when route class or route object is invalid.
+ * @throws \InvalidArgumentException when route class or route object is invalid.
+ * @throws \BadMethodCallException when the route to make conflicts with the current scope
  */
 	protected function _makeRoute($route, $defaults, $options) {
 		if (is_string($route)) {
@@ -341,7 +344,7 @@ class RouteBuilder {
 				$routeClass = App::className($options['routeClass'], 'Routing/Route');
 			}
 			if ($routeClass === false) {
-				throw new Exception(sprintf('Cannot find route class %s', $options['routeClass']));
+				throw new InvalidArgumentException(sprintf('Cannot find route class %s', $options['routeClass']));
 			}
 			unset($options['routeClass']);
 
@@ -352,7 +355,7 @@ class RouteBuilder {
 				if (isset($defaults[$param]) && $defaults[$param] !== $val) {
 					$msg = 'You cannot define routes that conflict with the scope. ' .
 						'Scope had %s = %s, while route had %s = %s';
-					throw new Exception(sprintf(
+					throw new BadMethodCallException(sprintf(
 						$msg,
 						$param,
 						$val,
@@ -370,7 +373,9 @@ class RouteBuilder {
 		if ($route instanceof Route) {
 			return $route;
 		}
-		throw new Exception('Route class not found, or route class is not a subclass of Cake\Routing\Route\Route');
+		throw new InvalidArgumentException(
+			'Route class not found, or route class is not a subclass of Cake\Routing\Route\Route'
+		);
 	}
 
 /**

+ 3 - 3
src/Routing/RouteCollection.php

@@ -16,7 +16,7 @@ namespace Cake\Routing;
 
 use Cake\Core\App;
 use Cake\Error;
-use Cake\Routing\Error\MissingRouteException;
+use Cake\Routing\Exception\MissingRouteException;
 use Cake\Routing\Router;
 use Cake\Routing\Route\Route;
 use Cake\Utility\Inflector;
@@ -108,7 +108,7 @@ class RouteCollection {
  *
  * @param string $url URL to parse.
  * @return array An array of request parameters parsed from the URL.
- * @throws \Cake\Routing\Error\MissingRouteException When a URL has no matching route.
+ * @throws \Cake\Routing\Exception\MissingRouteException When a URL has no matching route.
  */
 	public function parse($url) {
 		foreach (array_keys($this->_paths) as $path) {
@@ -224,7 +224,7 @@ class RouteCollection {
  * @param array $context The request context to use. Contains _base, _port,
  *    _host, and _scheme keys.
  * @return string|false Either a string on match, or false on failure.
- * @throws \Cake\Routing\Error\MissingRouteException when a route cannot be matched.
+ * @throws \Cake\Routing\Exception\MissingRouteException when a route cannot be matched.
  */
 	public function match($url, $context) {
 		// Named routes support optimization.

+ 1 - 1
src/Routing/Router.php

@@ -283,7 +283,7 @@ class Router {
  *
  * @param string $url URL to be parsed
  * @return array Parsed elements from URL
- * @throws \Cake\Routing\Error\MissingRouteException When a route cannot be handled
+ * @throws \Cake\Routing\Exception\MissingRouteException When a route cannot be handled
  */
 	public static function parse($url) {
 		if (!static::$initialized) {

+ 1 - 1
tests/TestCase/Error/ExceptionRendererTest.php

@@ -34,7 +34,7 @@ use Cake\Network\Exception\NotFoundException;
 use Cake\Network\Exception\SocketException;
 use Cake\Network\Request;
 use Cake\ORM\Error\MissingBehaviorException;
-use Cake\Routing\Error\MissingControllerException;
+use Cake\Routing\Exception\MissingControllerException;
 use Cake\Routing\Router;
 use Cake\TestSuite\TestCase;
 use Cake\View\Exception\MissingHelperException;

+ 1 - 1
tests/TestCase/Routing/DispatcherFactoryTest.php

@@ -56,7 +56,7 @@ class DispatcherFactoryTest extends TestCase {
 /**
  * Test add filter missing
  *
- * @expectedException Cake\Routing\Error\MissingDispatcherFilterException
+ * @expectedException Cake\Routing\Exception\MissingDispatcherFilterException
  * @return void
  */
 	public function testAddFilterMissing() {

+ 1 - 1
tests/TestCase/Routing/DispatcherFilterTest.php

@@ -63,7 +63,7 @@ class DispatcherFilterTest extends TestCase {
 /**
  * Test constructor error invalid when
  *
- * @expectedException Cake\Core\Exception\Exception
+ * @expectedException InvalidArgumentException
  * @expectedExceptionMessage "when" conditions must be a callable.
  * @return void
  */

+ 3 - 4
tests/TestCase/Routing/DispatcherTest.php

@@ -17,7 +17,6 @@ use Cake\Controller\Controller;
 use Cake\Core\App;
 use Cake\Core\Configure;
 use Cake\Core\Plugin;
-use Cake\Error;
 use Cake\Event\Event;
 use Cake\Network\Request;
 use Cake\Network\Response;
@@ -232,7 +231,7 @@ class DispatcherTest extends TestCase {
 /**
  * testMissingController method
  *
- * @expectedException \Cake\Routing\Error\MissingControllerException
+ * @expectedException \Cake\Routing\Exception\MissingControllerException
  * @expectedExceptionMessage Controller class SomeController could not be found.
  * @return void
  */
@@ -251,7 +250,7 @@ class DispatcherTest extends TestCase {
 /**
  * testMissingControllerInterface method
  *
- * @expectedException \Cake\Routing\Error\MissingControllerException
+ * @expectedException \Cake\Routing\Exception\MissingControllerException
  * @expectedExceptionMessage Controller class DispatcherTestInterface could not be found.
  * @return void
  */
@@ -271,7 +270,7 @@ class DispatcherTest extends TestCase {
 /**
  * testMissingControllerInterface method
  *
- * @expectedException \Cake\Routing\Error\MissingControllerException
+ * @expectedException \Cake\Routing\Exception\MissingControllerException
  * @expectedExceptionMessage Controller class Abstract could not be found.
  * @return void
  */

+ 2 - 2
tests/TestCase/Routing/RouteBuilderTest.php

@@ -162,7 +162,7 @@ class RouteBuilderTest extends TestCase {
 /**
  * Test error on invalid route class
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException \InvalidArgumentException
  * @expectedExceptionMessage Route class not found, or route class is not a subclass of
  * @return void
  */
@@ -174,7 +174,7 @@ class RouteBuilderTest extends TestCase {
 /**
  * Test conflicting parameters raises an exception.
  *
- * @expectedException \Cake\Core\Exception\Exception
+ * @expectedException \BadMethodCallException
  * @expectedExceptionMessage You cannot define routes that conflict with the scope.
  * @return void
  */

+ 3 - 3
tests/TestCase/Routing/RouteCollectionTest.php

@@ -35,7 +35,7 @@ class RouteCollectionTest extends TestCase {
 /**
  * Test parse() throws an error on unknown routes.
  *
- * @expectedException Cake\Routing\Error\MissingRouteException
+ * @expectedException Cake\Routing\Exception\MissingRouteException
  * @expectedExceptionMessage A route matching "/" could not be found
  */
 	public function testParseMissingRoute() {
@@ -126,7 +126,7 @@ class RouteCollectionTest extends TestCase {
 /**
  * Test match() throws an error on unknown routes.
  *
- * @expectedException Cake\Routing\Error\MissingRouteException
+ * @expectedException Cake\Routing\Exception\MissingRouteException
  * @expectedExceptionMessage A route matching "array (
  */
 	public function testMatchError() {
@@ -191,7 +191,7 @@ class RouteCollectionTest extends TestCase {
 /**
  * Test matching routes with names and failing
  *
- * @expectedException Cake\Routing\Error\MissingRouteException
+ * @expectedException Cake\Routing\Exception\MissingRouteException
  * @return void
  */
 	public function testMatchNamedError() {

+ 6 - 6
tests/TestCase/Routing/RouterTest.php

@@ -1081,7 +1081,7 @@ class RouterTest extends TestCase {
 /**
  * Test that using invalid names causes exceptions.
  *
- * @expectedException \Cake\Routing\Error\MissingRouteException
+ * @expectedException \Cake\Routing\Exception\MissingRouteException
  * @return void
  */
 	public function testNamedRouteException() {
@@ -1493,7 +1493,7 @@ class RouterTest extends TestCase {
 /**
  * Test exceptions when parsing fails.
  *
- * @expectedException Cake\Routing\Error\MissingRouteException
+ * @expectedException Cake\Routing\Exception\MissingRouteException
  */
 	public function testParseError() {
 		Router::connect('/', ['controller' => 'Pages', 'action' => 'display', 'home']);
@@ -1993,7 +1993,7 @@ class RouterTest extends TestCase {
 /**
  * test that patterns work for :action
  *
- * @expectedException Cake\Routing\Error\MissingRouteException
+ * @expectedException Cake\Routing\Exception\MissingRouteException
  * @return void
  */
 	public function testParsingWithPatternOnAction() {
@@ -2018,7 +2018,7 @@ class RouterTest extends TestCase {
 /**
  * Test url() works with patterns on :action
  *
- * @expectedException Cake\Routing\Error\MissingRouteException
+ * @expectedException Cake\Routing\Exception\MissingRouteException
  * @return void
  */
 	public function testUrlPatternOnAction() {
@@ -2194,7 +2194,7 @@ class RouterTest extends TestCase {
 /**
  * testRegexRouteMatching error
  *
- * @expectedException Cake\Routing\Error\MissingRouteException
+ * @expectedException Cake\Routing\Exception\MissingRouteException
  * @return void
  */
 	public function testRegexRouteMatchingError() {
@@ -2205,7 +2205,7 @@ class RouterTest extends TestCase {
 /**
  * testRegexRouteMatching method
  *
- * @expectedException Cake\Routing\Error\MissingRouteException
+ * @expectedException Cake\Routing\Exception\MissingRouteException
  * @return void
  */
 	public function testRegexRouteMatchUrl() {