diff --git a/common/oatbox/service/ExtendedConfigDriver.php b/common/oatbox/service/ExtendedConfigDriver.php new file mode 100644 index 000000000..51ccb687c --- /dev/null +++ b/common/oatbox/service/ExtendedConfigDriver.php @@ -0,0 +1,103 @@ + + */ + +namespace oat\oatbox\service; + + +class ExtendedConfigDriver extends ServiceConfigDriver +{ + const LOCAL_CONFIG_PREFIX = 'local'; + + /** + * Local configuration with high priority which overrides configuration for the service + * @var array + */ + private $localConfig; + + public function get($id) + { + $entry = parent::get($id); + return $this->mergeLocalConfig($id, $entry); + } + + private function mergeLocalConfig($id, $entry) + { + $opts = self::array_merge_recursive_ex($entry->getOptions(), $this->getLocalConfig($id)); + $entry->setOptions($opts); + return $entry; + } + + private static function array_merge_recursive_ex(array $array1, array $array2) + { + $merged = $array1; + + foreach ($array2 as $key => & $value) { + if (is_array($value) && isset($merged[$key]) && is_array($merged[$key])) { + $merged[$key] = static::array_merge_recursive_ex($merged[$key], $value); + } else if (is_numeric($key)) { + if (!in_array($value, $merged, 1)) { + $merged[] = $value; + } + } else { + $merged[$key] = $value; + } + } + + return $merged; + } + + private function getLocalConfig($id) + { + $localConfig = $this->loadLocalConfig(); + $path = explode('/', $id); + $conf = $localConfig; + foreach ($path as $key) { + if (array_key_exists($key, $conf)) { + $conf = $conf[$key]; + } else { + $conf = []; + break; + } + } + return $conf; + } + + /** + * + */ + /** + * @return array|mixed + */ + private function loadLocalConfig() + { + if (!$this->localConfig) { + $this->localConfig = []; + $config = str_replace('.php', '.json', $this->getPath(self::LOCAL_CONFIG_PREFIX)); + // extended configuration for the local service + if (is_readable($config)) { + $this->localConfig = @json_decode(@file_get_contents($config), 1); + } + } + return $this->localConfig; + } + + +} diff --git a/common/oatbox/service/ServiceConfigDriver.php b/common/oatbox/service/ServiceConfigDriver.php index 48ca85897..a5e91e0e6 100644 --- a/common/oatbox/service/ServiceConfigDriver.php +++ b/common/oatbox/service/ServiceConfigDriver.php @@ -31,6 +31,7 @@ */ class ServiceConfigDriver extends \common_persistence_PhpFileDriver implements ConfigurationDriver { + /** * Get the config content associated to given $key * $key has to be a configurable service diff --git a/manifest.php b/manifest.php index 813974414..0b1e2bfb4 100755 --- a/manifest.php +++ b/manifest.php @@ -31,7 +31,7 @@ 'label' => 'Generis Core', 'description' => 'Core extension, provide the low level framework and an API to manage ontologies', 'license' => 'GPL-2.0', - 'version' => '8.2.1', + 'version' => '8.3.0', 'author' => 'Open Assessment Technologies, CRP Henri Tudor', 'requires' => array(), 'models' => array( diff --git a/scripts/update/Updater.php b/scripts/update/Updater.php index 76f68b8e9..870118819 100644 --- a/scripts/update/Updater.php +++ b/scripts/update/Updater.php @@ -361,6 +361,6 @@ public function update($initialVersion) $this->setVersion('8.0.0'); } - $this->skip('8.0.0', '8.2.1'); + $this->skip('8.0.0', '8.3.0'); } }