Please explain the router code. - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28) +--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30) +--- Thread: Please explain the router code. (/showthread.php?tid=81890) |
Please explain the router code. - iRedds - 05-15-2022 I can't think of a case where this code would make sense. PHP Code: $replacekey = str_replace('/(.*)', '', $routeKey); PHP Code: // for route RE: Please explain the router code. - kenjis - 05-16-2022 The last `str_replace()` is not covered by PHPUnit tests. RouterTest passes if I remove the line. PHP Code: $routeKey: api/posts/(.*) PHP Code: $routeKey: api/posts/(.*)/edit PHP Code: $routeKey: api/posts/(.*) It seems the code came from https://github.com/codeigniter4/CodeIgniter4/pull/344 RE: Please explain the router code. - iRedds - 05-16-2022 Perhaps some separate logic was planned here. But I don't see the point in the first and second line. That is, the condition can be reduced to a single preg_replace() call. RE: Please explain the router code. - kenjis - 05-16-2022 From the time of the first PR, it looks the test passes without it. Code: --- a/system/Router/Router.php (05-16-2022, 08:55 PM)iRedds Wrote: Perhaps some separate logic was planned here. Agreed. We can remove the if statement. |