| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122 |
- <?php
- namespace ThurData\Servers\KerioEmail\Core\Configuration;
- use ThurData\Servers\KerioEmail\Core\FileReader\Reader;
- use ThurData\Servers\KerioEmail\Core\ModuleConstants;
- /**
- * Description of Data
- *
- * @autor ThurData <info@thurdata.ch>
- */
- class Data
- {
- protected static $data = [];
- public function __construct()
- {
- $this->load();
- }
- public function __get($name)
- {
- $this->load();
- if (array_key_exists(lcfirst($name), self::$data))
- {
- return self::$data[lcfirst($name)];
- }
- return null;
- }
- public function getAll()
- {
- return self::$data;
- }
- private function load()
- {
- if (count(self::$data) == 0)
- {
- $this->loadConfig();
- }
- }
- /**
- * Loads YML configuration files
- */
- private function loadConfig()
- {
- $dataDev = $this->read(ModuleConstants::getDevConfigDir() . DS . 'configuration.yml');
- $dataCore = $this->read(ModuleConstants::getCoreConfigDir() . DS . 'configuration.yml');
- $data = $this->parseConfigData($dataDev, $dataCore);
- $this->loadPackageConfig($data);
- self::$data = $data ? : [];
- }
- /**
- * @param self::$data $data
- *
- * overwrites module version and wiki url basing on moduleVersion.php file,
- * this file is added automatically during package creation
- */
- private function loadPackageConfig(&$data)
- {
- if (file_exists(ModuleConstants::getModuleRootDir() . DS . 'moduleVersion.php'))
- {
- include ModuleConstants::getModuleRootDir() . DS . 'moduleVersion.php';
- if ($moduleVersion)
- {
- $data['version'] = $moduleVersion;
- }
- }
- if ($data['description'] && strpos($data['description'], ':WIKI_URL:'))
- {
- $data['description'] = str_replace(':WIKI_URL:', ($moduleWikiUrl ? : 'https://www.docs.thurdata.com/'), $data['description']);
- }
- $data['debug'] = (file_exists(ModuleConstants::getModuleRootDir() . DIRECTORY_SEPARATOR . '.debug'))
- ? true : false;
- }
- private function parseConfigData($dataDev, $dataCore)
- {
- if (!$dataDev && $dataCore)
- {
- return $dataCore;
- }
- if (!$dataDev && $dataCore)
- {
- return $dataCore;
- }
- foreach ($dataCore as $coreKey => $core)
- {
- $isFind = false;
- foreach ($dataDev as $devKey => $dev)
- {
- if ($devKey === $coreKey)
- {
- $isFind = true;
- break;
- }
- }
- if (!$isFind)
- {
- $dataDev[$coreKey] = $core;
- }
- }
- return $dataDev;
- }
- private function read($name)
- {
- return Reader::read($name)->get();
- }
- }
|