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: 136: 137: 138: 139: 140: 141: 142: 143: 144: 145: 146: 147: 148: 149: 150: 151: 152: 153: 154: 155: 156: 157: 158: 159: 160: 161: 162: 163: 164: 165: 166: 167: 168: 169: 170: 171: 172: 173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183: 184: 185: 186: 187: 188: 189: 190: 191: 192: 193: 194: 195: 196: 197: 198: 199: 200: 201: 202: 203:
<?php
/**
* MvcCore
*
* This source file is subject to the BSD 3 License
* For the full copyright and license information, please view
* the LICENSE.md file that are distributed with this source code.
*
* @copyright Copyright (c) 2016 Tom Flidr (https://github.com/mvccore)
* @license https://mvccore.github.io/docs/mvccore/5.0.0/LICENCE.md
*/
namespace MvcCore;
/**
* Responsibility - reading/writing config file(s).
* - Config file(s) reading:
* - Reading any `config.ini` file by relative path.
* - Parsing and typing INI data into `stdClass|array` by key types or typing
* INI values into `int|float|bool|string` for all other detected primitives.
* - Config file(s) writing:
* - Dumping `stdClass`es and `array`s into INI syntax string with
* all other environment records.
* - Storing serialized config data in single process.
*/
interface IConfig {
/**
* Get system config relative path from app root.
* @return string
*/
public static function GetSystemConfigPath ();
/**
* Set system config relative path from app root.
* @param string $systemConfigPath
* @return string
*/
public static function SetSystemConfigPath ($systemConfigPath);
/**
* Set system config relative path from app root.
* @param string $appRootRelativePath
* @param \MvcCore\Config $config
* @return \MvcCore\Config
*/
public static function SetConfigCache ($appRootRelativePath, \MvcCore\IConfig $config);
/**
* Clear configs memory cache by relative path from app root
* or clear whole configs memory cache if `NULL` specified.
* @param string|NULL $appRootRelativePath
* @return bool
*/
public static function ClearConfigCache ($appRootRelativePath = NULL);
/**
* Return environment configuration data from system config. Environment
* configuration data are always stored under root level section `[environments]`.
* @param \MvcCore\Config $config
* @return array|\stdClass
*/
public static function & GetEnvironmentDetectionData (\MvcCore\IConfig $config);
/**
* Set up config with current environment data immediately after
* environment name is detected. This method is used INTERNALLY!
* @param \MvcCore\Config $config
* @param string $environmentName
* @return void
*/
public static function SetUpEnvironmentData (\MvcCore\IConfig $config, $environmentName);
/**
* This is INTERNAL method.
* Return always new instance of statically called class, no singleton.
* Always called from `\MvcCore\Config::GetSystem()` before system config is read.
* This is place where to customize any config creation process,
* before it's created by MvcCore framework.
* @param array $mergedData Configuration data for all environments.
* @param string $appRootRelativePath Relative config path from app root.
* @return \MvcCore\Config
*/
public static function CreateInstance (array $mergedData = [], $appRootRelativePath = NULL);
/**
* Get (optionally cached) system config INI file as `stdClass` or `array`,
* placed by default in: `"/App/config.ini"`.
* @throws \RuntimeException
* @return \MvcCore\Config|NULL
*/
public static function GetSystem ();
/**
* Get (optionally cached) config INI file as `stdClass` or `array`,
* placed relatively from application document root.
* @param string $appRootRelativePath Any config relative path like `'/%appPath%/website.ini'`.
* @throws \RuntimeException
* @return \MvcCore\Config|NULL
*/
public static function GetConfig ($appRootRelativePath);
/**
* Try to load and parse config file by absolute path.
* @param string $configFullPath
* @param string $systemConfigClass
* @param bool $isSystemConfig
* @return \MvcCore\Config|bool
*/
public static function LoadConfig ($configFullPath, $systemConfigClass, $isSystemConfig = FALSE);
/**
* Encode all data into string and store it in `\MvcCore\Config::$fullPath`.
* @throws \Exception Configuration data was not possible to dump or write.
* @return bool
*/
public function Save ();
/**
* Get internal array store as reference.
* @param string|NULL $environmentName Return configuration data only for specific
* environment name. If `NULL`, there are
* returned data for current environment.
* @return array
*/
public function & GetData ($environmentName = NULL);
/**
* Set whole internal array store.
* @param array $data Data to set into configuration store(s). If second
* param is `NULL`, there are set data for current envirnment.
* @param string|NULL $environmentName Set configuration data for specific
* environment name. If `NULL`, there are
* set data for current environment.
* @return \MvcCore\Config
*/
public function SetData (array $data = [], $environmentName = NULL);
/**
* Full path, where are configuration data stored.
* @return string
*/
public function GetFullPath ();
/**
* Config file last changed UNIX timestamp.
* @return int
*/
public function GetLastChanged ();
/**
* If `TRUE`, config contains system data.
* @return bool
*/
public function IsSystem ();
/**
* Load config file and return `TRUE` for success or `FALSE` in failure.
* - Load all sections for all environment names into `$this->envData` collection.
* - Retype all raw string values into `float`, `int` or `boolean` types.
* - Retype collections into `\stdClass`, if there are no numeric keys.
* @return bool
*/
public function Read ();
/**
* Dump configuration data (for all environments) into INI configuration
* syntax with environment specific sections and data.
* @return string
*/
public function Dump ();
/**
* Get not defined property from `$this->currentData` array store,
* if there is nothing, return `NULL`.
* @param string $key
* @return mixed
*/
public function __get ($key);
/**
* Store not defined property inside `$this->currentData` array store.
* @param string $key
* @return mixed
*/
public function __set ($key, $value);
/**
* Magic function triggered by: `isset($cfg->key);`.
* @param string $key
* @return bool
*/
public function __isset ($key);
/**
* Magic function triggered by: `unset($cfg->key);`.
* @param string $key
* @return void
*/
public function __unset ($key);
}