Skip to content
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

feat: new improved auto router #5889

Merged
merged 30 commits into from
May 3, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
680f9ff
feat: add AutoRouterImproved class
kenjis Apr 8, 2022
fd4f9b8
feat: add param checking
kenjis Apr 9, 2022
a5f8d80
test: add test for POST method
kenjis Apr 9, 2022
bdac511
refactor: improve exception messages
kenjis Apr 9, 2022
d7d5174
refactor: fix classnames and method names
kenjis Apr 9, 2022
b691387
test: rename Controllers/Test
kenjis Apr 10, 2022
dcd8ba7
feat: AutoRouterImproved does not support _remap()
kenjis Apr 10, 2022
8e89710
refactor: extract protectDefinedCliRoutes() method
kenjis Apr 10, 2022
f0f212b
fix: update __construct() and protectDefinedCliRoutes() in AutoRouter…
kenjis Apr 12, 2022
3fd4182
chore: updatte phpstan-baseline.neon.dist
kenjis Apr 12, 2022
ddfa0d7
docs: add @var
kenjis Apr 12, 2022
c253b61
refactor: rename method name
kenjis Apr 12, 2022
a090a64
test: fix tests
kenjis Apr 12, 2022
8f3365a
refactor: vendor/bin/rector process
kenjis Apr 12, 2022
9fc97e7
refactor: add return types
kenjis Apr 12, 2022
3cff22c
test: remove using BaseController because of rector's error
kenjis Apr 13, 2022
c8b1e41
refactor: vendor/bin/rector process
kenjis Apr 13, 2022
e6eaf71
test: fix tests that rector broke
kenjis Apr 13, 2022
97dcb46
fix: protectDefinedRoutes()
kenjis Apr 20, 2022
6d6ad00
docs: improve doc comment
kenjis Apr 20, 2022
6e454e5
refactor: add final to new classes that implements AutoRouterInterface
kenjis Apr 20, 2022
0ec9c06
docs: add @deprecated
kenjis Apr 20, 2022
83c4342
refactor: add property type
kenjis Apr 20, 2022
56f183c
docs: composer cs-fix
kenjis Apr 20, 2022
061984a
docs: add docs
kenjis Apr 26, 2022
2639a7f
docs: fix by proofreading
kenjis Apr 28, 2022
7b087b2
docs: fix typo
kenjis Apr 28, 2022
9e09097
docs: fix by proofreading
kenjis Apr 28, 2022
70f62aa
docs: replace Traditional with Legacy for auto-routing
kenjis Apr 28, 2022
2fe5107
test: run rector
kenjis May 3, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/Config/Feature.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
class Feature extends BaseConfig
{
/**
* Enable multiple filters for a route or not
* Enable multiple filters for a route or not.
*
* If you enable this:
* - CodeIgniter\CodeIgniter::handleRequest() uses:
Expand All @@ -24,4 +24,9 @@ class Feature extends BaseConfig
* @var bool
*/
public $multipleFilters = false;

/**
* Use improved new auto routing instead of the default legacy version.
*/
public bool $autoRoutesImproved = false;
}
6 changes: 3 additions & 3 deletions phpstan-baseline.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -677,7 +677,7 @@ parameters:

-
message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getDefaultNamespace\\(\\)\\.$#"
count: 2
count: 3
path: system/Router/Router.php

-
Expand Down Expand Up @@ -706,8 +706,8 @@ parameters:
path: system/Router/Router.php

-
message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getRegisteredControllers\\(\\)\\.$#"
count: 1
message: "#^Call to an undefined method CodeIgniter\\\\Router\\\\RouteCollectionInterface\\:\\:getRegisteredControllers\\(.*\\)\\.$#"
count: 2
path: system/Router/Router.php

-
Expand Down
26 changes: 17 additions & 9 deletions system/Router/AutoRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,44 +16,46 @@
/**
* Router for Auto-Routing
*/
class AutoRouter
final class AutoRouter implements AutoRouterInterface
MGatner marked this conversation as resolved.
Show resolved Hide resolved
{
/**
* List of controllers registered for the CLI verb that should not be accessed in the web.
*
* @var class-string[]
*/
protected array $protectedControllers;
private array $protectedControllers;

/**
* Sub-directory that contains the requested controller class.
* Primarily used by 'autoRoute'.
*/
protected ?string $directory = null;
private ?string $directory = null;

/**
* The name of the controller class.
*/
protected string $controller;
private string $controller;

/**
* The name of the method to use.
*/
protected string $method;
private string $method;

/**
* Whether dashes in URI's should be converted
* to underscores when determining method names.
*/
protected bool $translateURIDashes;
private bool $translateURIDashes;

/**
* HTTP verb for the request.
*/
protected string $httpVerb;
private string $httpVerb;

/**
* Default namespace for controllers.
*/
protected string $defaultNamespace;
private string $defaultNamespace;

public function __construct(
array $protectedControllers,
Expand Down Expand Up @@ -164,6 +166,8 @@ public function getRoute(string $uri): array
/**
* Tells the system whether we should translate URI dashes or not
* in the URI from a dash to an underscore.
*
* @deprecated This method should be removed.
*/
public function setTranslateURIDashes(bool $val = false): self
{
Expand All @@ -179,7 +183,7 @@ public function setTranslateURIDashes(bool $val = false): self
*
* @return array returns an array of remaining uri segments that don't map onto a directory
*/
protected function scanControllers(array $segments): array
private function scanControllers(array $segments): array
{
$segments = array_filter($segments, static fn ($segment) => $segment !== '');
// numerically reindex the array, removing gaps
Expand Down Expand Up @@ -234,6 +238,8 @@ private function isValidSegment(string $segment): bool
* Sets the sub-directory that the controller is in.
*
* @param bool $validate if true, checks to make sure $dir consists of only PSR4 compliant segments
*
* @deprecated This method should be removed.
*/
public function setDirectory(?string $dir = null, bool $append = false, bool $validate = true)
{
Expand Down Expand Up @@ -263,6 +269,8 @@ public function setDirectory(?string $dir = null, bool $append = false, bool $va
/**
* Returns the name of the sub-directory the controller is in,
* if any. Relative to APPPATH.'Controllers'.
*
* @deprecated This method should be removed.
*/
public function directory(): string
{
Expand Down
Loading