Skip to content

[DependencyInjection] BC break after PR 13519 #14171

Closed
@boekkooi

Description

@boekkooi

So when updating from SF 2.6.1 to 2.6.6 i found my self stuck with a error on cache:clear.
After some research I found out that in one of our internal components we where doing the following:

$container
    # ...
     ->setFactoryService(new Reference($entityManagerService));

This used to work but due to a change made in #13519 if stopped working.
The code dumped after #13519 was merged looks something like (see the double $this->get):

return $this->services['service_name'] = new \SomeLoader($this->get($this->get('object_manager'))->getRepository('EntityClass'));

I'm not sure if this a BC break everyone is ok with but it confused the ..... out of me.
A simple fix would be to modify the code in src/Symfony/Component/DependencyInjection/Dumper/PhpDumper.php around line 1334.

-$service = $this->dumpValue($value->getFactoryService());
-
-return sprintf('%s->%s(%s)', 0 === strpos($service, '$') ? sprintf('$this->get(%s)', $service) : $this->getServiceCall($value->getFactoryService()), $value->getFactoryMethod(), implode(', ', $arguments));
+$service = null;
+if (!$value->getFactoryService() instanceof Reference) {
+    $service = $this->dumpValue($value->getFactoryService());
+    $service = (0 === strpos($service, '$') ? sprintf('$this->get(%s)', $service) : null);
+}
+$service = $service ?: $this->getServiceCall($value->getFactoryService());
+
+return sprintf('%s->%s(%s)', $service, $value->getFactoryMethod(), implode(', ', $arguments));

Is there any interest in a PR for this?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions