Security::getSecurity()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace Knp\RadBundle\Controller\Helper;
4
5
use Symfony\Component\Security\Core\Exception\AccessDeniedException;
6
use Symfony\Component\Security\Core\SecurityContextInterface;
7
8
class Security
9
{
10
    private $securityContext;
11
12
    public function __construct(SecurityContextInterface $securityContext)
13
    {
14
        $this->securityContext = $securityContext;
15
    }
16
17
    public function createAccessDeniedException($message = 'Access Denied', \Exception $previous = null)
18
    {
19
        return new AccessDeniedException($message, $previous);
20
    }
21
22
    public function isGranted($attributes, $object = null)
23
    {
24
        return $this->getSecurity()->isGranted($attributes, $object);
25
    }
26
27
    public function isGrantedOr403($attributes, $object = null)
28
    {
29
        if (!$this->isGranted($attributes, $object)) {
30
            throw $this->createAccessDeniedException();
31
        }
32
    }
33
34
    public function getSecurity()
35
    {
36
        return $this->securityContext;
37
    }
38
}
39