Skip to content

[DependencyInjection] PHP configuration doesn't support string factory #24704

Closed
@vudaltsov

Description

@vudaltsov
Q A
Bug report? yes
Feature request? no
BC Break report? no
RFC? no
Symfony version 3.4 and higher

Works:

services:
    App\Repository\UserRepository:
        factory: 'Doctrine\ORM\EntityManagerInterface:getRepository'
        arguments: [App\Entity\User]

Works:

<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\Entity\User;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;

return function (ContainerConfigurator $configurator) {
    $configurator
        ->services()
        ->set(UserRepository::class)
        ->factory([ref(EntityManagerInterface::class), 'getRepository'])
        ->args([
            User::class,
        ]);
};

Doesn't work and says Cannot dump definition because of invalid class name ('Doctrine\\ORM\\EntityManagerInterface:getRepository'):

<?php

namespace Symfony\Component\DependencyInjection\Loader\Configurator;

use App\Entity\User;
use App\Repository\UserRepository;
use Doctrine\ORM\EntityManagerInterface;

return function (ContainerConfigurator $configurator) {
    $configurator
        ->services()
        ->set(UserRepository::class)
        ->factory(EntityManagerInterface::class.':getRepository')
        ->args([
            User::class,
        ]);
};

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions