Slim 4: removing container, alternatives?


I just read in a new post that Slim 4 will not ship with a container.
I’m just getting started using Slim for an API at work that will eventually be a decent size.
This weekend I was looking at containers and thinking about my app scaling and I came across the PHP-DI/Slim-bridge.

Is this a good option? Something else?



@dstefani a container package doesn’t help you to scale your app :smiley:

The point is that for build an application using Slim4 you won’t need a container.
But if you want you can use it for your application.

I am not a fan of big package for really simple stuff.
I build a really simple container and it’s all i need 99.99% of the time.

I don’t see a real example using an huge package for use DI in your application :smiley:


Thanks, your container looks interesting, but right now our server is at PHP 5.6.1. Upgrading would have to happen and that’s a whole other discussion.

Thanks - Don


The nice thing about PHP-DI is the autowiring. Less things you need to setup in your container. However it comes a bit of a speed price.

You could also use Pimple with Slim 4… the same container Slim 3 ships with.


Thanks, I guess my concern is that I will eventually have a lot of routes and if I use the pattern that is encouraged I’ll be building lots of DIC factories. What impact will the changes in Slim 4 have if I want to upgrade?
Perhaps there will be a better solution for DI in v4?

Thanks - Don


If you use a PSR-11 container with Slim 3, I don’t think there will be much headache with that for Slim 4. You can still use a container, much the same. It is just that Slim 4 won’t ship with one.

If you don’t want to write lots of DI factories for your controllers, then use PHP-DI and its autowiring capabilities.

It isn’t as though Slim doesn’t expect people to use containers with Slim 4… but rather than shipping with one by default you can pick whichever one you want to use. Or, if you don’t wish to use one, you don’t have to. So it just becomes a bit more flexible.


Thanks for mentioning PHP-DI, I looked at it over the weekend but thought it might be more than I need. But for the amount of routes I think it will do really good. I’ve got it wired up and working on my app. Very cool.