<commit_before><?php
namespace Youkok\Containers;

use \Slim\Container;
use \Slim\Views\Twig;
use \Slim\Views\TwigExtension;

use Youkok\TwigPlugins\YoukokTwigExtension;

class View
{
    public static function load(Container $container)
    {
        $baseDir = $container->get('settings')['base_dir'];

        $container['view'] = function ($container) use ($baseDir) {
            $view = new Twig($baseDir . '/templates/', [
                'cache' => false,
                'auto_reload' => true,
                'debug' => true
            ]);

            // Instantiate and add Slim specific extension
            $basePath = rtrim(str_ireplace('index.php', '', $container['request']->getUri()->getBasePath()), '/');
            $view->addExtension(new TwigExtension($container['router'], $basePath));
            $view->addExtension(new YoukokTwigExtension($container['router'], $container['request']));

            return $view;
        };
    }
}<commit_msg>Twig settings + twig caching<commit_after><?php
namespace Youkok\Containers;

use \Slim\Container;
use \Slim\Views\Twig;
use \Slim\Views\TwigExtension;

use Youkok\TwigPlugins\YoukokTwigExtension;

class View
{
    public static function load(Container $container)
    {
        $baseDir = $container->get('settings')['base_dir'];
        $cacheDir = $container->get('settings')['cache_directory'];

        $container['view'] = function ($container) use ($baseDir, $cacheDir) {
            $cache = false;
            if (getenv('DEV') === '0') {
                $twigCacheDir = $cacheDir . 'twig';
                if (!file_exists($twigCacheDir)) {
                    mkdir($twigCacheDir);
                    if (file_exists($twigCacheDir) and is_writable($twigCacheDir)) {
                        $cache = $twigCacheDir;
                    }
                }
            }

            $view = new Twig($baseDir . '/templates/', [
                'cache' => $cache,
                'auto_reload' => getenv('DEV') === '1',
                'debug' => getenv('DEV') === '1'
            ]);

            // Instantiate and add Slim specific extension
            $basePath = rtrim(str_ireplace('index.php', '', $container['request']->getUri()->getBasePath()), '/');
            $view->addExtension(new TwigExtension($container['router'], $basePath));
            $view->addExtension(new YoukokTwigExtension($container['router'], $container['request']));

            return $view;
        };
    }
}
{'fraction_non_alphanumeric': 0.15891629599676507, 'fraction_numerical': 0.001213101496158512, 'mean_word_length': 2.2811671087533156, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4489718', 'n_tokens_mistral': 726, 'n_tokens_neox': 696, 'n_words': 129}