Config   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
eloc 11
c 2
b 0
f 1
dl 0
loc 35
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 12 3
A val() 0 2 1
1
<?php
2
3
    namespace rAPId\Config;
4
5
    use rAPId\Data\ArrayFileReader;
6
7
    class Config
8
    {
9
        protected static $config = [];
10
        public static    $err    = '';
11
12
        /**
13
         * @param string $filename
14
         * @param string $prefix [optional]
15
         *                       If prefix is used, all config options loaded will be indexed
16
         *                       in dot notation ie prefix.option
17
         */
18
        public static function load($filename, $prefix = '') {
19
            $reader = new ArrayFileReader($filename);
20
            $new_config = $reader->loadArray();
21
22
            if (!empty($prefix)) {
23
                foreach ($new_config as $key => $value) {
24
                    $new_config[ $prefix . '.' . $key ] = $value;
25
                    unset($new_config[ $key ]);
26
                }
27
            }
28
29
            self::$config = merge(self::$config, $new_config);
30
        }
31
32
        /**
33
         * Get the value of a config var
34
         *
35
         * @param string $var_name
36
         * @param mixed  $default
37
         *
38
         * @return mixed|null
39
         */
40
        public static function val($var_name, $default = null) {
41
            return array_get(self::$config, strtolower($var_name), $default);
42
        }
43
    }