Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spiral: Twig not provided by the Spiral Twig Bridge #42

Open
alexander-schranz opened this issue Nov 9, 2022 · 0 comments
Open

Spiral: Twig not provided by the Spiral Twig Bridge #42

alexander-schranz opened this issue Nov 9, 2022 · 0 comments
Labels
Engine: Twig Twig engine and integration Framework: Spiral Spiral integration

Comments

@alexander-schranz
Copy link
Contributor

Like mezzio plates integration before where we fixed it. The Spiral Twig integration does not provide the Twig Engine Twig\Environment / twig as a service and this make usage of it hard. Currently a hack here is used here to get Twig instance of Spiral which is very hacky:

$container->bindSingleton('twig', function (Container $container) {
// Use a hack to get Twig from the ViewManager as it is not available as an service yet
$viewManager = $container->get(ViewManager::class);
$engines = $viewManager->getEngines();
$twigEngine = null;
foreach ($engines as $engine) {
if ($engine instanceof TwigEngine) {
$twigEngine = $engine;
break;
}
}
if (null === $twigEngine) {
throw new \LogicException(
\sprintf('Expected "%s" to be registered in the view manager.', TwigEngine::class)
);
}
return $twigEngine->getEnvironment(new ViewContext());
});

Upstream issue: spiral/twig-bridge#10

@alexander-schranz alexander-schranz changed the title Spiral: Twig not provded by Spiral Integration Spiral: Twig not provided by the Spiral Twig Bridge Nov 9, 2022
@alexander-schranz alexander-schranz added Engine: Twig Twig engine and integration Framework: Spiral Spiral integration labels Nov 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Engine: Twig Twig engine and integration Framework: Spiral Spiral integration
Projects
None yet
Development

No branches or pull requests

1 participant