<commit_before><?php

use Artax\Client;
use Arya\Application;
use Auryn\Provider;
use CvRing\Backlog\BacklogCore;
use CvRing\Backlog\ConfigFile;
use CvRing\Backlog\FileCache;
use CvRing\Backlog\StackExchange\ChatCrawler;
use CvRing\Backlog\StackExchange\StackApi;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Monolog\Processor\IntrospectionProcessor;
use Monolog\Processor\MemoryPeakUsageProcessor;
use Monolog\Processor\MemoryUsageProcessor;
use Monolog\Processor\UidProcessor;
use Monolog\Processor\WebProcessor;

$config = new ConfigFile(__DIR__ . '/../config/backlog.ini');

/* keep a log for each day and rotate weekly */
$stream = new RotatingFileHandler(__DIR__ . "/../logs/backlog_$appEnv.log", 7, $logLevel);
$stream->setFormatter(
    new LineFormatter("[%datetime%] %level_name%: %message% %context% %extra%\n", 'H:i:s')
);

$logger = new Logger(
    'backlog',
    [$stream],
    [
        new IntrospectionProcessor,
        new MemoryPeakUsageProcessor,
        new MemoryUsageProcessor,
        new UidProcessor,
        new WebProcessor
    ]
);

$twig = new Twig_Environment(
    new Twig_Loader_Filesystem(__DIR__ . '/../src/CvRing/Backlog/templates'),
    [
        'autoescape' => false, /* we escape manually */
        'cache' => __DIR__ . '/../cache/twig',
        'debug' => $debug,
        'strict_variables' => $debug
    ]
);

$twig->addExtension(new Twig_Extension_Optimizer());

$twig->addGlobal('APP_ENV', $appEnv);
$twig->addGlobal('config', $config);

$twig->addFunction(
    new Twig_SimpleFunction(
        'asset',
        function ($asset) {
            return '/' . ltrim($asset, '/');
        }
    )
);

$twig->addFunction(
    new Twig_SimpleFunction(
        'dump',
        function ($value) {
            ob_start();
            var_dump($value);
            return ob_get_clean();
        }
    )
);

$httpClient = new Client;
$httpClient->setOption('connectTimeout', 30);
$httpClient->setOption('userAgentString', 'CVBacklogUI/2.0.0 (https://github.com/Room-11/CVBacklogUI)');

$stackApi = new StackApi($httpClient, $config, $logger);

$chatCrawler = new ChatCrawler($httpClient, $config, $logger, $stackApi);

$cache = new FileCache($config);

$backlog = new BacklogCore($config, $chatCrawler, $cache, $logger, $stackApi);

/* inject dependencies */
$app = new Application(
    (new Provider)
        ->share($backlog)
        ->share($config)
        ->share($logger)
        ->share($twig)
);

require __DIR__ . '/../src/routes.php';

$app->run();
<commit_msg>Twig optimizer is loaded by default<commit_after><?php

use Artax\Client;
use Arya\Application;
use Auryn\Provider;
use CvRing\Backlog\BacklogCore;
use CvRing\Backlog\ConfigFile;
use CvRing\Backlog\FileCache;
use CvRing\Backlog\StackExchange\ChatCrawler;
use CvRing\Backlog\StackExchange\StackApi;
use Monolog\Formatter\LineFormatter;
use Monolog\Handler\RotatingFileHandler;
use Monolog\Logger;
use Monolog\Processor\IntrospectionProcessor;
use Monolog\Processor\MemoryPeakUsageProcessor;
use Monolog\Processor\MemoryUsageProcessor;
use Monolog\Processor\UidProcessor;
use Monolog\Processor\WebProcessor;

$config = new ConfigFile(__DIR__ . '/../config/backlog.ini');

/* keep a log for each day and rotate weekly */
$stream = new RotatingFileHandler(__DIR__ . "/../logs/backlog_$appEnv.log", 7, $logLevel);
$stream->setFormatter(
    new LineFormatter("[%datetime%] %level_name%: %message% %context% %extra%\n", 'H:i:s')
);

$logger = new Logger(
    'backlog',
    [$stream],
    [
        new IntrospectionProcessor,
        new MemoryPeakUsageProcessor,
        new MemoryUsageProcessor,
        new UidProcessor,
        new WebProcessor
    ]
);

$twig = new Twig_Environment(
    new Twig_Loader_Filesystem(__DIR__ . '/../src/CvRing/Backlog/templates'),
    [
        'autoescape' => false, /* we escape manually */
        'cache' => __DIR__ . '/../cache/twig',
        'debug' => $debug,
        'strict_variables' => $debug
    ]
);

$twig->addGlobal('APP_ENV', $appEnv);
$twig->addGlobal('config', $config);

$twig->addFunction(
    new Twig_SimpleFunction(
        'asset',
        function ($asset) {
            return '/' . ltrim($asset, '/');
        }
    )
);

$twig->addFunction(
    new Twig_SimpleFunction(
        'dump',
        function ($value) {
            ob_start();
            var_dump($value);
            return ob_get_clean();
        }
    )
);

$httpClient = new Client;
$httpClient->setOption('connectTimeout', 30);
$httpClient->setOption('userAgentString', 'CVBacklogUI/2.0.0 (https://github.com/Room-11/CVBacklogUI)');

$stackApi = new StackApi($httpClient, $config, $logger);

$chatCrawler = new ChatCrawler($httpClient, $config, $logger, $stackApi);

$cache = new FileCache($config);

$backlog = new BacklogCore($config, $chatCrawler, $cache, $logger, $stackApi);

/* inject dependencies */
$app = new Application(
    (new Provider)
        ->share($backlog)
        ->share($config)
        ->share($logger)
        ->share($twig)
);

require __DIR__ . '/../src/routes.php';

$app->run();

{'fraction_non_alphanumeric': 0.15260886622204786, 'fraction_numerical': 0.003138485680659082, 'mean_word_length': 3.457167832167832, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 36, 'https://': 2, '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': '2581811', 'n_tokens_mistral': 1699, 'n_tokens_neox': 1680, 'n_words': 325}