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

Loaded route not available to middelware? #623

Open
esbenboye opened this issue Oct 18, 2022 · 1 comment
Open

Loaded route not available to middelware? #623

esbenboye opened this issue Oct 18, 2022 · 1 comment

Comments

@esbenboye
Copy link

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?

Screen.Recording.2022-10-18.at.06.58.11.mov
@DeveloperMarius
Copy link
Contributor

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants