getAuthenticatedParticipant()   A
last analyzed

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 5
nc 2
nop 0
1
<?php
2
3
/*
4
 * This file is part of the MilioooMessageBundle package.
5
 *
6
 * (c) Michiel boeckaert <[email protected]>
7
 * This source file is subject to the MIT license that is bundled
8
 * with this source code in the file LICENSE.
9
 */
10
11
namespace Miliooo\Messaging\User;
12
13
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
14
use Symfony\Component\Security\Core\Authentication\Token\TokenInterface;
15
16
/**
17
 * Participant provider from the security token.
18
 *
19
 * This is the participant provider implementation using the security token
20
 * from the symfony security context.
21
 *
22
 * @author Michiel Boeckaert <[email protected]>
23
 */
24
class ParticipantProviderSecurityToken implements ParticipantProviderInterface
25
{
26
    protected $securityToken;
27
28
    /**
29
     * Constructor.
30
     *
31
     * @param TokenInterface $securityToken A security token
32
     */
33
    public function __construct(TokenInterface $securityToken)
34
    {
35
        $this->securityToken = $securityToken;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getAuthenticatedParticipant()
42
    {
43
        $participant = $this->securityToken->getUser();
44
45
        if (!is_object($participant) || !$participant instanceof ParticipantInterface) {
46
            throw new AccessDeniedException('You must be logged in with a participant interface');
47
        }
48
49
        return $participant;
50
    }
51
}
52