Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
9 / 9
CRAP
100.00% covered (success)
100.00%
1 / 1
WithUtilsTrait
100.00% covered (success)
100.00%
18 / 18
100.00% covered (success)
100.00%
9 / 9
10
100.00% covered (success)
100.00%
1 / 1
 getParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createGetParams
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setGetParams
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 server
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createServer
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setServer
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getAllUtils
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setAllUtils
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 getOrCreate
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2
3namespace Olz\Utils;
4
5use Olz\Captcha\Utils\CaptchaUtilsTrait;
6use Olz\Fetchers\SolvFetcherTrait;
7use Olz\News\Utils\NewsUtilsTrait;
8use Olz\Suche\Utils\SearchUtilsTrait;
9use Olz\Termine\Utils\TermineUtilsTrait;
10
11trait WithUtilsTrait {
12    use AuthUtilsTrait;
13    use CaptchaUtilsTrait;
14    use DateUtilsTrait;
15    use DbUtilsTrait;
16    use DevDataUtilsTrait;
17    use EmailUtilsTrait;
18    use EntityManagerTrait;
19    use EntityUtilsTrait;
20    use EnvUtilsTrait;
21    use GeneralUtilsTrait;
22    use HtmlUtilsTrait;
23    use HttpUtilsTrait;
24    use IdUtilsTrait;
25    use ImageUtilsTrait;
26    use LogTrait;
27    use MapUtilsTrait;
28    use MailerTrait;
29    use MessageBusTrait;
30    use NewsUtilsTrait;
31    use SearchUtilsTrait;
32    use SessionTrait;
33    use SolvFetcherTrait;
34    use SymfonyUtilsTrait;
35    use TelegramUtilsTrait;
36    use TermineUtilsTrait;
37    use UploadUtilsTrait;
38
39    // Legacy implementation
40    // TODO: Migrate away!
41
42    /**
43     * @return array<string, string>
44     */
45    public function getParams(): array {
46        return $this->getOrCreate('getParams');
47    }
48
49    /**
50     * @return array<string, string>
51     */
52    public function createGetParams(): array {
53        global $_GET;
54        return $_GET;
55    }
56
57    /**
58     * @param array<string, string> $getParams
59     */
60    public function setGetParams(array $getParams): void {
61        WithUtilsCache::set('getParams', $getParams);
62    }
63
64    /**
65     * @return array<string, mixed>
66     */
67    public function server(): array {
68        return $this->getOrCreate('server');
69    }
70
71    /**
72     * @return array<string, mixed>
73     */
74    public function createServer(): array {
75        global $_SERVER;
76        return $_SERVER;
77    }
78
79    /**
80     * @param array<string, mixed> $server
81     */
82    public function setServer(array $server): void {
83        WithUtilsCache::set('server', $server);
84    }
85
86    // ---
87
88    /**
89     * @return array<string, mixed>
90     */
91    public function getAllUtils(): array {
92        return WithUtilsCache::getAll();
93    }
94
95    /**
96     * @param array<string, mixed> $all_utils
97     */
98    public function setAllUtils(array $all_utils): void {
99        WithUtilsCache::setAll($all_utils);
100    }
101
102    protected function getOrCreate(string $util_name): mixed {
103        $util = WithUtilsCache::get($util_name);
104        if ($util) {
105            return $util;
106        }
107        $cap_util_name = ucfirst($util_name);
108        $creator_name = "create{$cap_util_name}";
109        $util = $this->{$creator_name}();
110        WithUtilsCache::set($util_name, $util);
111        return $util;
112    }
113}