Completed
Pull Request — dev (#50)
by Arnaud
02:55
created

RequestHandler::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 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
    public function __construct(Registry $registry)
18
    {
19
        $this->registry = $registry;
20
    }
21
22
    public function handle(Request $request)
23
    {
24
        $routeParameters = $request->get('_route_params');
25
26
        if (!$routeParameters) {
27
            throw new Exception('Cannot find admin from request. _route_params parameters for request not found');
28
        }
29
        if (!array_key_exists('_admin', $routeParameters)) {
30
            throw new Exception('Cannot find admin from request. "_admin" route parameter is missing');
31
        }
32
        if (!array_key_exists('_action', $routeParameters)) {
33
            throw new Exception('Cannot find admin action from request. "_action" route parameter is missing');
34
        }
35
36
        return $this
37
            ->registry
38
            ->get($routeParameters['_admin']);
39
    }
40
}
41