Completed
Push — develop ( 0e6c87...fa3267 )
by
unknown
07:28
created

DefaultNavigationFactory   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
B injectComponents() 0 19 5
1
<?php
2
/**
3
 * YAWIK
4
 *
5
 * @filesource
6
 * @license MIT
7
 * @copyright  2013 - 2016 Cross Solution <http://cross-solution.de>
8
 */
9
  
10
/** */
11
namespace Core\Factory\Navigation;
12
13
use Zend\Navigation\Service\DefaultNavigationFactory as ZfDefaultNavigationFactory;
14
use Zend\Mvc\Router as MvcRouter;
15
use Zend\Mvc\Router\RouteMatch;
16
17
/**
18
 * Extends the ZF DefaultNavigationFactory to let it set
19
 * active flags on pages when the route matches an entry
20
 * in the "active_on" option.
21
 * 
22
 * @author Mathias Gelhausen <[email protected]>
23
 * @since 0.26
24
 * @since 0.30 - will do nothing if $routeMatch is null
25
 *               (prevent fatal error)
26
 */
27
class DefaultNavigationFactory extends ZfDefaultNavigationFactory
28
{
29
30
    /**
31
     * Inject components into the pages.
32
     *
33
     * @internal
34
     *      Parses the pages options for the "active_on" property and
35
     *      sets the active flag if one of the routes match.
36
     *
37
     * {@inheritDoc}
38
     * @since 0.30 add check, if $routeMatch is null
39
     */
40
    protected function injectComponents(
41
        array $pages,
42
        $routeMatch = null,
43
        $router = null,
44
        $request = null
45
    ) {
46
        if ($routeMatch) {
47
            /* @var RouteMatch|MvcRouter\RouteMatch $routeMatch */
48
            $routeName = $routeMatch->getMatchedRouteName();
49
50
            foreach ($pages as &$page) {
51
                if (isset($page['active_on']) && in_array($routeName, (array) $page['active_on'])) {
52
                    $page['active'] = true;
53
                }
54
            }
55
        }
56
57
        return parent::injectComponents($pages, $routeMatch, $router, $request);
58
    }
59
60
61
}