The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Enhancing route mdidleware

Tiago Fernandes's Avatar

Tiago Fernandes

17 Jun, 2014 08:31 AM

Hi everyone,

found Slim a couple of weeks ago and it is already powering my small website :)
Great work!

Since we are in the suggestion space, let me jump right into my proposal:
1- "Apply" the Rack protocol to Route Middleware (RM) as it is done is Application Middleware (AM)
2- Create RM groups so that they can be easily "attached" to routes
3- (maybe not so important) Change the RM naming because it might confuse new people (it did confuse me for a couple of days) that mix it up with AM.

Now, detailing a bit more:
1- Why not refactor and have both RM and AM extend from the same base functionality?

  • AM and RM would be interchangeable.
  • RM would be able to execute code before and after the controller
  • ...really, only 1 type of Middleware

2- With middleware groups we could group together commoly used middlewares:

  • Let me use a concrete example here: my site requires authentication and authorization for around 80% of its content. My approach was to use RM and not AM (I really didn't want to be checking if authentication and authorization should be checked on every request) so, for every route that requires it, I'm adding to RM: 1 for checking if the user is authenticated and another for checking if the user is authorized.

3- Just naming really but, if you agree with 1 and 2 above then there would only be 1 type middleware :)

Do let me know your thoughts on this.
If they are even a lit bit positive I'll write some lines to implement this suggestion.

Cheers,
Tiago

  1. Support Staff 1 Posted by Andrew Smith on 18 Jun, 2014 09:21 PM

    Andrew Smith's Avatar

    I agree with the naming being confusing and agree that they should either be merged or only have 1.

    2- With middleware groups we could group together commoly used middlewares:

    I am not sure what would stop you from doing this in a application middleware, kinda like how I did it with Strong Middleware, that way all things would be in 1 central location.

    Route Groups is currently being rethought for Slim 3, as currently they don't behave like normal routes, which is something that is likely to change.

    I think you should still go ahead with your implementation and send a PR. Josh will most likely review it and let you know his thoughts.

  2. 2 Posted by Tiago Fernandes on 19 Jun, 2014 03:16 PM

    Tiago Fernandes's Avatar

    Thanks Andrew!
    I've submitted the PR (#844). Let's see :)

Reply to this discussion

Internal reply

Formatting help / Preview (switch to plain text) No formatting (switch to Markdown)

Attaching KB article:

»

Attached Files

You can attach files up to 10MB

If you don't have an account yet, we need to confirm you're human and not a machine trying to post spam.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac