Completed
Push — master ( e9d1ee...cb5c09 )
by Théo
06:38
created

DefaultExtension   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 2
Metric Value
wmc 3
c 3
b 0
f 2
lcom 0
cbo 3
dl 0
loc 34
ccs 0
cts 12
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 11 1
A loadResourceIfExist() 0 10 2
1
<?php
2
3
/*
4
 * This file is part of the LaravelYaml package.
5
 *
6
 * (c) Théo FIDRY <[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 Fidry\LaravelYaml\DependencyInjection\Extension;
13
14
use Fidry\LaravelYaml\DependencyInjection\Builder\ContainerBuilder;
15
use Fidry\LaravelYaml\FileLoader\FileLoaderInterface;
16
use Fidry\LaravelYaml\FileLoader\Yaml\YamlFileLoader;
17
use Illuminate\Support\Facades\App;
18
use Symfony\Component\Config\FileLocator;
19
20
/**
21
 * @author Théo FIDRY <[email protected]>
22
 */
23
final class DefaultExtension implements ExtensionInterface
24
{
25
    /**
26
     * {@inheritdoc}
27
     */
28
    public function load(ContainerBuilder $container)
29
    {
30
        $rootDir = new FileLocator(resource_path('providers'));
31
        $loader = new YamlFileLoader($container, $rootDir);
32
33
        $this
34
            ->loadResourceIfExist($loader, 'parameters.yml')
35
            ->loadResourceIfExist($loader, 'services.yml')
36
            ->loadResourceIfExist($loader, sprintf('parameters_%s.yml', App::environment()))
37
        ;
38
    }
39
40
    /**
41
     * @param FileLoaderInterface $loader
42
     * @param string              $resource
43
     *
44
     * @return $this
45
     */
46
    private function loadResourceIfExist(FileLoaderInterface $loader, $resource)
47
    {
48
        try {
49
            $loader->load($resource);
50
        } catch (\InvalidArgumentException $exception) {
51
            // Ignore error as is an optional file
52
        }
53
54
        return $this;
55
    }
56
}
57