如何从容器中取出 Twig 对象?

How to get the Twig object out of the container?

我在 PHP-DI/Slim-Bridge 中使用 Slim Framework 3。这是我的容器:

$builder->addDefinitions([
            'settings.displayErrorDetails' => true,

            'router' => get(Router::class),

            Twig::class => function(ContainerInterface $c) {
                $twig = new Twig(__DIR__.'/../resources/views', [
                   'cache'=> false
                ]);

                $twig->addExtension(new TwigExtension(
                    $c->get('router'),
                    $c->get('request')->getUri()
                ));

                return $twig;
            }
   ]);

如何从容器中取回树枝对象? 我尝试了 $container->twig,但无法取回对象。

尝试$container->get(Twig::class)

我邀请你阅读Getting started with PHP-DI