From bc566b5cd84deb36ec22c3b690855d28977b4ec1 Mon Sep 17 00:00:00 2001 From: Felipe Figueroa Date: Mon, 2 Nov 2015 14:07:48 -0200 Subject: [PATCH] Catches error thrown from Twig v 1.21 and newer Since Twig 1.21 (https://github.com/twigphp/Twig/commit/cc980282dee1964d867b70666ec7d2183d87ea4c) using Twig_Loaders is deprecated, and triggers a silent error using @ supressor. However, certain middlewares such as Whoops will still stop the normal flow. --- Twig.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/Twig.php b/Twig.php index a76ddd2..c0e328e 100644 --- a/Twig.php +++ b/Twig.php @@ -113,11 +113,16 @@ public function getInstance() * Check if Twig_Autoloader class exists * otherwise include it. */ - if (!class_exists('\Twig_Autoloader')) { - require_once $this->parserDirectory . '/Autoloader.php'; - } + try { + if (!class_exists('\Twig_Autoloader')) { + require_once $this->parserDirectory . '/Autoloader.php'; + } - \Twig_Autoloader::register(); + \Twig_Autoloader::register(); + } catch (\ErrorException $e) { + $app = \Slim\Slim::getInstance(); + $app->log->error($e->getMessage()); + } $loader = new \Twig_Loader_Filesystem($this->getTemplateDirs()); $this->parserInstance = new \Twig_Environment( $loader,