Passed
Push — dev ( 1930e5...4afce3 )
by 世昌
02:32
created

ApplicationBaseLoader::load()   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
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
rs 10
1
<?php
2
3
4
namespace suda\application\loader;
5
6
7
use suda\framework\loader\Loader;
8
use suda\application\database\Database;
9
use suda\framework\filesystem\FileSystem;
10
use suda\database\exception\SQLException;
11
12
class ApplicationBaseLoader extends ApplicationModuleLoader
13
{
14
15
    /**
16
     * 加载额外vendor
17
     */
18
    public function loadVendorIfExist()
19
    {
20
        $vendorAutoload = $this->application->getPath() . '/vendor/autoload.php';
21
        if (FileSystem::exist($vendorAutoload)) {
22
            Loader::requireOnce($vendorAutoload);
23
        }
24
    }
25
26
    /**
27
     * 加载数据源
28
     *
29
     * @throws SQLException
30
     */
31
    public function loadDataSource()
32
    {
33
        Database::loadApplication($this->application);
34
        $dataSource = Database::getDefaultDataSource();
35
        $this->application->setDataSource($dataSource);
36
    }
37
38
    /**
39
     * 加载全局配置
40
     */
41
    public function loadGlobalConfig()
42
    {
43
        $resource = $this->application->getResource();
44
        if ($configPath = $resource->getConfigResourcePath('config/config')) {
45
            $this->application->getConfig()->load($configPath);
46
        }
47
        if ($listenerPath = $resource->getConfigResourcePath('config/listener')) {
48
            $this->application->loadEvent($listenerPath);
49
        }
50
    }
51
52
    /**
53
     * 加载APP
54
     */
55
    public function load()
56
    {
57
        $this->loadVendorIfExist();
58
        $this->loadGlobalConfig();
59
        $this->loadModule();
60
        LanguageLoader::load($this->application);
61
    }
62
}