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?