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
|
|
|
|