-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Twig 1.38.0 classes Twig_Loader_Filesystem and Twig_Environment don't accept constructor parameters #2907
Comments
Are you sure? The method signature doesn't seem to have changed in a while: https://github.com/twigphp/Twig/blob/1.x/src/Loader/FilesystemLoader.php#L37 |
Yes I am sure for me this file
|
But in that case you should see code similar to what I linked to for the |
Issue is when I update from Twig v1.35.4 to v1.38.0 I get this error: |
Can you show a bit of how Twig is set up in your case and the full stack trace of this exception? |
We are using Auryn\Injector to setup twig loader and pass path and options vars to twig using injector code is like this: // vars // injector // tell the Injector class to inject an instance of Twig_Loader_Filesystem any time // controller I am getting following error: Fatal error: Uncaught exception 'LogicException' with message 'You must set a loader first.' in /projectroot/vendor/twig/twig/src/Environment.php on line 10896 LogicException: You must set a loader first. in /projectroot/vendor/twig/twig/src/Environment.php on line 10896 Call Stack: 1.1175 2020672 1. Raven_ErrorHandler->handleException() /projectroot/vendor/sentry/sentry/lib/Raven/ErrorHandler.php:0 |
Maybe the injector doesn't take class aliases into account. And since the type hint in the use Twig\Loader\FilesystemLoader;
// ...
$injector->alias(FilesystemLoader::class, 'Twig_Loader_Filesystem'); |
This doesn't works besides this code was working in v1.37.1, something in v1.38.0 changed that caused this issue. I think this issue is because type hint in Code breaks here: Where $twigEnvironment is object of |
Well, what changed in 1.38 is that Maybe the |
Can confirm this issue with PHP-DI as well. Here's my definition: $c[Twig_Environment::class] = function(ContainerInterface $c) {
$loader = new Twig_Loader_Filesystem();
$basePath = __DIR__ . "/../view";
$loader->addPath($basePath);
$loader->addPath($basePath . "/pages", "pages");
$twig = new Twig_Environment($loader, $c->get("settings")["twig"]);
$twig->addExtension(new TwigExtension());
$twig->addExtension(new TestAuthTwigExtension());
return $twig;
}; The controller is initialized with For PHP-DI (probably applies other DI containers as well) I managed to fix it by aliasing $c[\Twig\Environment::class] = DI\get(Twig_Environment::class); __construct(\Twig\Environment $twig) |
I'm closing this issue as the problems comes from the DI libraries you are using and not from Twig. |
Took me a while to figure out what this issue was. Seems like this has changed after Edit: just checked the change log, yeah
|
Twig version v1.38.0 removed constructor parameters from
Twig_Loader_Filesystem
andTwig_LoaderInterface
classes, both of these classes used to accept parameters$path
and$options
. This is how our current code in v1.35.4 defines loader.This change breaks our code since loader is not set because these parameters were removed. Our code now throws following exception:
Fatal error: Uncaught exception 'LogicException' with message 'You must set a loader first.'
We load twig templates at lots of places, is there a way to fix this error in our codebase without having to edit 100s of files?
The text was updated successfully, but these errors were encountered: