|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/* |
|
4
|
|
|
* This file is part of the ConfigCacheBundle package. |
|
5
|
|
|
* |
|
6
|
|
|
* Copyright (c) 2015-2016 Yahoo Japan Corporation |
|
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 YahooJapan\ConfigCacheBundle\ConfigCache\Loader; |
|
13
|
|
|
|
|
14
|
|
|
use Symfony\Component\Config\Loader\LoaderInterface; |
|
15
|
|
|
use Symfony\Component\Config\Loader\LoaderResolverInterface; |
|
16
|
|
|
|
|
17
|
|
|
/** |
|
18
|
|
|
* FileLoader is the abstract class used by loading configuration file. |
|
19
|
|
|
*/ |
|
20
|
|
|
abstract class Loader implements LoaderInterface |
|
21
|
|
|
{ |
|
22
|
|
|
protected $resolver; |
|
23
|
|
|
protected $loaders = array(); |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Loads a resource. |
|
27
|
|
|
* |
|
28
|
|
|
* @SuppressWarnings(PHPMD.UnusedFormalParameter) |
|
29
|
|
|
* @param string $resource File name |
|
30
|
|
|
* @param string $type The resource type |
|
31
|
|
|
* |
|
32
|
|
|
* @return array |
|
33
|
|
|
*/ |
|
34
|
32 |
|
public function load($resource, $type = null) |
|
35
|
|
|
{ |
|
36
|
32 |
|
return $this->loadFile($resource); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Gets the loader resolver. |
|
41
|
|
|
* |
|
42
|
|
|
* @return LoaderResolverInterface A LoaderResolverInterface instance |
|
43
|
|
|
*/ |
|
44
|
1 |
|
public function getResolver() |
|
45
|
|
|
{ |
|
46
|
1 |
|
return $this->resolver; |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Sets the loader resolver. |
|
51
|
|
|
* |
|
52
|
|
|
* @param LoaderResolverInterface $resolver A LoaderResolverInterface instance |
|
53
|
|
|
*/ |
|
54
|
11 |
|
public function setResolver(LoaderResolverInterface $resolver) |
|
55
|
|
|
{ |
|
56
|
11 |
|
$this->resolver = $resolver; |
|
57
|
11 |
|
} |
|
58
|
|
|
|
|
59
|
|
|
/** |
|
60
|
|
|
* Adds an array loader. |
|
61
|
|
|
* |
|
62
|
|
|
* @param ArrayLoaderInterface $loader |
|
63
|
|
|
* |
|
64
|
|
|
* @return Loader |
|
65
|
|
|
*/ |
|
66
|
7 |
|
public function addLoader(ArrayLoaderInterface $loader) |
|
67
|
|
|
{ |
|
68
|
7 |
|
$this->loaders[] = $loader; |
|
69
|
|
|
|
|
70
|
7 |
|
return $this; |
|
71
|
|
|
} |
|
72
|
|
|
|
|
73
|
|
|
/** |
|
74
|
|
|
* Adds array loaders. |
|
75
|
|
|
* |
|
76
|
|
|
* @param array $loaders |
|
77
|
|
|
* |
|
78
|
|
|
* @return Loader |
|
79
|
|
|
*/ |
|
80
|
2 |
|
public function addLoaders(array $loaders) |
|
81
|
|
|
{ |
|
82
|
2 |
|
foreach ($loaders as $loader) { |
|
83
|
2 |
|
$this->addLoader($loader); |
|
84
|
2 |
|
} |
|
85
|
|
|
|
|
86
|
2 |
|
return $this; |
|
87
|
|
|
} |
|
88
|
|
|
|
|
89
|
|
|
/** |
|
90
|
|
|
* Loads internal processing. |
|
91
|
|
|
* |
|
92
|
|
|
* @param string $file |
|
93
|
|
|
* |
|
94
|
|
|
* @return array|\SimpleXMLElement |
|
95
|
|
|
*/ |
|
96
|
|
|
abstract protected function loadFile($file); |
|
97
|
|
|
} |
|
98
|
|
|
|