codeigniter4 / shield

Authentication and Authorization for CodeIgniter 4
https://shield.codeigniter.com
MIT License
366 stars 133 forks source link

shield:setup sets up its routes in an unfortunate location #295

Closed mv-steven closed 2 years ago

mv-steven commented 2 years ago

Not a big issue but something that stood out during the installation process.

I have an existing route group defined in Routes.php, and shield:setup put the route definition in the group closure, like this:

$routes->group('api', function($routes) {

service('auth')->routes($routes); <===
    $routes->map([
        ...
    ]);
});

Again, not a big issue, anyone using code modification tools should be reviewing what changes are being made. Just wanted to make sure this was known.

datamweb commented 2 years ago

Not sure, but it seems to be solvable using https://github.com/codeigniter4/CodeIgniter4/pull/6133#issue-1273276433.

kenjis commented 2 years ago

It is difficult to find the following code block with regex.

$routes->group('api', function($routes) {
    ...
});

So a fundamental solution seems difficult in the current situation. https://github.com/codeigniter4/CodeIgniter4/pull/6133#issue-1273276433 also finds a line and adds a new line before/after it.

mv-steven commented 2 years ago

I bet you could use token_get_all to determine whether a given line is in between a closure's (or something else's) braces

kenjis commented 2 years ago

Yes, we want a method to

  1. find the last $routes->...; block
  2. add new line service('auth')->routes($routes); after it
kenjis commented 2 years ago

This bug was fixed in develop. Please check.