Completed
Pull Request — master (#165)
by Paul
03:21
created

YamlFileLoader   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1
Metric Value
wmc 3
lcom 1
cbo 1
dl 0
loc 36
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A parseRoute() 0 8 2
A setDefaults() 0 4 1
1
<?php
2
/**
3
 * This file is part of the PPI Framework.
4
 *
5
 * @copyright  Copyright (c) 2011-2016 Paul Dragoonis <[email protected]>
6
 * @license    http://opensource.org/licenses/mit-license.php MIT
7
 *
8
 * @link       http://www.ppi.io
9
 */
10
11
namespace PPI\Framework\Router\Loader;
12
13
use Symfony\Component\Routing\Loader\YamlFileLoader as BaseYamlFileLoader;
14
use Symfony\Component\Routing\RouteCollection;
15
16
/**
17
 * YamlFileLoader class.
18
 *
19
 * @author     Paul Dragoonis <[email protected]>
20
 * @author     Vítor Brandão <[email protected]>
21
 */
22
class YamlFileLoader extends BaseYamlFileLoader
23
{
24
    /**
25
     * The loader defaults.
26
     *
27
     * @var array
28
     */
29
    protected $defaults = array();
30
31
    /**
32
     * Constructor.
33
     *
34
     * @param array $defaults
35
     */
36
    public function setDefaults($defaults)
37
    {
38
        $this->defaults = $defaults;
39
    }
40
41
    /**
42
     * Parses a route and adds it to the RouteCollection.
43
     *
44
     * @param RouteCollection $collection A RouteCollection instance
45
     * @param string          $name       Route name
46
     * @param array           $config     Route definition
47
     * @param string          $path       Full path of the YAML file being processed
48
     */
49
    protected function parseRoute(RouteCollection $collection, $name, array $config, $path)
50
    {
51
        if (!empty($this->defaults)) {
52
            $config['defaults'] = array_merge($config['defaults'], $this->defaults);
53
        }
54
55
        parent::parseRoute($collection, $name, $config, $path);
56
    }
57
}
58