Skip to content

Commit

Permalink
Throw web.NotFound instead of using deprecated web.routing package
Browse files Browse the repository at this point in the history
  • Loading branch information
thekid committed Apr 6, 2024
1 parent 4ecc704 commit 8d67046
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 10 additions & 0 deletions src/main/php/web/NotFound.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php namespace web;

class NotFound extends Error {
public $path;

public function __construct($path, $cause= null) {
parent::__construct(404, 'Cannot find '.$path, $cause);
$this->path= $path;
}
}
6 changes: 3 additions & 3 deletions src/main/php/web/Routes.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ public function default($target) {

/**
* Routes a request to the handler specified by this routing instance's
* routes. Throws a `CannotRoute` error if not route is matched and no
* routes. Throws a `NotFound` error if not route is matched and no
* default route exists.
*
* @param web.Request $request
* @return web.Handler
* @throws web.CannotRoute
* @throws web.NotFound
*/
public function target($request) {
$match= $request->method().' '.rtrim($request->uri()->path(), '/').'/';
Expand All @@ -100,7 +100,7 @@ public function target($request) {
}
if ($this->default) return $this->default;

throw new CannotRoute($request);
throw new NotFound($request->uri()->path());
}

/**
Expand Down

0 comments on commit 8d67046

Please sign in to comment.