问题
Can anyone explain if there are any significant advantages or disadvantages when choosing to implement features such as authentication or caching etc using hooks as opposed to using middleware? For instance - I can implement a translation feature by obtaining the request object through custom middleware and setting an app language variable that can be used to load the correct translation file when the app executes. Or I can add a hook before the routing and read the request variable and then load the correct file during the app execution. Is there any obvious reason I am missing that makes one choice better than the other?
回答1:
As far as I can say that middleware
is perfect for each routing work. And hooks
is best for doing anything application-wide. For your case I think it should be better to use hooks
than middleware.
来源:https://stackoverflow.com/questions/19091841/hooks-versus-middleware-in-slim-2-0