-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: auto routing legacy and $route->add() #7690
fix: auto routing legacy and $route->add() #7690
Conversation
ed8bfd6
to
72a32c2
Compare
system/Router/AutoRouter.php
Outdated
|
||
foreach ($this->protectedControllers as $controllerInRoute) { | ||
if (! is_string($controllerInRoute)) { | ||
continue; | ||
} | ||
if (strtolower($controllerInRoute) !== $controller) { | ||
continue; | ||
$methodName = strtolower($this->methodName()); | ||
|
||
foreach ($this->cliRoutes as $handler) { | ||
if (is_string($handler)) { | ||
$handler = strtolower($handler); | ||
|
||
if (strpos($handler, $controller . '::' . $methodName) === 0) { | ||
throw new PageNotFoundException( | ||
'Cannot access CLI Route: ' . $uri | ||
); | ||
} | ||
|
||
if ($handler === $controller) { | ||
throw new PageNotFoundException( | ||
'Cannot access CLI Route: ' . $uri | ||
); | ||
} | ||
} | ||
|
||
throw new PageNotFoundException( | ||
'Cannot access the controller in a CLI Route. Controller: ' . $controllerInRoute | ||
); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I restored the logic from v4.1.9:
CodeIgniter4/system/Router/Router.php
Lines 492 to 513 in 202f41a
if ($this->collection->getHTTPVerb() !== 'cli') { | |
$controller = '\\' . $defaultNamespace; | |
$controller .= $this->directory ? str_replace('/', '\\', $this->directory) : ''; | |
$controller .= $controllerName; | |
$controller = strtolower($controller); | |
$methodName = strtolower($this->methodName()); | |
foreach ($this->collection->getRoutes('cli') as $route) { | |
if (is_string($route)) { | |
$route = strtolower($route); | |
if (strpos($route, $controller . '::' . $methodName) === 0) { | |
throw new PageNotFoundException(); | |
} | |
if ($route === $controller) { | |
throw new PageNotFoundException(); | |
} | |
} | |
} | |
} |
6dffdac
to
94843ff
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One naming comment, I'm fine either way.
If you $routes->add(), the controller was inaccessible with auto-routing legacy.
94843ff
to
3c9cde7
Compare
3c9cde7
to
bed018a
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome looking forward ⏩ to 4.3.7
Description
See https://forum.codeigniter.com/showthread.php?tid=86977
There is a bug:
$route->add()
, the controller's other methods are inaccessible from the web browser.How to Test
Navigate to:
Checklist: