Completed
Push — master ( 5bcd6a...b668e1 )
by Jim
04:48 queued 01:57
created

AbstractController::denyAccessUnlessGranted()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 3
eloc 3
nc 2
nop 3
1
<?php
2
3
/*
4
 * (c) Jim Martens <[email protected]>
5
 *
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 */
9
10
namespace TwoMartens\Bundle\CoreBundle\Controller;
11
12
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
13
14
/**
15
 * Empowers ROLE_SUPER_ADMIN to do everything.
16
 *
17
 * Extends the denyAccessUnlessGranted method to check
18
 * if either provided role or ROLE_SUPER_ADMIN is granted.
19
 * If both are not granted it throws an exception.
20
 *
21
 * @author    Jim Martens <[email protected]>
22
 * @copyright 2013-2016 Jim Martens
23
 */
24
abstract class AbstractController extends Controller
25
{
26
    /**
27
     * {@inheritdoc}
28
     */
29
    protected function denyAccessUnlessGranted($attributes, $object = null, $message = 'Access Denied.')
30
    {
31
        if (!$this->isGranted($attributes, $object) && !$this->isGranted('ROLE_SUPER_ADMIN', $object)) {
32
            throw $this->createAccessDeniedException($message);
33
        }
34
    }
35
}
36