Symfony - using a callable as factory in Dependency Injection

时间:2017-06-15 10:34:14

标签: php symfony dependency-injection factory

Suppose I have a class Foo and I am provided with a callable which works as a factory for my class Foo. For example it could be something like the following (using a function here, but my question refers to a generic callable):

factory = function (ContainerBuilder $container) : Foo
{
    $foo = // build an instance of Foo, possibly using the $container

    return $foo;
}

I don't know Symfony very well and I don't understand how to configure the Dependency Injection component to use my callable as a factory.

I saw this, but it seems that I'm allowed only to used static methods of a class as factory methods, and not generic callables.

Is there a way, without creating new classes, to use a generic callable as a factory with Symfony Dependency Injection component?

0 个答案:

没有答案