Completed
Push — master ( 6da022...101884 )
by Restu
13:37
created

Config   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 0
loc 49
rs 10
wmc 7
lcom 1
cbo 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A get() 0 11 2
A load() 0 9 3
A initConfigDir() 0 4 2
1
<?php
2
namespace JayaCode\Framework\Core\Helper\Config;
3
4
/**
5
 * Class Config
6
 * @package JayaCode\Framework\Core\Config
7
 */
8
class Config
9
{
10
    /**
11
     * @var null
12
     */
13
    protected static $configDir = null;
14
    /**
15
     * @var array
16
     */
17
    protected static $dataConfig = array();
18
19
    /**
20
     * @param $name
21
     * @return mixed
22
     */
23
    public static function get($name)
24
    {
25
        $configName = explode(".", $name);
26
        $configName = $configName[0];
27
28
        if (!isset(static::$dataConfig[$configName])) {
29
            static::$dataConfig[$configName] = static::load($configName.".php");
30
        }
31
32
        return arr_get(static::$dataConfig, $name);
33
    }
34
35
    /**
36
     * @param $filename
37
     * @return array|mixed
38
     */
39
    public static function load($filename)
40
    {
41
        if (is_null(static::$configDir)) {
42
            static::initConfigDir();
43
        }
44
45
        $locFile = static::$configDir."/".$filename;
46
        return file_exists($locFile)?include($locFile):array();
47
    }
48
49
    /**
50
     * Init $configDir
51
     */
52
    protected static function initConfigDir()
53
    {
54
        static::$configDir = defined("__CONFIG_DIR__")?__CONFIG_DIR__:__DIR__."/config";
55
    }
56
}
57