Passed
Push — master ( 7796f0...ca9076 )
by 世昌
01:52
created

Manager::getActive()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
namespace nebula\application\module;
3
4
use nebula\Context;
5
use nebula\application\Application;
6
use nebula\application\module\Module;
7
use nebula\application\module\Builder;
8
use nebula\application\module\NameFinder;
9
use nebula\application\filesystem\FileSystem;
10
11
12
13
/**
14
 * 模板管理器
15
 */
16
class Manager
17
{
18
    /**
19
     * Nebula
20
     *
21
     * @var Application
22
     */
23
    protected $app;
24
25
    /**
26
     * 模块名称管理器
27
     *
28
     * @var NameFinder
29
     */
30
    protected $finder;
31
32
    /**
33
     * 激活的模块
34
     *
35
     * @var string
36
     */
37
    protected $active;
38
39
    /**
40
     * 可访问的模块
41
     *
42
     * @var array
43
     */
44
    protected $reachable;
45
46
    /**
47
     * 注册的模块
48
     *
49
     * @var Module[]
50
     */
51
    protected $module;
52
53
    /**
54
     * 构建管理器
55
     *
56
     * @param Application $app
57
     */
58
    public function __construct(Application $app) {
59
        $this->app = $app;
60
        $this->finder = new NameFinder;
61
    }
62
63
    /**
64
     * Get 激活的模块
65
     *
66
     * @return  string
67
     */ 
68
    public function getActive()
69
    {
70
        return $this->active;
71
    }
72
73
    /**
74
     * Set 激活的模块
75
     *
76
     * @param  string  $active  激活的模块
77
     *
78
     * @return  self
79
     */ 
80
    public function setActive(string $active)
81
    {
82
        $this->active = $active;
83
84
        return $this;
85
    }
86
87
    /**
88
     * Get 可访问的模块
89
     *
90
     * @return  array
91
     */ 
92
    public function getReachable()
93
    {
94
        return $this->reachable;
95
    }
96
97
    /**
98
     * Set 可访问的模块
99
     *
100
     * @param  array  $reachable  可访问的模块
101
     *
102
     * @return  self
103
     */ 
104
    public function setReachable(array $reachable)
105
    {
106
        $this->reachable = $reachable;
107
108
        return $this;
109
    }
110
111
112
    /**
113
     * 注册模块
114
     *
115
     * @return void
116
     */
117
    public function registerModule()
118
    {
119
        $scan = $this->getApp()->getConfig('app.module.scan-path', []);
120
        $cache = $this->getDataPath() .'/module-cache';
0 ignored issues
show
Bug introduced by
The method getDataPath() does not exist on nebula\application\module\Manager. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

120
        $cache = $this->/** @scrutinizer ignore-call */ getDataPath() .'/module-cache';

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
121
        FileSystem::makes($cache);
122
        foreach (Builder::scan($scan, $cache) as $module) {
123
            $this->finder->add($module->getName(), $module->getVersion());
124
            $this->module[$module->getFullName()] = $module;
125
            $this->getApp()->getContext()->getDebugger()->info('register module {name} at {path}', ['name'=>$module->getFullName(), 'path'=>$module->getPath()]);
126
        }
127
    }
128
129
130
    /**
131
     * 查找模块
132
     *
133
     * @param string $name
134
     * @return Module|null
135
     */     
136
    public function find(string $name):?Module {
137
        $fullName = $this->finder->getFullName($name);
138
        return $this->module[$fullName] ?? null;
139
    }
140
141
    /**
142
     * Get nebula
143
     *
144
     * @return  Application
145
     */ 
146
    public function getApp()
147
    {
148
        return $this->app;
149
    }
150
}
151