1 | <?php |
||
2 | |||
3 | /* |
||
4 | * This file is part of the Tadcka package. |
||
5 | * |
||
6 | * (c) Tadas Gliaubicas <[email protected]> |
||
7 | * |
||
8 | * For the full copyright and license information, please view the LICENSE |
||
9 | * file that was distributed with this source code. |
||
10 | */ |
||
11 | |||
12 | namespace Tadcka\Component\Routing; |
||
13 | |||
14 | use Symfony\Cmf\Component\Routing\RouteObjectInterface; |
||
15 | use Symfony\Component\HttpFoundation\Request; |
||
16 | use Tadcka\Component\Routing\Model\RouteInterface; |
||
17 | |||
18 | /** |
||
19 | * Class RouteAwareTrait. |
||
20 | * |
||
21 | * @package Tadcka\Component\Routing |
||
22 | */ |
||
23 | trait RouteAwareTrait |
||
24 | { |
||
25 | /** |
||
26 | * Get route from request. |
||
27 | * |
||
28 | * @param Request $request |
||
29 | * |
||
30 | * @return null|RouteInterface |
||
31 | */ |
||
32 | protected function getRouteFromRequest(Request $request) |
||
33 | { |
||
34 | $attributes = $request->attributes->get('_route_params'); |
||
35 | |||
36 | if (isset($attributes[RouteObjectInterface::ROUTE_OBJECT]) |
||
37 | && ($attributes[RouteObjectInterface::ROUTE_OBJECT] instanceof RouteInterface) |
||
38 | ) { |
||
39 | return $attributes[RouteObjectInterface::ROUTE_OBJECT]; |
||
40 | } |
||
41 | |||
42 | return null; |
||
43 | } |
||
44 | } |
||
45 |