Config::set()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace Core;
4
5
class Config
6
{
7
    private static $instance;
8
    private $config_array;
9
    private $config_path;
10
11
    public function __construct()
12
    {
13
        $this->config_array = [];
14
        $this->config_path = ROOT_APP.'Config'.DS;
15
        $this->make();
16
    }
17
18
    /**
19
     * @return Config
20
     */
21
    public static function getInstance()
22
    {
23
        if (!self::$instance) {
24
            self::$instance = (new self());
25
        }
26
27
        return self::$instance;
28
    }
29
30
    /**
31
     * @param $key
32
     * @param $value
33
     */
34
    public function set($key, $value)
35
    {
36
        $this->config_array[$key] = $value;
37
    }
38
39
    /**
40
     * @param $keys
41
     *
42
     * @return array|mixed|null
43
     */
44
    public static function get($keys)
45
    {
46
        $keys = explode('.', $keys);
47
        $tmp = self::getInstance()->config_array;
48
        foreach ($keys as $key) {
49
            $tmp = isset($tmp[$key]) ? $tmp[$key] : null;
50
        }
51
52
        return $tmp;
53
    }
54
55
    /**
56
     * @param $array
57
     */
58
    public function addConfigs($array)
59
    {
60
        foreach ($array as $key => $value) {
61
            $this->config_array[$key] = $value;
62
        }
63
    }
64
65
    /**
66
     * @return array
67
     */
68
    public function make()
69
    {
70
        $view = include $this->config_path.'views.php';
71
        $app = include $this->config_path.'app.php';
72
        $database = include $this->config_path.'database.php';
73
        $mail = include $this->config_path.'mail.php';
74
        $this->config_array['views'] = $view;
75
        $this->config_array['app'] = $app;
76
        $this->config_array['database'] = $database;
77
        $this->config_array['mail'] = $mail;
78
79
        return $this->config_array;
80
    }
81
}
82