Completed
Push — master ( 55311e...acc5b2 )
by Craig
06:34
created

DefaultPathExtension::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 5
nc 1
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
/*
4
 * This file is part of the Zikula package.
5
 *
6
 * Copyright Zikula Foundation - http://zikula.org/
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 Zikula\ExtensionsModule\Twig\Extension;
13
14
use Symfony\Component\Routing\RouterInterface;
15
use Zikula\ExtensionsModule\Api\ApiInterface\CapabilityApiInterface;
16
17
class DefaultPathExtension extends \Twig_Extension
18
{
19
    /**
20
     * @var CapabilityApiInterface
21
     */
22
    private $capabilityApi;
23
24
    /**
25
     * @var RouterInterface
26
     */
27
    private $router;
28
29
    /**
30
     * DefaultPathExtension constructor.
31
     * @param CapabilityApiInterface $capabilityApi
32
     * @param RouterInterface $router
33
     */
34
    public function __construct(
35
        CapabilityApiInterface $capabilityApi,
36
        RouterInterface $router
37
    ) {
38
        $this->capabilityApi = $capabilityApi;
39
        $this->router = $router;
40
    }
41
42
    public function getDefaultPath($extensionName, $type = CapabilityApiInterface::USER)
43
    {
44
        $capability = $this->capabilityApi->isCapable($extensionName, $type);
45
        if (!$capability) {
46
            return '';
47
        }
48
        if (isset($capability['route'])) {
49
            return $this->router->generate($capability['route']);
50
        } elseif (isset($capability['url'])) {
51
            // BC - remove at Core-2.0
52
            return $capability['url'];
53
        }
54
55
        return '';
56
    }
57
}
58