Make using twig cache optional

This commit is contained in:
Greyscale 2020-07-10 05:02:39 +02:00
parent 5fcb927b5a
commit 4b05e9ea1d

View file

@ -129,6 +129,8 @@ class App
$container = $container->build();
$container->set(Slim\Views\Twig::class, function (ContainerInterface $container) {
/** @var EnvironmentService $environmentService */
$environmentService = $container->get(EnvironmentService::class);
foreach ($this->viewPaths as $i => $viewLocation) {
if (!file_exists($viewLocation) || !is_dir($viewLocation)) {
unset($this->viewPaths[$i]);
@ -136,7 +138,11 @@ class App
}
$twigCachePath = "{$this->getCachePath()}/twig";
$twigSettings = ['cache' => $twigCachePath];
$twigSettings = [];
if($environmentService->has('TWIG_CACHE') && strtolower($environmentService->get('TWIG_CACHE')) == "on") {
$twigSettings['cache'] = $twigCachePath;
}
if (!file_exists($twigCachePath)) {
@mkdir($twigCachePath, 0777, true);