-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Configure the application via a container #2793
Configure the application via a container #2793
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great, thank you for this contribution. I would like to mention that I’d like to work closely with third-party library devs like you to make Slim flexible and sensical in terms of approaching different problems. I highly value your input @mnapoli
2778 Prophesize Unit Tests
Looks good to me. Please have a quick look before I merge @adriansuter! |
@l0gicgate Can be merged. We need to make sure that this possibility gets its way into the documentation. |
|
This is an implementation for what we discussed in #2778.
The idea is to simplify how to configure the application when using a PSR-11 container.
Here is an example with PHP-DI, using the default services from Slim:
Here is an example when we want to overload one service:
(in reality I would recommend using a config file, but the example here is simpler)
instead of the current way of doing it:
The advantages:
AppFactory
is no longer storing global state, meaning subsequent calls toAppFactory::create()
will not be affected by any previous call toAppFactory
The 2nd point is interesting for PHP-DI: the bridge could provide a pre-configured container for Slim. Users would just have to call
AppFactory::createFromContainer($container)
, which is pretty cool.