Completed
Push — development ( cfd391...deed4d )
by Andrij
12:03
created

AdminLoader   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 0

Importance

Changes 0
Metric Value
dl 0
loc 56
rs 10
c 0
b 0
f 0
wmc 9
lcom 2
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getInstance() 0 3 2
A __construct() 0 3 1
B adminAutoload() 0 28 6
1
<?php namespace CMSFactory;
2
3
class AdminLoader
4
{
5
6
    /**
7
     * @var AdminLoader
8
     */
9
    private static $instance;
10
11
    /**
12
     * @var bool
13
     */
14
    private static $adminAutoLoaded = false;
15
16
    /**
17
     * @var \CI_DB_active_record
18
     */
19
    private $db;
20
21
    public static function getInstance() {
22
        return self::$instance ?: self::$instance = new self(\CI::$APP->db);
23
    }
24
25
    public function __construct(\CI_DB_active_record $db) {
26
        $this->db = $db;
27
    }
28
29
    public function adminAutoload() {
30
        if (!self::$adminAutoLoaded) {
31
            /** Search module with autoload */
32
            $query = $this->db->select('name')->where('autoload', 1)->get('components');
33
34
            if ($query) {
35
                /** Run all Admin autoload method */
36
                $modules = $query->result_array();
37
                $modules = array_column($modules, 'name');
38
                array_unshift($modules, 'core');
39
40
                $modules = array_unique($modules);
41
42
                foreach ($modules as $moduleName) {
43
                    \Modules::load_file($moduleName, APPPATH . 'modules' . DIRECTORY_SEPARATOR . $moduleName . DIRECTORY_SEPARATOR);
44
                    $moduleName = ucfirst($moduleName);
45
                    if (class_exists($moduleName)) {
46
                        if (method_exists($moduleName, 'adminAutoload')) {
47
                            $moduleName::adminAutoload();
48
                        }
49
                    }
50
                }
51
            }
52
53
            self::$adminAutoLoaded = true;
54
        }
55
56
    }
57
58
}