Skip to content

Commit

Permalink
fix: Move the condition into AutoRouter.php from CodeIgniter.php.
Browse files Browse the repository at this point in the history
  • Loading branch information
ping-yee committed Sep 22, 2023
1 parent 47674e8 commit c780a23
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 19 deletions.
20 changes: 1 addition & 19 deletions system/CodeIgniter.php
Original file line number Diff line number Diff line change
Expand Up @@ -451,7 +451,7 @@ protected function handleRequest(?RouteCollectionInterface $routes, Cache $cache

$uri = $this->determinePath();

if ($this->enableFilters && $this->checkControllerNotFoundBeforeFilter()) {
if ($this->enableFilters) {
// Start up the filters
$filters = Services::filters();

Expand Down Expand Up @@ -1159,22 +1159,4 @@ protected function outputBufferingEnd(): string

return $buffer;
}

/**
* Check whether the controller is not found before the before filter.
*/
protected function checkControllerNotFoundBeforeFilter(): bool
{
// Check whether the controller type is Closure.
if (is_object($this->controller) && (get_class($this->controller) === 'Closure')) {
return true;
}

// Try to autoload the class
if (! class_exists($this->controller, true) || $this->method[0] === '_') {
throw PageNotFoundException::forControllerNotFound($this->controller, $this->method);
}

return true;
}
}
5 changes: 5 additions & 0 deletions system/Router/AutoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,11 @@ public function getRoute(string $uri, string $httpVerb): array
);
}

// Check if the controller exists.
if (! class_exists($this->controller, true) || $this->method[0] === '_') {
throw PageNotFoundException::forControllerNotFound($this->controller, $this->method);
}

return [$this->directory, $this->controllerName(), $this->methodName(), $params];
}

Expand Down
2 changes: 2 additions & 0 deletions user_guide_src/source/changelogs/v4.4.2.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ Release Date: Unreleased
BREAKING
********

- **AutoRouting Legacy:** Add a condition to check if the controller exists.

Message Changes
***************

Expand Down

0 comments on commit c780a23

Please sign in to comment.