Skip to content

Autowiring is not working properly in Symfony 3.2.7 #22309

Closed
@secit-pl

Description

@secit-pl
Q A
Bug report? yes
Feature request? no
BC Break report? no
Symfony version 3.2.7

I'm not able to autowire the Symfony\Component\Translation\DataCollectorTranslator to more than one service in Symfony 3.2.7. In 3.2.6 all worked fine.

Example code:

Service1.php

<?php

namespace Acme\BugTestBundle\Service;

use Symfony\Component\Translation\DataCollectorTranslator;

class Service1
{
    /**
     * @var DataCollectorTranslator
     */
    private $translator;

    /**
     * Service1 constructor.
     *
     * @param DataCollectorTranslator $translator
     */
    public function __construct(DataCollectorTranslator $translator)
    {
        $this->translator = $translator;
    }
}

Service 2:

<?php

namespace Acme\BugTestBundle\Service;

class Service2 extends Service1
{
}

services.yml

services:
    bug.service1:
        class: Acme\BugTestBundle\Service\Service1
        autowire: true

    bug.service2:
        class: Acme\BugTestBundle\Service\Service2
        autowire: true

The part of the production cache:
var/cache/prod/appProdProjectContainer.php

/*
 * Gets the 'bug.service1' service.
 *
 * This service is shared.
 * This method always returns the same instance of the service.
 *
 * This service is autowired.
 *
 * @return \Acme\BugTestBundle\Service\Service1 A Acme\BugTestBundle\Service\Service1 instance
 */
protected function getBug_Service1Service()
{
    return $this->services['bug.service1'] = new \Acme\BugTestBundle\Service\Service1(new \Symfony\Component\Translation\DataCollectorTranslator($this->get('translator.default')));
}

/*
 * Gets the 'bug.service2' service.
 *
 * This service is shared.
 * This method always returns the same instance of the service.
 *
 * This service is autowired.
 *
 * @return \Acme\BugTestBundle\Service\Service2 A Acme\BugTestBundle\Service\Service2 instance
 */
protected function getBug_Service2Service()
{
    return $this->services['bug.service2'] = new \Acme\BugTestBundle\Service\Service2();
}

As you see only the first service was properly autowired.

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