Import service-provider
as defined in container-interop
into a Symfony application.
This is a fork of thecodingmachine/service-provider-bridge-bundle to support Symfony 4. Credits go to David Négrier.
Add Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle
in your kernel (the app/AppKernel.php
file).
AppKernel.php
public function registerBundles()
{
$bundles = [
...
new \Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle()
];
...
}
You have to declare service providers manually in the constructor of the bundle.
AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
...
new \Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
new MyServiceProvide1(),
new MyServiceProvide2()
])
];
...
}
}
Alternatively, you can also pass the service provider class name. This is interesting because the service-provider bundle will not instantiate the service provider unless it is needed for a service. You can therefore improve performances of your application.
AppKernel.php
public function registerBundles()
{
$bundles = [
...
new \Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
MyServiceProvide1::class,
MyServiceProvide2::class
])
];
...
}
Finally, if you need to pass parameters to the constructors of the service providers, you can do this by passing an array:
AppKernel.php
public function registerBundles()
{
$bundles = [
...
new \Bnf\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
[ MyServiceProvide1::class, [ "param1", "param2" ] ],
[ MyServiceProvide2::class, [ 42 ] ],
])
];
...
}