Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| Application | |
0.00% |
0 / 11 |
|
0.00% |
0 / 4 |
90 | |
0.00% |
0 / 1 |
| initializeCache | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| validateCacheDirectory | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
20 | |||
| setupCache | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| initialize | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @package Zmsdb |
| 5 | * @copyright BerlinOnline Stadtportal GmbH & Co. KG |
| 6 | **/ |
| 7 | |
| 8 | namespace BO\Zmsdb; |
| 9 | |
| 10 | use Psr\SimpleCache\CacheInterface; |
| 11 | use Symfony\Component\Cache\Adapter\FilesystemAdapter; |
| 12 | use Symfony\Component\Cache\Psr16Cache; |
| 13 | |
| 14 | define( |
| 15 | 'ZMSDB_SESSION_DURATION', |
| 16 | getenv('ZMSDB_SESSION_DURATION') ? getenv('ZMSDB_SESSION_DURATION') : 28800 |
| 17 | ); |
| 18 | |
| 19 | class Application extends \BO\Slim\Application |
| 20 | { |
| 21 | /** |
| 22 | * Name of the application |
| 23 | */ |
| 24 | const IDENTIFIER = 'zms'; |
| 25 | |
| 26 | const MODULE_NAME = 'zmsdb'; |
| 27 | |
| 28 | const DEBUG = false; |
| 29 | |
| 30 | const SESSION_DURATION = ZMSDB_SESSION_DURATION; |
| 31 | |
| 32 | public static ?CacheInterface $cache = null; |
| 33 | // Cache config |
| 34 | public static string $CACHE_DIR; |
| 35 | public static int $SOURCE_CACHE_TTL; |
| 36 | |
| 37 | /** |
| 38 | * Default parameters for templates |
| 39 | */ |
| 40 | public static $templatedefaults = array(); |
| 41 | |
| 42 | /** |
| 43 | * Default parameters for middleware HttpBasicAuth |
| 44 | */ |
| 45 | public static $httpBasicAuth = array(); |
| 46 | |
| 47 | /** |
| 48 | * image preferences |
| 49 | */ |
| 50 | public static $isImageAllowed = false; |
| 51 | |
| 52 | /** |
| 53 | * language preferences |
| 54 | */ |
| 55 | const MULTILANGUAGE = true; |
| 56 | public static $locale = 'de'; |
| 57 | public static $supportedLanguages = array( |
| 58 | // Default language |
| 59 | 'de' => array( |
| 60 | 'name' => 'Deutsch', |
| 61 | 'locale' => 'de_DE', |
| 62 | 'default' => true, |
| 63 | ), |
| 64 | // Other languages |
| 65 | 'en' => array( |
| 66 | 'name' => 'English', |
| 67 | 'locale' => 'en_GB', |
| 68 | ) |
| 69 | ); |
| 70 | |
| 71 | private static function initializeCache(): void |
| 72 | { |
| 73 | self::$CACHE_DIR = getenv('CACHE_DIR') ?: __DIR__ . '/cache'; |
| 74 | self::$SOURCE_CACHE_TTL = (int) (getenv('SOURCE_CACHE_TTL') ?: 3600); |
| 75 | self::validateCacheDirectory(); |
| 76 | self::setupCache(); |
| 77 | } |
| 78 | |
| 79 | private static function validateCacheDirectory(): void |
| 80 | { |
| 81 | if (!is_dir(self::$CACHE_DIR) && !mkdir(self::$CACHE_DIR, 0750, true)) { |
| 82 | throw new \RuntimeException(sprintf('Cache directory "%s" could not be created', self::$CACHE_DIR)); |
| 83 | } |
| 84 | |
| 85 | if (!is_writable(self::$CACHE_DIR)) { |
| 86 | throw new \RuntimeException(sprintf('Cache directory "%s" is not writable', self::$CACHE_DIR)); |
| 87 | } |
| 88 | } |
| 89 | |
| 90 | private static function setupCache(): void |
| 91 | { |
| 92 | $psr6 = new FilesystemAdapter(namespace: '', defaultLifetime: self::$SOURCE_CACHE_TTL, directory: self::$CACHE_DIR); |
| 93 | self::$cache = new Psr16Cache($psr6); |
| 94 | } |
| 95 | |
| 96 | public static function initialize(): void |
| 97 | { |
| 98 | self::initializeCache(); |
| 99 | } |
| 100 | } |
| 101 | |
| 102 | Application::initialize(); |