From 209d108e6f4c1caab10e6e2557f6b75d11b7c78e Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Tue, 26 May 2020 13:39:27 -0700 Subject: [PATCH] Minor optimizations to TwigFactory --- app/src/Factories/TwigFactory.php | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/app/src/Factories/TwigFactory.php b/app/src/Factories/TwigFactory.php index 7ccf971..7c17431 100644 --- a/app/src/Factories/TwigFactory.php +++ b/app/src/Factories/TwigFactory.php @@ -40,24 +40,18 @@ class TwigFactory { $twig = new Twig(new FilesystemLoader( $this->container->get('views_path') - )); + ), ['cache' => $this->container->get('view_cache')]); - $twig->getEnvironment()->setCache( - $this->container->get('view_cache') - ); + $environment = $twig->getEnvironment(); + $core = $environment->getExtension(CoreExtension::class); - $twig->getEnvironment()->getExtension(CoreExtension::class)->setDateFormat( - $this->container->get('date_format'), '%d days' - ); - - $twig->getEnvironment()->getExtension(CoreExtension::class)->setTimezone( - $this->container->get('timezone') - ); + $core->setDateFormat($this->container->get('date_format'), '%d days'); + $core->setTimezone($this->container->get('timezone')); foreach ($this->container->get('view_functions') as $function) { $function = $this->callableResolver->resolve($function); - $twig->getEnvironment()->addFunction( + $environment->addFunction( new TwigFunction($function->name(), $function) ); }