Core uses a compile pass (defined in DependencySerializationTraitPass) to attach a property (_serviceId) to all defined services.
The Symfony Service Container allows decorating a service (http://symfony.com/doc/current/components/dependency_injection/advanced....):
webprofiler.debug.config.factory:
class: Drupal\webprofiler\Config\ConfigFactoryWrapper
public: false
decorates: config.factory
arguments: ['@webprofiler.debug.config.factory.inner', '@webprofiler.config']
but the DependencySerializationTraitPass class fails to set the property _serivceId on the correct service:
protected function getConfig_FactoryService()
{
$a = new \Drupal\Core\Config\ConfigFactory($this->get('config.storage'), $this->get('webprofiler.debug.event_dispatcher'), $this->get('config.typed'));
$a->_serviceId = 'config.factory';
return $this->services['config.factory'] = new \Drupal\webprofiler\Config\ConfigFactoryWrapper($a, $this->get('webprofiler.config'));
}
should be
protected function getConfig_FactoryService()
{
$this->services['config.factory'] = $instance = new \Drupal\webprofiler\Config\ConfigFactoryWrapper(new \Drupal\Core\Config\ConfigFactory($this->get('config.storage'), $this->get('webprofiler.debug.event_dispatcher'), $this->get('config.typed')), $this->get('webprofiler.config'));
$instance->_serviceId = 'config.factory';
return $instance;
}
Beta phase evaluation
| Issue category | Bug because it prevents the use of a Symfony core feature |
|---|---|
| Issue priority | Major because can expose developers to weird bugs (i.e. fatal errors if try to serialize a decorator) |
| Disruption | Non-disruptive because Core doesn't use decorated services |
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | 2536370-1.patch | 1.85 KB | lussoluca |
Comments
Comment #1
lussolucaComment #2
lussolucaComment #3
lussolucaComment #4
dawehnerJust to be clear, never expect it to be there. This is a pure implementation detail.
Comment #5
lussolucaSo a contrib cannot use decorated services? It seems a useful functionality.
Comment #6
dawehnerDo you mind checking whether decorated services work once #2531564: Fix leaky and brittle container serialization solution is applied?
Comment #7
lussolucaYes with the patch in https://www.drupal.org/node/2531564#comment-10133478 all my decorated services works.
Meanwhile I'm setting:
in webprofiler.services.yml for every decorated service as a workaround.
Comment #10
dawehnerLet's ensure to add test coverage here.
Comment #11
cilefen commentedComment #12
cilefen commentedComment #13
alexpottDiscussed with @effulgentsia, @catch, @xjm, @cilefen. We decided to mark this issue as a duplicate of #2531564: Fix leaky and brittle container serialization solution and require that that issue adds a test for this bug.