Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Container lint command fails with synthetic service+expression language combo #35691

Closed
HypeMC opened this issue Feb 12, 2020 · 2 comments
Closed

Comments

@HypeMC
Copy link
Contributor

HypeMC commented Feb 12, 2020

Symfony version(s) affected: 4.4

Description
The container lint command fails when using a combination of synthetic services & the expression language. I've created an example application to demonstrate the problem, all the code needed to reproduce the bug is in this commit: https://github.com/HypeMC/sf-container-lint-bug/commit/bb342d5b68892609fa86a048ce61f1750d0be6ab.

Basically the problem is that when using the service function from the expression language with a service which it self requires a synthetic service, the lint command fails, even though the service definitions are valid. The following error message is outputed:

In ContainerBuilder.php line 1091:
                                                                                                           
  You have requested a synthetic service ("kernel"). The DIC does not know how to construct this service.

How to reproduce

# config/services.yaml

    App\Controller\TestController:
        arguments:
            - '@=service("App\\Service\\Test").getSomething()'
class TestController extends AbstractController
{
    private $string;

    public function __construct(string $string)
    {
        $this->string = $string;
    }

    /**
     * @Route("/", name="test")
     */
    public function index(): Response
    {
        return new Response($this->string);
    }
}

class Test
{
    private $kernel;

    public function __construct(KernelInterface $kernel)
    {
        $this->kernel = $kernel;
    }

    public function getSomething(): string
    {
        return 'some-string';
    }
}

Additional context
image

@nicolas-grekas
Copy link
Member

Please send a PR providing a reproducing test case + a fix if possible.

@HypeMC
Copy link
Contributor Author

HypeMC commented Mar 3, 2020

@nicolas-grekas Done, #35949

nicolas-grekas added a commit that referenced this issue Mar 12, 2020
…s used in an expression (HypeMC)

This PR was merged into the 4.4 branch.

Discussion
----------

[DI] Fix container lint command when a synthetic service is used in an expression

Fix container lint command when a synthetic service is used in combination with the expression language.

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #35691
| License       | MIT
| Doc PR        | -

Commits
-------

e7fa73a Fix container lint command when a synthetic service is used in combination with the expression language
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants