Completed
Push — development ( b65fd0...1c81ac )
by Torben
02:57
created

BeUserSessionService   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 56
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A saveSessionData() 0 4 1
A getSessionData() 0 4 1
A getSessionDataByKey() 0 9 3
A getBackendUser() 0 4 1
1
<?php
2
namespace DERHANSEN\SfEventMgt\Service;
3
4
/*
5
 * This file is part of the TYPO3 CMS project.
6
 *
7
 * It is free software; you can redistribute it and/or modify it under
8
 * the terms of the GNU General Public License, either version 2
9
 * of the License, or any later version.
10
 *
11
 * For the full copyright and license information, please read the
12
 * LICENSE.txt file that was distributed with this source code.
13
 *
14
 * The TYPO3 project - inspiring people to share!
15
 */
16
17
/**
18
 * BeUserSessionService
19
 *
20
 * @author Torben Hansen <[email protected]>
21
 */
22
class BeUserSessionService
23
{
24
    /**
25
     * The session key
26
     *
27
     * @var string
28
     */
29
    const SESSION_KEY = 'sf_event_mgt';
30
31
    /**
32
     * Saves the given data to the session
33
     *
34
     * @param array $data
35
     * @return void
36
     */
37
    public function saveSessionData($data)
38
    {
39
        $this->getBackendUser()->setAndSaveSessionData(self::SESSION_KEY, $data);
40
    }
41
42
    /**
43
     * Returns the session data
44
     *
45
     * @return mixed
46
     */
47
    public function getSessionData()
48
    {
49
        return $this->getBackendUser()->getSessionData(self::SESSION_KEY);
50
    }
51
52
    /**
53
     * Returns a specific value from the session data by the given key
54
     *
55
     * @param string $key
56
     * @return mixed|null
57
     */
58
    public function getSessionDataByKey($key)
59
    {
60
        $result = null;
61
        $data = $this->getSessionData();
62
        if (is_array($data) && isset($data[$key])) {
63
            $result = $data[$key];
64
        }
65
        return $result;
66
    }
67
68
    /**
69
     * Returns the current Backend User
70
     *
71
     * @return mixed|\TYPO3\CMS\Core\Authentication\BackendUserAuthentication
72
     */
73
    protected function getBackendUser()
74
    {
75
        return $GLOBALS['BE_USER'];
76
    }
77
}
78