0.3.x-dev
0.3.9999999.9999999-devThis Drupal 8 module provides a bridge to include container-interop/service-provider service providers into your Drupal project.
MIT
The Requires
This Drupal 8 module provides a bridge to include container-interop/service-provider service providers into your Drupal project.
Import service-provider
as defined in container-interop
into a Drupal 8 project., (*1)
Install the package using Composer:, (*2)
composer require thecodingmachine/drupal-service-provider-bridge
Go to Drupal administration panel, to the "Extensions" page and enable the "Service providers integration" module., (*3)
There is currently an issue with Puli loading.
To fix it, create a load_puli.php
file at the root of your project:, (*4)
load_puli.php, (*5)
<?php if (file_exists(__DIR__.'/.puli/GeneratedPuliFactory.php')) { require_once __DIR__.'/.puli/GeneratedPuliFactory.php'; }
Now, go to your project composer.json
file and in the autoload
section, add:, (*6)
{ "autoload": { "files": [ "load_puli.php" ] }, }
The bridge bundle will use Puli to automatically discover the service providers of your project. If the service provider you are loading publishes itself on Puli, then you are done. The services declared in the service provider are available in the Symfony container!, (*7)
If the service provider you are using does not publishes itself using Puli, you will have to declare it manually.
To do so, open a service-providers.php
file at the web-root of your project, and return the list of service provider you want to import:, (*8)
service-providers.php, (*9)
return [ 'service-providers' => [ 'My\\Project\\Di\\MyServiceProvider', 'My\\Project\\Di\\MyOtherServiceProvider', ] ];
You can disable Puli discovery by passing 'puli' => false
in the service-providers.php
file:, (*10)
service-providers.php, (*11)
return [ 'service-providers' => [ 'My\\Project\\Di\\MyServiceProvider', 'My\\Project\\Di\\MyOtherServiceProvider', ], 'puli' => false ];
Note: instead of returning a fully-qualified class name, you can also put in the array an instance of a service provider directly., (*12)
Drupal 8 container only accepts lower-case identifiers., (*13)
Since service providers can provide any kind of identifiers for services (both upper and lower case), this bridge systematically put cast the identifiers in lower-case., (*14)
This can introduce bugs if you have 2 services that have the same name in different cases (but honnestly, you should reconsider the way you design your service providers if you have this issue :) ), (*15)
By default, this package provides will create the following entries:, (*16)
Psr\Log\LoggerInterface
=> alias to logger.channel.default
puli_factory
=> The Puli factorypuli_repository
=> The Puli repositorypuli_discovery
=> The Puli discovery serviceBehind the scene, this Drupal 8 module heavily relies on the Symfony = service-provider bridge bundle. Indeed, Drupal 8 container is a heavily adapted container based on Symfony container. This module is therefore a set of adaptations from the Symfony bridge., (*17)
This Drupal 8 module provides a bridge to include container-interop/service-provider service providers into your Drupal project.
MIT