Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CacheInitializationTrait
0.00% covered (danger)
0.00%
0 / 6
0.00% covered (danger)
0.00%
0 / 3
12
0.00% covered (danger)
0.00%
0 / 1
 initializeCache
0.00% covered (danger)
0.00%
0 / 4
0.00% covered (danger)
0.00%
0 / 1
2
 validateCacheDirectory
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 setupCache
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3declare(strict_types=1);
4
5namespace BO\Slim\Traits;
6
7use BO\Slim\Helper\CacheBootstrap;
8
9/**
10 * Shared cache initialization for module Application classes.
11 *
12 * Expects the using class to declare:
13 * - public static ?\Psr\SimpleCache\CacheInterface $cache
14 * - public static string $CACHE_DIR
15 * - public static int $SOURCE_CACHE_TTL
16 */
17trait CacheInitializationTrait
18{
19    private static function initializeCache(?string $fallbackCacheDir = null): void
20    {
21        [$cacheDir, $ttl] = CacheBootstrap::resolveConfig($fallbackCacheDir);
22        static::$CACHE_DIR = $cacheDir;
23        static::$SOURCE_CACHE_TTL = $ttl;
24        static::$cache = CacheBootstrap::create($cacheDir, $ttl);
25    }
26
27    private static function validateCacheDirectory(): void
28    {
29        CacheBootstrap::validateDirectory(static::$CACHE_DIR);
30    }
31
32    private static function setupCache(): void
33    {
34        static::$cache = CacheBootstrap::create(static::$CACHE_DIR, static::$SOURCE_CACHE_TTL);
35    }
36}