Merge pull request #5 from Zankaria/local-vars

PR fixup
This commit is contained in:
Alex 2025-04-25 21:51:42 +00:00 committed by GitHub
commit 3781a10776
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 19 additions and 18 deletions

View File

@ -12,10 +12,10 @@ defined('TINYBOARD') or exit;
class Cache {
private static function buildCache(): CacheDriver {
global $config;
// Determine if Redis is configured via environment variables
getenv('VICHAN_CACHE_ENGINE') && $config['cache']['enabled'] = getenv('VICHAN_CACHE_ENGINE');
// Determine if the cache engine is configured via environment variables.
$engine = \getenv('VICHAN_CACHE_ENGINE') ?: $config['cache']['enabled'];
switch ($config['cache']['enabled']) {
switch ($engine) {
case 'memcached':
return new MemcachedCacheDriver(
$config['cache']['prefix'],
@ -31,7 +31,7 @@ class Cache {
$port = getenv('VICHAN_CACHE_PORT') ?: $port;
$password = getenv('VICHAN_CACHE_PASSWORD') ?: $password;
$database = getenv('VICHAN_CACHE_DATABASE') ?: $database;
return new RedisCacheDriver(
$config['cache']['prefix'],
$host,

View File

@ -142,7 +142,8 @@ class Tinyboard extends Twig\Extension\AbstractExtension
new Twig\TwigFunction('ratio', 'twig_ratio_function'),
new Twig\TwigFunction('secure_link_confirm', 'twig_secure_link_confirm'),
new Twig\TwigFunction('secure_link', 'twig_secure_link'),
new Twig\TwigFunction('link_for', 'link_for')
new Twig\TwigFunction('link_for', 'link_for'),
new Twig\TwigFunction('check_container', 'twig_check_container')
);
}
@ -226,18 +227,18 @@ function twig_secure_link($href) {
return $href . '/' . make_secure_link_token($href);
}
// /*
// * ====================
// * Container Detection
// * ===================
// */
/*
* ====================
* Container Detection
* ===================
*/
function twig_check_container() {
global $config;
$isDocker = is_file("/.dockerenv") || is_file("/run/.containerenv");
$isKubernetes = is_file("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
$config['is_container'] = $isDocker || $isKubernetes ? true : false;
$config['is_docker'] = $isDocker;
$config['is_kubernetes'] = $isKubernetes;
return $config['is_container'];
}
static $is_container = null;
if ($is_container === null) {
$is_docker = \is_file("/.dockerenv") || \is_file("/run/.containerenv");
$is_kubernetes = \is_file("/var/run/secrets/kubernetes.io/serviceaccount/namespace");
$is_container = $is_docker || $is_kubernetes;
}
return $is_container;
}