/core/classes/framework/config/config.php
PHP | 135 lines | 58 code | 12 blank | 65 comment | 7 complexity | a8574f79e3e940b64a1e5ce016f4e761 MD5 | raw file
- <?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);
- }
- }