You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
38 lines
1.3 KiB
PHTML
38 lines
1.3 KiB
PHTML
|
2 months ago
|
<?php
|
||
|
|
|
||
|
|
require dirname(__DIR__) . '/vendor/autoload.php';
|
||
|
|
|
||
|
|
$directory = sys_get_temp_dir() . '/virt-cloud-template-test-' . bin2hex(random_bytes(8));
|
||
|
|
if (!mkdir($directory, 0700)) {
|
||
|
|
throw new RuntimeException('Cannot create private template-test directory');
|
||
|
|
}
|
||
|
|
$smarty = new Smarty();
|
||
|
|
$smarty->setTemplateDir(dirname(__DIR__) . '/resources/views/venix');
|
||
|
|
$smarty->setCompileDir($directory);
|
||
|
|
$smarty->setCacheDir($directory);
|
||
|
|
foreach (['urlencode', 'number_format', 'date'] as $modifier) {
|
||
|
|
$smarty->registerPlugin('modifier', $modifier, $modifier);
|
||
|
|
}
|
||
|
|
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator(
|
||
|
|
dirname(__DIR__) . '/resources/views/venix', FilesystemIterator::SKIP_DOTS
|
||
|
|
));
|
||
|
|
$count = 0;
|
||
|
|
try {
|
||
|
|
foreach ($iterator as $file) {
|
||
|
|
if ($file->getExtension() !== 'tpl') {
|
||
|
|
continue;
|
||
|
|
}
|
||
|
|
$template = $smarty->createTemplate($file->getPathname());
|
||
|
|
$template->compileTemplateSource();
|
||
|
|
$count++;
|
||
|
|
}
|
||
|
|
} finally {
|
||
|
|
foreach (new FilesystemIterator($directory, FilesystemIterator::SKIP_DOTS) as $generated) {
|
||
|
|
if ($generated->isFile()) {
|
||
|
|
unlink($generated->getPathname());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
rmdir($directory);
|
||
|
|
}
|
||
|
|
echo 'Smarty venix templates compiled without rendering or database access: ' . $count . ".\n";
|