Completed
Push — master ( d01ad3...6b97e6 )
by Paweł
21s queued 10s
created

FinalMatcher   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 4
dl 0
loc 29
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A finalMatch() 0 9 1
A getAttributes() 0 10 3
1
<?php
2
3
/*
4
 * This file is part of the Superdesk Web Publisher Content Bundle.
5
 *
6
 * Copyright 2019 Sourcefabric z.ú. and contributors.
7
 *
8
 * For the full copyright and license information, please see the
9
 * AUTHORS and LICENSE files distributed with this source code.
10
 *
11
 * @copyright 2019 Sourcefabric z.ú
12
 * @license http://www.superdesk.org/license
13
 */
14
15
namespace SWP\Bundle\ContentBundle\Routing;
16
17
use Symfony\Bundle\FrameworkBundle\Routing\RedirectableUrlMatcher;
18
use Symfony\Cmf\Component\Routing\NestedMatcher\FinalMatcherInterface;
19
use Symfony\Cmf\Component\Routing\RouteObjectInterface;
20
use Symfony\Component\HttpFoundation\Request;
21
use Symfony\Component\Routing\RequestContext;
22
use Symfony\Component\Routing\Route;
23
use Symfony\Component\Routing\RouteCollection;
24
25
class FinalMatcher extends RedirectableUrlMatcher implements FinalMatcherInterface
26
{
27
    /**
28
     * {@inheritdoc}
29
     */
30
    public function finalMatch(RouteCollection $collection, Request $request)
31
    {
32
        $this->routes = $collection;
33
        $context = new RequestContext();
34
        $context->fromRequest($request);
35
        $this->setContext($context);
36
37
        return $this->match($request->getPathInfo());
38
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43
    protected function getAttributes(Route $route, $name, array $attributes)
44
    {
45
        if ($route instanceof RouteObjectInterface && is_string($route->getRouteKey())) {
46
            $name = $route->getRouteKey();
47
        }
48
        $attributes[RouteObjectInterface::ROUTE_NAME] = $name;
49
        $attributes[RouteObjectInterface::ROUTE_OBJECT] = $route;
50
51
        return $this->mergeDefaults($attributes, $route->getDefaults());
52
    }
53
}
54