Completed
Pull Request — master (#6641)
by Damian
09:35 queued 27s
created

ConfigLoader::nest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 0
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
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
     * @var self
14
     */
15
    private static $instance;
16
17
    /**
18
     * @var ConfigCollectionInterface[] map of config collections
19
     */
20
    protected $manifests = array();
21
22
    /**
23
     * @return self
24
     */
25
    public static function instance()
26
    {
27
        return self::$instance ? self::$instance : self::$instance = new self();
28
    }
29
30
    /**
31
     * Returns the currently active class manifest instance that is used for
32
     * loading classes.
33
     *
34
     * @return ConfigCollectionInterface
35
     */
36
    public function getManifest()
37
    {
38
        return $this->manifests[count($this->manifests) - 1];
39
    }
40
41
    /**
42
     * Returns true if this class loader has a manifest.
43
     *
44
     * @return bool
45
     */
46
    public function hasManifest()
47
    {
48
        return (bool)$this->manifests;
49
    }
50
51
    /**
52
     * Pushes a class manifest instance onto the top of the stack.
53
     *
54
     * @param ConfigCollectionInterface $manifest
55
     */
56
    public function pushManifest(ConfigCollectionInterface $manifest)
57
    {
58
        $this->manifests[] = $manifest;
59
    }
60
61
    /**
62
     * @return ConfigCollectionInterface
63
     */
64
    public function popManifest()
65
    {
66
        return array_pop($this->manifests);
67
    }
68
69
    /**
70
     * Check number of manifests
71
     *
72
     * @return int
73
     */
74
    public function countManifests()
75
    {
76
        return count($this->manifests);
77
    }
78
79
    /**
80
     * Nest the current manifest
81
     *
82
     * @return ConfigCollectionInterface
83
     */
84
    public function nest()
85
    {
86
        $manifest = $this->getManifest()->nest();
87
        $this->pushManifest($manifest);
88
        return $manifest;
89
    }
90
}
91