Completed
Push — master ( 80bff0...2aa3b5 )
by Damian
08:40
created

ModuleLoader   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
dl 0
loc 81
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 1

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getModule() 0 4 1
A getManifest() 0 4 1
A hasManifest() 0 4 1
A pushManifest() 0 4 1
A popManifest() 0 4 1
A countManifests() 0 4 1
A inst() 0 4 2
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 inst()
24
    {
25
        return self::$instance ? self::$instance : self::$instance = new self();
26
    }
27
28
    /**
29
     * Get module by name from the current manifest.
30
     * Alias for ::inst()->getManifest()->getModule()
31
     *
32
     * @param string $module
33
     * @return Module
34
     */
35
    public static function getModule($module)
36
    {
37
        return static::inst()->getManifest()->getModule($module);
38
    }
39
40
    /**
41
     * Returns the currently active class manifest instance that is used for
42
     * loading classes.
43
     *
44
     * @return ModuleManifest
45
     */
46
    public function getManifest()
47
    {
48
        return $this->manifests[count($this->manifests) - 1];
49
    }
50
51
    /**
52
     * Returns true if this class loader has a manifest.
53
     *
54
     * @return bool
55
     */
56
    public function hasManifest()
57
    {
58
        return (bool)$this->manifests;
59
    }
60
61
    /**
62
     * Pushes a module manifest instance onto the top of the stack.
63
     *
64
     * @param ModuleManifest $manifest
65
     */
66
    public function pushManifest(ModuleManifest $manifest)
67
    {
68
        $this->manifests[] = $manifest;
69
    }
70
71
    /**
72
     * @return ModuleManifest
73
     */
74
    public function popManifest()
75
    {
76
        return array_pop($this->manifests);
77
    }
78
79
    /**
80
     * Check number of manifests
81
     *
82
     * @return int
83
     */
84
    public function countManifests()
85
    {
86
        return count($this->manifests);
87
    }
88
}
89