simple-php-router icon indicating copy to clipboard operation
simple-php-router copied to clipboard

Loaded route not available to middelware?

Open esbenboye opened this issue 3 years ago • 1 comments

I'm using the latest version of this package (4.3.7.2)

I just tried to create a small middleware to check if a user is authorized to do a certain action. I was using SimpleRouter::request()->getLoadedRoute()->getParameters() inside the middleware to get the parameters from the route, but that failed since the value from getLoadedRoute() was null.

An easy fix would be to move Router.php line 408 ($this->request->addLoadedRoute($route);) up before the event EVENT_MATCH_ROUTE is triggered to make the loaded route available to the events. I haven't noted any negative side effects by making this change.

But the question is if this is 'by design' or if I should open a pull request?

https://user-images.githubusercontent.com/4438511/196339422-e62d4ed0-569e-4978-8b6c-b2920ba1560f.mov

esbenboye avatar Oct 18 '22 05:10 esbenboye

Hey,

the PR #604 sould do what you want to do. I merged it a while ago with my fork.

Warning: I changed a lot in this fork and currently I only support the php8 branch (I think php 8.1 is required). You can use it with composer:

"repositories": [
        {
            "type": "vcs",
            "url": "https://github.com/developermarius/simple-php-router"
        },
        {
            "type": "composer",
            "url": "https://packagist.org"
        }
],
"require": {
  "pecee/simple-router": "dev-v5-development-php8"
}

In this year I had no time to do the README.md and stuff like this, but I hope to make some time soon to also do some changes to the input validation topic. A lot was explained in #607 (validation) and a lot of changes were made to the InputHandler. If you have any questions, use this comment section.

~ Marius

DeveloperMarius avatar Nov 10 '22 14:11 DeveloperMarius