Skip to content

Unable to reference PHP DI dependencies in Symfony 3.1 #16

Open
@pevdh

Description

@pevdh

First of all, thank you for this very useful bridge!

I am trying to use the Symfony bridge with Symfony 3.1, but I ran into an issue where I seem to be unable to reference to PHP DI dependencies from the Symfony services.yml configuration file.

This is my services.yml configuration file (as suggested in the docs):

services:
    app.page_layout_extension:
        class: AppBundle\Twig\PageLayoutExtension
        arguments:
            - 'AppBundle\Layout\PageLayoutFactory'
            - 'AppBundle\Service\ContentBlockService'
        tags:
            - {name: twig.extension}

The signature of the PageLayoutExtension constructor is public function __construct(PageLayoutFactory $pageLayoutFactory, ContentBlockService $contentBlockService)

This configuration yields the following error:

PHP Fatal error:  Uncaught Symfony\Component\Debug\Exception\FatalThrowableError: Type error: Argument 1 passed to AppBundle\Twig\PageLayoutExtension::__construct() must be an instance of AppBundle\Layout\PageLayoutFactory, string given, called in /var/cache/dev/appDevDebugProjectContainer.php on line 300 in /src/AppBundle/Twig/PageLayoutExtension.php:23
Stack trace:
#0 /var/cache/dev/appDevDebugProjectContainer.php(300): AppBundle\Twig\PageLayoutExtension->__construct('AppBundle\\Layou...', 'AppBundle\\Servi...')
#1 /vendor/symfony/symfony/src/Symfony/Component/DependencyInjection/Container.php(275): appDevDebugProjectContainer->getApp_PageLayoutExtensionService()
#2 /vendor/php-di/symfony-bridge/src/SymfonyContainerBridge.php(93): Symfony\Component\DependencyInjection\Container->get('app.page_layout...', 1)
#3 /vendor/php-di/symfony-bridge/src/SymfonyContainer in /src/AppBundle/Twig/PageLayoutExtension.php on line 23

Upon inspection, this error is caused by this line in appDevDebugContainer.php:

return $this->services['app.page_layout_extension'] = new \AppBundle\Twig\PageLayoutExtension('AppBundle\\Layout\\PageLayoutFactory', 'AppBundle\\Service\\ContentBlockService');

Which makes the error obvious. This line should read:

return $this->services['app.page_layout_extension'] = new \AppBundle\Twig\PageLayoutExtension($this->get('AppBundle\\Layout\\PageLayoutFactory'), $this->get('AppBundle\\Service\\ContentBlockService'));

Looking into the issue, I came across the following suggested modification of services.yml (forgot where I read it):

services:
    app.page_layout_extension:
        class: AppBundle\Twig\PageLayoutExtension
        arguments:
            - '@AppBundle\Layout\PageLayoutFactory'
            - '@AppBundle\Service\ContentBlockService'
        tags:
            - {name: twig.extension}

However, this makes that same appDevDebugContainer.php line translate to:

return $this->services['app.page_layout_extension'] = new \AppBundle\Twig\PageLayoutExtension($this->get('appbundle\layout\pagelayoutfactory'), $this->get('appbundle\service\contentblockservice'));

(Note the lowercase service names). Which is clearly wrong as well.

Am I missing something or is this new "functionality" of Symfony's container? Are there any workarounds?

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