Import service-provider as defined in container-interop into a Symfony application.
Add TheCodingMachine\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle in your kernel (the app/AppKernel.php file).
AppKernel.php
public function registerBundles()
{
$bundles = [
...
new \TheCodingMachine\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle()
];
...
}The bridge bundle will use thecodingmachine/discvoery to automatically discover the service providers of your project. If the service provider you are loading publishes itself on Discovery, then you are done. The services declared in the service provider are available in the Symfony container!
If the service provider you are using does not publishes itself using thecodingmachine/discovery, you will have to declare it manually in the constructor of the bundle.
AppKernel.php
class AppKernel extends Kernel
{
public function registerBundles()
{
$bundles = [
...
new \TheCodingMachine\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
new MyServiceProvide1(),
new MyServiceProvide2()
])
];
...
}
}Alternatively, you can also pass the service provider class name. This is interesting because the service-locator 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 \Puli\SymfonyBundle\PuliBundle(),
new \TheCodingMachine\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 \Puli\SymfonyBundle\PuliBundle(),
new \TheCodingMachine\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
[ MyServiceProvide1::class, [ "param1", "param2" ] ],
[ MyServiceProvide2::class, [ 42 ] ],
])
];
...
}You can disable Discovery by passing false as the second argument of the bundle:
AppKernel.php
public function registerBundles()
{
$bundles = [
...
// false is passed as second argument. Puli discovery will be disabled.
new \TheCodingMachine\Interop\ServiceProviderBridgeBundle\InteropServiceProviderBridgeBundle([
...
], false)
];
...
}By default, this package provides a CommonAliasesServiceProvider that will create the following aliases:
logger=>Psr\Log\LoggerInterfacecache.app=>Psr\Cache\CacheItemPoolInterfacetwig=>Twig_Environment
This is useful because most service providers expect entries to be available by class/interface name.
