Completed
Push — master ( ff4b35...4dc3e9 )
by
04:40 queued 12s
created

AbstractResourceExtension::load()   C

Complexity

Conditions 7
Paths 24

Size

Total Lines 34
Code Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 34
rs 6.7273
cc 7
eloc 18
nc 24
nop 2
1
<?php
2
3
namespace DoS\ResourceBundle\DependencyInjection;
4
5
use Sylius\Bundle\ResourceBundle\DependencyInjection\Extension\AbstractResourceExtension as BaseAbstractResourceExtension;
6
use Symfony\Component\Config\Definition\ConfigurationInterface;
7
use Symfony\Component\Config\FileLocator;
8
use Symfony\Component\Config\Loader\DelegatingLoader;
9
use Symfony\Component\Config\Loader\LoaderResolver;
10
use Symfony\Component\DependencyInjection\ContainerBuilder;
11
use Symfony\Component\DependencyInjection\Exception\BadMethodCallException;
12
use Symfony\Component\DependencyInjection\Loader\YamlFileLoader;
13
14
abstract class AbstractResourceExtension extends BaseAbstractResourceExtension
15
{
16
    protected $applicationName = 'dos';
17
18
    protected $configFiles = array(
19
        'parameters.yml',
20
        'services.yml',
21
        'providers.yml',
22
        'controllers.yml',
23
        'templatings.yml',
24
        'listeners.yml',
25
        'settings.yml',
26
        'callbacks.yml',
27
        'forms.yml',
28
        'mails.yml',
29
        'menus.yml',
30
        'twigs.yml',
31
    );
32
33
    /**
34
     * DoS translate to Dos preventing Container::underscore => do_s_.
35
     *
36
     * {@inheritdoc}
37
     */
38
    public function getAlias()
39
    {
40
        $className = get_class($this);
41
42
        if (substr($className, -9) != 'Extension') {
43
            throw new BadMethodCallException('This extension does not follow the naming convention; you must overwrite the getAlias() method.');
44
        }
45
46
        return AbstractResourceBundle::expectedAlias(substr(strrchr($className, '\\'), 1, -9));
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function load(array $config, ContainerBuilder $container)
53
    {
54
        $config = $this->processConfiguration($this->getBundleConfiguration(), $config);
55
        $loader = new YamlFileLoader($container, new FileLocator($this->getConfigDir()));
56
57
        if (empty($config['resources'])) {
58
            $config['resources'] = array();
59
        }
60
61
        $this->registerResources($this->applicationName, $config['driver'], $config['resources'], $container);
0 ignored issues
show
Bug introduced by
The method registerResources() does not seem to exist on object<DoS\ResourceBundl...tractResourceExtension>.

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
62
63
        $interfaces = array();
64
65
        foreach($config['resources'] as $model => $resource) {
66
            foreach($resource['classes'] as $key => $class) {
67
                if ($key === 'interface') {
68
                    $name = sprintf('%s.%s.%s.class', $this->applicationName, $key, $model);
69
                    $container->setParameter($name, $class);
70
71
                    $interfaces[$class] = sprintf('%s.%s.%s.class', $this->applicationName, 'model', $model);
72
                }
73
            }
74
        }
75
76
        $container->setParameter($this->getAlias() . '_interfaces', $interfaces);
77
78
        foreach ($this->configFiles as $configFile) {
79
            if (file_exists(sprintf('%s/%s', $this->getConfigDir(), $configFile))) {
80
                $loader->load($configFile);
81
            }
82
        }
83
84
        return $config;
85
    }
86
87
    /**
88
     * @return string
89
     */
90
    protected function getConfigDir()
91
    {
92
        $reflector = new \ReflectionClass($this);
93
        $fileName = $reflector->getFileName();
94
95
        return sprintf('%s/../Resources/config', dirname($fileName));
96
    }
97
98
    /**
99
     * @return ConfigurationInterface
100
     */
101
    abstract protected function getBundleConfiguration();
102
}
103