-
Notifications
You must be signed in to change notification settings - Fork 2
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
Is it possible to access SlimApp or SlimContainer or Route in middleware? #24
Comments
Not sure what |
It seems that it is the |
I see. One nasty solution can be something like this: /**
* @var SlimApp
*/
private $slimApplication;
public function __construct(SlimApplicationFactory $applicationFactory)
{
$this->slimApplication = $applicationFactory->create();
}
public function dispatch()
{
$container = $this->slimApplication->getContainer();
$this->slimApplication->add(...);
// ...
$this->slimApplication->run();
} I am not sure if an order of the middlewares will be correct but it can be the starting point of figuring it out. But its not nice. |
Another approach can be to have |
(To be honest, I do not have a solution, I am just thinking loudly basically.) |
Hi, getting back to this (I feel like a chess player, just taking a long time to think about next move 😄 ).
That could work and I would consider it to be quite a clean solution. I will check and if I am able to do it, I will send a PR. |
Quick idea: Router should be dependency of the SlimApp (created or provided into SlimAppFactory) Then router can be dependency of the cors middleware |
// This may require changes in Slim lib itself. |
Nice, thank you! |
Hi!
Let's have example code (from https://www.slimframework.com/docs/v3/cookbook/enable-cors.html):
It is okay if i place this into my
index.php
where i have application in variable$application = $applicationFactory->create();
But i did not find if i wanted to create
CORSMiddleware
, register it as service and do it all via config.The problem is
$this->router
- i do not have access to router in middleware service.When debugging, i found out that
Slim\Container
is in the$next
variable, should i use it? Any idea how to achieve it?The text was updated successfully, but these errors were encountered: