BeUserSessionService::saveSessionData()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the Extension "sf_event_mgt" for TYPO3 CMS.
7
 *
8
 * For the full copyright and license information, please read the
9
 * LICENSE.txt file that was distributed with this source code.
10
 */
11
12
namespace DERHANSEN\SfEventMgt\Service;
13
14
use TYPO3\CMS\Core\Authentication\BackendUserAuthentication;
15
16
class BeUserSessionService
17
{
18
    private const SESSION_KEY = 'sf_event_mgt';
19
20
    /**
21
     * Saves the given data to the session
22
     */
23
    public function saveSessionData(array $data): void
24
    {
25
        $this->getBackendUser()->setAndSaveSessionData(self::SESSION_KEY, $data);
26
    }
27
28
    /**
29
     * Returns the session data
30
     *
31
     * @return mixed
32
     */
33
    public function getSessionData()
34
    {
35
        return $this->getBackendUser()->getSessionData(self::SESSION_KEY);
36
    }
37
38
    /**
39
     * Returns a specific value from the session data by the given key
40
     *
41
     * @return mixed|null
42
     */
43
    public function getSessionDataByKey(string $key)
44
    {
45
        $result = null;
46
        $data = $this->getSessionData();
47
        if (is_array($data) && isset($data[$key])) {
48
            $result = $data[$key];
49
        }
50
51
        return $result;
52
    }
53
54
    protected function getBackendUser(): ?BackendUserAuthentication
55
    {
56
        return $GLOBALS['BE_USER'] ?? null;
57
    }
58
}
59