Completed
Push — master ( deca00...5388ff )
by Sam
24s
created

ModuleLoader::pushManifest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SilverStripe\Core\Manifest;
4
5
/**
6
 * Module manifest holder
7
 */
8
class ModuleLoader
9
{
10
    /**
11
     * @var self
12
     */
13
    private static $instance;
14
15
    /**
16
     * @var ModuleManifest[] Module manifests
17
     */
18
    protected $manifests = array();
19
20
    /**
21
     * @return self
22
     */
23
    public static function instance()
24
    {
25
        return self::$instance ? self::$instance : self::$instance = new self();
26
    }
27
28
    /**
29
     * Returns the currently active class manifest instance that is used for
30
     * loading classes.
31
     *
32
     * @return ModuleManifest
33
     */
34
    public function getManifest()
35
    {
36
        return $this->manifests[count($this->manifests) - 1];
37
    }
38
39
    /**
40
     * Returns true if this class loader has a manifest.
41
     *
42
     * @return bool
43
     */
44
    public function hasManifest()
45
    {
46
        return (bool)$this->manifests;
47
    }
48
49
    /**
50
     * Pushes a module manifest instance onto the top of the stack.
51
     *
52
     * @param ModuleManifest $manifest
53
     */
54
    public function pushManifest(ModuleManifest $manifest)
55
    {
56
        $this->manifests[] = $manifest;
57
    }
58
59
    /**
60
     * @return ModuleManifest
61
     */
62
    public function popManifest()
63
    {
64
        return array_pop($this->manifests);
65
    }
66
67
    /**
68
     * Check number of manifests
69
     *
70
     * @return int
71
     */
72
    public function countManifests()
73
    {
74
        return count($this->manifests);
75
    }
76
}
77