1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\Core\Config; |
4
|
|
|
|
5
|
|
|
use SilverStripe\Config\Collections\ConfigCollectionInterface; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Registers config sources via ConfigCollectionInterface |
9
|
|
|
*/ |
10
|
|
|
class ConfigLoader |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @internal |
14
|
|
|
* @var self |
15
|
|
|
*/ |
16
|
|
|
private static $instance; |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var ConfigCollectionInterface[] map of config collections |
20
|
|
|
*/ |
21
|
|
|
protected $manifests = array(); |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* @return self |
25
|
|
|
*/ |
26
|
|
|
public static function inst() |
27
|
|
|
{ |
28
|
|
|
return self::$instance ? self::$instance : self::$instance = new self(); |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* Returns the currently active class manifest instance that is used for |
33
|
|
|
* loading classes. |
34
|
|
|
* |
35
|
|
|
* @return ConfigCollectionInterface |
36
|
|
|
*/ |
37
|
|
|
public function getManifest() |
38
|
|
|
{ |
39
|
|
|
return $this->manifests[count($this->manifests) - 1]; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Returns true if this class loader has a manifest. |
44
|
|
|
* |
45
|
|
|
* @return bool |
46
|
|
|
*/ |
47
|
|
|
public function hasManifest() |
48
|
|
|
{ |
49
|
|
|
return (bool)$this->manifests; |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
/** |
53
|
|
|
* Pushes a class manifest instance onto the top of the stack. |
54
|
|
|
* |
55
|
|
|
* @param ConfigCollectionInterface $manifest |
56
|
|
|
*/ |
57
|
|
|
public function pushManifest(ConfigCollectionInterface $manifest) |
58
|
|
|
{ |
59
|
|
|
$this->manifests[] = $manifest; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @return ConfigCollectionInterface |
64
|
|
|
*/ |
65
|
|
|
public function popManifest() |
66
|
|
|
{ |
67
|
|
|
return array_pop($this->manifests); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
/** |
71
|
|
|
* Check number of manifests |
72
|
|
|
* |
73
|
|
|
* @return int |
74
|
|
|
*/ |
75
|
|
|
public function countManifests() |
76
|
|
|
{ |
77
|
|
|
return count($this->manifests); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
/** |
81
|
|
|
* Nest the current manifest |
82
|
|
|
* |
83
|
|
|
* @return ConfigCollectionInterface |
84
|
|
|
*/ |
85
|
|
|
public function nest() |
86
|
|
|
{ |
87
|
|
|
$manifest = $this->getManifest()->nest(); |
88
|
|
|
$this->pushManifest($manifest); |
89
|
|
|
return $manifest; |
90
|
|
|
} |
91
|
|
|
} |
92
|
|
|
|