Skip to content

Commit

Permalink
Update Router.php
Browse files Browse the repository at this point in the history
  • Loading branch information
PlanetTheCloud committed Oct 20, 2020
1 parent 38042be commit 9a58e68
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/Bramus/Router/Router.php
Original file line number Diff line number Diff line change
Expand Up @@ -289,11 +289,7 @@ public function run($callback = null)

// If no route was handled, trigger the 404 (if any)
if ($numHandled === 0) {
if ($this->notFoundCallback) {
$this->invoke($this->notFoundCallback);
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
}
$this->return404();
} // If a route was handled, perform the finish callback (if any)
else {
if ($callback && is_callable($callback)) {
Expand All @@ -320,6 +316,17 @@ public function set404($fn)
$this->notFoundCallback = $fn;
}

/**
* Triggers 404 response
*/
public function return404(){
if ($this->notFoundCallback) {
$this->invoke($this->notFoundCallback);
} else {
header($_SERVER['SERVER_PROTOCOL'] . ' 404 Not Found');
}
}

/**
* Handle a a set of routes: if a match is found, execute the relating handling function.
*
Expand Down

0 comments on commit 9a58e68

Please sign in to comment.