Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
40.00% covered (danger)
40.00%
2 / 5
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
Application
40.00% covered (danger)
40.00%
2 / 5
0.00% covered (danger)
0.00%
0 / 2
4.94
0.00% covered (danger)
0.00%
0 / 1
 http
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
 initialize
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2
3/**
4 * @package Zmsstatistic
5 * @copyright BerlinOnline Stadtportal GmbH & Co. KG
6 **/
7
8namespace BO\Zmsstatistic;
9
10use BO\Slim\Helper\ModuleLoggerInitializer;
11use BO\Zmsclient\Http;
12use Psr\SimpleCache\CacheInterface;
13
14define(
15    'ZMS_STATISTIC_SESSION_DURATION',
16    (int) ((($value = getenv('ZMS_STATISTIC_SESSION_DURATION')) !== false && $value !== '') ? $value : 36000)
17);
18
19if (($token = getenv('ZMS_CONFIG_SECURE_TOKEN')) === false || $token === '') {
20    throw new \RuntimeException('ZMS_CONFIG_SECURE_TOKEN environment variable must be set');
21}
22
23define('ZMS_CONFIG_SECURE_TOKEN', getenv('ZMS_CONFIG_SECURE_TOKEN'));
24
25if (!defined('ZMS_STATISTIC_TWIG_CACHE')) {
26    $value = getenv('ZMS_STATISTIC_TWIG_CACHE');
27    if ($value === 'false') {
28        define('ZMS_STATISTIC_TWIG_CACHE', false);
29    } elseif ($value === false || $value === '') {
30        define('ZMS_STATISTIC_TWIG_CACHE', '/cache/');
31    } else {
32        define('ZMS_STATISTIC_TWIG_CACHE', $value);
33    }
34}
35
36class Application extends \BO\Slim\Application
37{
38    /**
39     * Name of the application
40     *
41     */
42    const string IDENTIFIER = 'zms';
43
44    const string MODULE_NAME = 'zmsstatistic';
45
46    public static ?CacheInterface $cache = null;
47
48    const bool DEBUG = false;
49
50    const mixed TWIG_CACHE = ZMS_STATISTIC_TWIG_CACHE;
51
52    const int SESSION_DURATION = ZMS_STATISTIC_SESSION_DURATION;
53
54    /** @var string */
55    public static ?string $includeUrl = '/terminvereinbarung/statistic';
56    /**
57     * language preferences
58     */
59    public static string $locale = 'de';
60    /** @var array */
61    public static array $supportedLanguages = array(
62        // Default language
63        'de' => array(
64            'name'    => 'Deutsch',
65            'locale'  => 'de_DE',
66            'default' => true,
67        ),
68        // Other languages
69        'en' => array(
70            'name'    => 'English',
71            'locale'  => 'en_GB',
72        )
73    );
74
75    /**
76     * image preferences
77     */
78
79    /** @var bool */
80    public static bool $isImageAllowed = false;
81
82    /*
83     * -----------------------------------------------------------------------
84     * ZMS API access
85     */
86    public static ?Http $http = null;
87
88    public static function http(): Http
89    {
90        if (self::$http instanceof Http) {
91            return self::$http;
92        }
93        throw new \RuntimeException('HTTP client is not initialized');
94    }
95
96    public static array $http_curl_config = array();
97
98    const int JSON_COMPRESS_LEVEL = 1;
99
100    /**
101    * config preferences
102    */
103    const string CONFIG_SECURE_TOKEN = ZMS_CONFIG_SECURE_TOKEN;
104
105    /**
106     * HTTP url for api
107     */
108    const string HTTP_BASE_URL = 'http://user:pass@host.tdl';
109
110    public static function initialize(): void
111    {
112        ModuleLoggerInitializer::configure('ZMS_STATISTIC');
113        self::$cache = ModuleLoggerInitializer::tryInitializeCache();
114    }
115}
116
117Application::initialize();