Passed
Pull Request — master (#166)
by
unknown
21:05
created

Security::getUserRole()   B

Complexity

Conditions 9
Paths 54

Size

Total Lines 34
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 9
eloc 17
c 1
b 0
f 0
nc 54
nop 0
dl 0
loc 34
rs 8.0555
1
<?php
2
namespace EWW\Dpf\Security;
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
class Security
18
{
19
    /**
20
     * frontendUserRepository
21
     *
22
     * @var \EWW\Dpf\Domain\Repository\FrontendUserRepository
23
     * @inject
24
     */
25
    protected $frontendUserRepository = null;
26
27
    const ROLE_ANONYMOUS = "ROLE_ANONYMOUS";
28
    const ROLE_RESEARCHER = "ROLE_RESEARCHER";
29
    const ROLE_LIBRARIAN = "ROLE_LIBRARIAN";
30
31
32
    /**
33
     * Gets the current logged in frontend user
34
     *
35
     * @return null|\EWW\Dpf\Domain\Model\FrontendUser
36
     */
37
    public function getUser()
38
    {
39
        $user = $GLOBALS['TSFE']->fe_user->user;
40
        if (!empty($user) && is_array($user) && array_key_exists('uid', $user)) {
41
            return $this->frontendUserRepository->findByUid($GLOBALS['TSFE']->fe_user->user['uid']);
42
        } else {
43
            return NULL;
44
        }
45
    }
46
47
}
48