Download the PHP package flexsounds/slim-symfony-di-container without Composer
On this page you can find all versions of the php package flexsounds/slim-symfony-di-container. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download flexsounds/slim-symfony-di-container
More information about flexsounds/slim-symfony-di-container
Files in flexsounds/slim-symfony-di-container
Package slim-symfony-di-container
Short Description The bridge to use the Symfony Dependency Injection Container to use in Slim Framework 3
License MIT
Informations about the package slim-symfony-di-container
Slim-Symfony-Dependency-Injection-Bridge
Just a simple bridge to use the Symfony Dependency Injection Container to replace the Container in Slim Framework 3
This will replace the pimple
container which comes default with Slim Framework 3.
The default services (like router
, request
, response
) which Slim Framework uses, are preloaded in the ContainerBuilder
. This way Slim will work as it should.
Installation
Use composer to install
composer require flexsounds/slim-symfony-di-container
Default usage
To use the Symfony DI Container just add the ContainerBuilder to Slim\App
Default parameters
The default Slim Framework Settings are 1 on 1 mapped with parameters. To overwrite the settings you can either create a new ParameterBag
with your settings and pass it as the first argument to the ContainerBuilder
.
Or if you use one of the file loaders, change them with the parameters config key.
Just change the parameters to your own choice to your config file like this.
Other Examples
Example loading your dependencies through yaml configuration (The Symfony way)
`
Now you can create a config.yml
file to load your services, parameters, etc. The use of importing other config files is also available.
Now the service my.custom.service
is available in the container. Use $this->get('my.custom.service')
to load the service.
Read more
Read the symfony service container documentation to find out what other options are available in the service container.
Read the symfony dependency injection documentation to find out how the ContainerBuilder is used. Like setting default parameters.
Interesting to know
If you use PhpStorm as IDE and add the Symfony Plugin, typehinting for services should be available.
All versions of slim-symfony-di-container with dependencies
slim/slim Version ^3.1
symfony/dependency-injection Version ^3.2 || ^4.0
symfony/config Version ^3.2 || ^4.0