Completed
Pull Request — master (#2)
by Beñat
02:41
created

RoutesLoaderBuilder::defaultRoutePath()

Size

Total Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 1
c 0
b 0
f 0
nc 1
1
<?php
2
3
/*
4
 * This file is part of the CMS Kernel package.
5
 *
6
 * Copyright (c) 2016-present LIN3S <[email protected]>
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 LIN3S\CMSKernel\Infrastructure\BenGorFileBundle\DependencyInjection\Compiler\Routing;
13
14
use Symfony\Component\DependencyInjection\ContainerBuilder;
15
16
/**
17
 * @author Beñat Espiña <[email protected]>
18
 */
19
abstract class RoutesLoaderBuilder
20
{
21
    protected $configuration;
22
    protected $container;
23
24
    public function __construct(ContainerBuilder $container, array $configuration = [])
25
    {
26
        $this->configuration = $this->sanitize($configuration);
27
        $this->container = $container;
28
    }
29
30
    public function build()
31
    {
32
        if ($this->container->hasDefinition($this->definitionName())) {
33
            $this->container->getDefinition(
34
                $this->definitionName()
35
            )->replaceArgument(0, array_unique($this->configuration, SORT_REGULAR));
36
        }
37
38
        return $this->container;
39
    }
40
41
    public function configuration()
42
    {
43
        return $this->configuration;
44
    }
45
46
    protected function sanitize(array $configuration)
47
    {
48
        foreach ($configuration as $key => $config) {
49
            if (null === $config['name']) {
50
                $configuration[$key]['name'] = $this->defaultRouteName($key);
51
            }
52
            if (null === $config['path']) {
53
                $configuration[$key]['path'] = $this->defaultRoutePath($key);
54
            }
55
        }
56
57
        return $configuration;
58
    }
59
60
    abstract protected function defaultRouteName($file);
61
62
    abstract protected function defaultRoutePath($file);
63
64
    abstract protected function definitionName();
65
}
66