Xhgui_Config   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 81
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 8
lcom 1
cbo 0
dl 0
loc 81
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A load() 0 5 1
A read() 0 7 2
A all() 0 4 1
A write() 0 4 1
A clear() 0 4 1
A shouldRun() 0 8 2
1
<?php
2
/**
3
 * Loads and reads config file.
4
 */
5
class Xhgui_Config
6
{
7
    private static $_config = array();
8
9
    /**
10
     * Load a config file, it will replace
11
     * all the currently loaded configuration.
12
     *
13
     * @param string $file
14
     * @return void
15
     */
16
    public static function load($file)
17
    {
18
        $config = include($file);
19
        self::$_config = array_merge(self::$_config, $config);
20
    }
21
22
    /**
23
     * Read a config value.
24
     *
25
     * @param string $name The name of the config variable
26
     * @return The value or null.
27
     */
28
    public static function read($name)
29
    {
30
        if (isset(self::$_config[$name])) {
31
            return self::$_config[$name];
32
        }
33
        return null;
34
    }
35
36
    /**
37
     * Get all the configuration options.
38
     *
39
     * @return array
40
     */
41
    public static function all()
42
    {
43
        return self::$_config;
44
    }
45
46
    /**
47
     * Write a config value.
48
     *
49
     * @param string $name The name of the config variable
50
     * @param mixed $value The value of the config variable
51
     * @return void
52
     */
53
    public static function write($name, $value)
54
    {
55
        self::$_config[$name] = $value;
56
    }
57
58
    /**
59
     * Clear out the data stored in the config class.
60
     *
61
     * @return void
62
     */
63
    public static function clear()
64
    {
65
        self::$_config = array();
66
    }
67
68
    /**
69
     * Called during profiler initialization
70
     *
71
     * Allows arbitrary conditions to be added configuring how
72
     * Xhgui profiles runs.
73
     *
74
     * @return boolean
75
     */
76
    public static function shouldRun()
77
    {
78
        $callback = self::read('profiler.enable');
79
        if (!is_callable($callback)) {
80
            return false;
81
        }
82
        return (bool)$callback();
83
    }
84
85
}
86