fantasia /core/classes/framework/config/config.php

Language PHP Lines 135
MD5 Hash a8574f79e3e940b64a1e5ce016f4e761 Estimated Cost $3,300 (why?)
Repository https://github.com/GinoPane/fantasia.git View Raw File
  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<?php
class Config
{
    /*
     * Array to store settings for configuration
     */
    protected static $_settings     = array();
    
    /*
     * 
     */
    protected static $_packSettings   = array();       
    
    /**
     * 
     * Loads configuration data from the file and sets options
     * 
     * @param string $filePath
     */
    public static function loadFromFile($filePath)
    {
        static::setOptions(Loader::loadConfigurationFromFile($filePath));
    }
    
    /**
     * 
     * @param array $data
     */
    public static function setOptions($data)
    {
        if (is_array($data)) {
            static::$_settings = array_merge(static::$_settings, $data);
        } else {
            trigger_error("Wrong settings passed!", E_USER_WARNING);
        }
    }
    
    /**
     * 
     * @param mixed $key
     * @param mixed $value
     */
    public static function setOption($key, $value)
    {
        static::setOptions(array($key => $value));
    }
    
    /**
     * 
     * Returns option for the key
     * 
     * @param mixed $key
     * @return mixed
     */
    public static function getOption($key)
    {
        return isset(static::$_settings[$key]) ? static::$_settings[$key] : null;
    }
    
    /**
     * 
     * Returns all options from the config
     * 
     * @return array Array with option_key => option_value pairs
     */
    public static function getOptions()
    {
        return static::$_settings;
    }
    
    /**
     * 
     * Gets array of options from the pack config
     * 
     * @param string $packName
     * @param bool $onlyChanges if true, only options set from the config will be returned; 
     *                          or they will be merged with application config otherwise  
     */
    public static function getPackOptions($packName, $onlyChanges = false)
    {
        if (isset(static::$_packSettings[$packName])){
            if (!$onlyChanges){
                return array_merge(static::getOptions(), static::$_packSettings[$packName]);
            } else {
                return static::$_packSettings[$packName];
            }
        } else {
            return static::getOptions();
        }
    }
    
    /**
     * 
     * Gets the option value from the pack config
     * 
     * @param string $key
     * @param string $packName
     */
    public static function getPackOption($key, $packName = "")
    {
        $options = static::getPackOptions($packName);

        return isset($options[$key]) ? $options[$key] : null;
    }
    
    /**
     * 
     * Sets pack option value
     * 
     * @param string $key
     * @param mixed $value
     * @param string $packName
     * @return void
     */
    public static function setPackOption($key, $value, $packName = "")
    {
        if (!isset(static::$_packSettings[$packName])){
            static::$_packSettings[$packName] = array();
        }
        
        static::$_packSettings[$packName][$key] = $value;
    }
    
    /**
     * 
     * Alias for getOption method
     * 
     * @param mixed $key
     * @return mixed
     */
    public static function _($key)
    {
        return static::getOption($key);
    }
}
Back to Top