/
generate-twig-cache
37 lines (33 loc) · 1.12 KB
/
generate-twig-cache
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/* vim: set expandtab sw=4 ts=4 sts=4 ft=php: */
define('PHPMYADMIN', 1);
require_once 'vendor/autoload.php';
require_once 'libraries/vendor_config.php';
use PMA\libraries\twig\I18nExtension;
use PMA\libraries\twig\UrlExtension;
use PMA\libraries\twig\UtilExtension;
$tplDir = dirname(__FILE__) . '/../templates';
$tmpDir = dirname(__FILE__) . '/../' . CACHE_DIR . 'twig';
$loader = new Twig_Loader_Filesystem($tplDir);
// force auto-reload to always have the latest version of the template
$twig = new Twig_Environment($loader, array(
'cache' => $tmpDir,
'auto_reload' => true
));
$twig->addExtension(new I18nExtension());
$twig->addExtension(new UrlExtension());
$twig->addExtension(new UtilExtension());
// iterate over all templates
foreach (new RecursiveIteratorIterator(
new RecursiveDirectoryIterator($tplDir),
RecursiveIteratorIterator::LEAVES_ONLY
) as $file) {
// Skip test files
if (strpos($file, '/test/') !== false) {
continue;
}
// force compilation
if ($file->isFile() && $file->getExtension() == 'twig') {
$twig->loadTemplate(str_replace($tplDir.'/', '', $file));
}
}