Completed
Push — master ( bd4cbc...df0c76 )
by Arnaud
9s
created

RequestHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
namespace LAG\AdminBundle\Admin\Request;
4
5
6
use Exception;
7
use LAG\AdminBundle\Admin\Registry\Registry;
8
use Symfony\Component\HttpFoundation\Request;
9
10
class RequestHandler
11
{
12
    /**
13
     * @var Registry
14
     */
15
    protected $registry;
16
17 1
    public function __construct(Registry $registry)
18
    {
19 1
        $this->registry = $registry;
20 1
    }
21
22 1
    public function handle(Request $request)
23
    {
24 1
        $routeParameters = $request->get('_route_params');
25
26 1
        if (!$routeParameters) {
27
            throw new Exception('Cannot find admin from request. _route_params parameters for request not found');
28
        }
29 1
        if (!array_key_exists('_admin', $routeParameters)) {
30
            throw new Exception('Cannot find admin from request. "_admin" route parameter is missing');
31
        }
32 1
        if (!array_key_exists('_action', $routeParameters)) {
33
            throw new Exception('Cannot find admin action from request. "_action" route parameter is missing');
34
        }
35
36 1
        return $this
37
            ->registry
38 1
            ->get($routeParameters['_admin']);
39
    }
40
}
41