RouteLinkComponent   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 2
lcom 0
cbo 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A configure() 0 7 1
A onRender() 0 9 1
1
<?php
2
/**
3
 * Webino™ (http://webino.sk)
4
 *
5
 * @link        https://github.com/webino for the canonical source repository
6
 * @copyright   Copyright (c) 2015-2017 Webino, s.r.o. (http://webino.sk)
7
 * @author      Peter Bačinský <[email protected]>
8
 * @license     BSD-3-Clause
9
 */
10
11
namespace WebinoAppLib\View;
12
13
use WebinoAppLib\Service\Initializer\RoutingAwareInterface;
14
use WebinoAppLib\Service\Initializer\RoutingAwareTrait;
15
use WebinoDomLib\Event\RenderEvent;
16
use WebinoViewLib\Component\AbstractBaseViewComponent;
17
use WebinoViewLib\Component\OnRenderComponentInterface;
18
use WebinoViewLib\Feature\NodeView;
19
20
/**
21
 * Class RouteLinkComponent
22
 */
23
class RouteLinkComponent extends AbstractBaseViewComponent implements
24
    OnRenderComponentInterface,
25
    RoutingAwareInterface
26
{
27
    use RoutingAwareTrait;
28
29
    /**
30
     * @param NodeView $node
31
     */
32
    public function configure(NodeView $node)
33
    {
34
        $node
35
            ->setLocator('route-link')
36
            ->setPriority(-100)
37
            ->setRename('a');
38
    }
39
40
    /**
41
     * @param RenderEvent $event
42
     */
43
    public function onRender(RenderEvent $event)
44
    {
45
        $node  = $event->getNode();
46
        $route = $node->getAttribute('route');
47
48
        $node
49
            ->setAttribute('href', $this->getRouter()->url($route))
50
            ->setAttribute('route', null);
51
    }
52
}
53