Closed hassankhan closed 5 years ago
Can you not do something like this?
$c['Twig_LoaderInterface'] = function ($c) {
return $c['MyApp_TwigLoaderImplementation'];
};
I could, I guess I was hoping for an auto-resolving solution. That said, I hadn't even thought of doing what you did, thanks for that!
It could be a useful feature, already actively using it in my own home project, saves time and allows to auto-wire interfaces, e.g.:
$container = new Wart([], [
'createArgs' => [
Twig_Loader_Filesystem::class => [__DIR__ . '/templates'],
Twig_Environment::class => [['cache' => __DIR__ . '/cache']],
],
'aliases' => [
Twig_LoaderInterface::class => Twig_Loader_Filesystem::class
],
]);
$twig = $container[Twig_Environment::class]; // works correctly
Added here: https://github.com/ukautz/wart/pull/4
@ukautz you can close this issue I guess
For example, when using Twig, the
Twig_Environment
object requires another object of typeTwig_LoaderInterface
. Can I somehow "map" an object onto it? Using createArgs() doesn't seem to be working for me.