Templates based on classes, cache custom paths

This commit is contained in:
Pablo Ferreiro 2022-01-25 17:20:11 +01:00
parent dde4185ad7
commit 6d6ec109ca
No known key found for this signature in database
GPG key ID: 41FBCE65B779FA24
26 changed files with 236 additions and 156 deletions

View file

@ -25,8 +25,8 @@ class Misc {
}
}
// Cache config
if (isset($_ENV['APP_CACHE'])) {
switch ($_ENV['APP_CACHE']) {
if (isset($_ENV['API_CACHE'])) {
switch ($_ENV['API_CACHE']) {
case 'json':
$cacheEngine = new JSONCache();
break;
@ -54,15 +54,24 @@ class Misc {
$subdir = '';
}
$latte = new \Latte\Engine;
$latte->setTempDirectory(__DIR__ . '/../cache/views');
$cache_path = isset($_ENV['LATTE_CACHE']) && !empty($_ENV['LATTE_CACHE']) ? $_ENV['LATTE_CACHE'] : __DIR__ . '/../cache/latte';
$latte->setTempDirectory($cache_path);
// -- CUSTOM FUNCTIONS -- //
// Import assets
$latte->addFunction('assets', function (string $name, string $type) use ($subdir) {
$path = "{$subdir}/{$type}/{$name}";
return $path;
});
// Relative path
$latte->addFunction('path', function (string $name) use ($subdir) {
$path = "{$subdir}/{$name}";
return $path;
});
// Version being used
$latte->addFunction('version', function () {
return \Composer\InstalledVersions::getVersion('pablouser1/proxitok');
});
// https://stackoverflow.com/a/36365553
$latte->addFunction('number', function (int $x) {
if($x > 1000) {