Completed
Pull Request — dev (#50)
by Arnaud
03:27
created

RequestHandler::handle()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.2
c 0
b 0
f 0
cc 4
eloc 11
nc 4
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