. // }}} namespace App\Core\Cache; use Functional as F; use Symfony\Component\Cache\Adapter\AbstractAdapter; use Symfony\Component\Cache\Adapter\ChainAdapter; abstract class Cache { protected static AbstractAdapter $pool; private const ENV_VAR = 'SOCIAL_CACHE_ADAPTER'; /** * Configure a cache pool, with adapters taken from `ENV_VAR`. * We may want multiple of these in the future, but for now it seems * unnecessary */ public static function setPool() { if (!isset($_ENV[ENV_VAR])) { return; } $adapters = F\map(explode(':', strtolower($_ENV[ENV_VAR])), function (string $a) { return 'Adapter\\' . ucfirst($a) . 'Adapter'; }); if (count($adapters) === 1) { self::$pool = new $adapters[0]; } else { self::$pool = new ChainAdapter($adapters); } } /** * Forward calls to the configured $pool */ public static function __callStatic(string $name, array $args) { return self::$pool->{$name}(...$args); } }