Permalink
Browse files

Documenting change in thrown exception, adding test, loading exceptio…

…n without requiring autoloading.
  • Loading branch information...
1 parent 77b1484 commit 182e424256f3a82b831abbf7be07c3fd7a61c17b @deceze committed Feb 26, 2013
Showing with 17 additions and 3 deletions.
  1. +1 −0 Router.php
  2. +8 −3 readme.md
  3. +8 −0 tests/RouterTest.php
View
@@ -197,6 +197,7 @@ public function routeMethod($method, $url, $noMatch = null) {
return call_user_func($noMatch, $url);
}
+ require_once __DIR__ . DIRECTORY_SEPARATOR . 'NotFoundException.php';
@K-Phoen
K-Phoen Feb 26, 2013 Contributor

Why not relying on the autoloading?

@deceze
deceze Feb 26, 2013 Owner

Because the library isn't designed to so far.

In practice I do use autoloading exclusively, so I may break this dependency in a future version, together with some reorganization of directories.

throw new NotFoundException("No route matched $url");
}
View
@@ -336,22 +336,22 @@ $r->add('/foo');
This is powerful behavior, but also tricky. Generally you should define your specific, narrow routes before the broad catch-all routes.
-If no route matched a given URL, a `RuntimeException` is thrown. Alternatively you can pass a callback as second argument to `Router::route`, which will be called in case no URL matched:
+If no route matched a given URL, a `NotFoundException` is thrown. Alternatively you can pass a callback as second argument to `Router::route`, which will be called in case no URL matched:
```php
$r->route($_GET['url'], function ($url) {
die("404: $url not found");
});
```
-No `RuntimeException` will be thrown in this case.
+No `NotFoundException` will be thrown in this case.
This gives you several different strategies for dealing with non-matches. You can catch the thrown exception:
```php
try {
$r->route($_GET['url']);
-} catch (RuntimeException $e) {
+} catch (Kunststube\Router\NotFoundException $e) {
die($e->getMessage());
}
```
@@ -610,6 +610,11 @@ Web: http://kunststube.net, https://github.com/deceze/Kunststube-Router
Version history
---------------
+### 0.2.1
+
+Changed thrown exception to specialized NotFoundException in case no route matched.
+Thanks Kévin Gomez (K-Phoen).
+
### 0.2
Added APIs for routing by request method.
@@ -175,5 +175,13 @@ public function testMethodStringRouting() {
$r->addMethod($r::POST, '/*', array(), array($callbackMock, 'callback'));
$r->routeMethodFromString('POST', '/foo');
}
+
+ /**
+ * @expectedException Kunststube\Router\NotFoundException
+ */
+ public function testNoRouteMatchException() {
+ $r = new Router;
+ $r->route('/foo');
+ }
}

0 comments on commit 182e424

Please sign in to comment.