Completed
Push — master ( 530ce9...1b2ae5 )
by Paweł
23:42 queued 20:31
created

MetaRouter::generate()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
c 2
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 2
nop 3
1
<?php
2
3
/**
4
 * This file is part of the Superdesk Web Publisher Web Renderer Bundle.
5
 *
6
 * Copyright 2015 Sourcefabric z.u. 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 2015 Sourcefabric z.ú.
12
 * @license http://www.superdesk.org/license
13
 */
14
namespace SWP\Bundle\WebRendererBundle\Routing;
15
16
use Symfony\Cmf\Bundle\RoutingBundle\Routing\DynamicRouter;
17
use SWP\TemplatesSystem\Gimme\Meta\Meta;
18
use SWP\Bundle\ContentBundle\Document\Article;
19
20
class MetaRouter extends DynamicRouter
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function generate($name, $parameters = array(), $referenceType = false)
26
    {
27
        $route = $name;
28
        if ($name instanceof Meta && $name->getValues() instanceof Article) {
29
            $parameters['slug'] = $name->getValues()->getSlug();
30
            $route = $name->getValues()->getRoute();
31
        }
32
33
        return parent::generate($route, $parameters, $referenceType);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function supports($name)
40
    {
41
        return $name instanceof Meta;
42
    }
43
}
44