_reader = $reader; $this->_configScope = $configScope; $this->_cache = $cache; $this->_cacheId = $cacheId; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); } /** * Get config value by key * * @param string $path * @param mixed $default * @return array|mixed|null */ public function get($path = null, $default = null) { $this->_loadScopedData(); return parent::get($path, $default); } /** * Load data for current scope * * @return void */ protected function _loadScopedData() { $scope = $this->_configScope->getCurrentScope(); if (false == isset($this->_loadedScopes[$scope])) { if (false == in_array($scope, $this->_scopePriorityScheme)) { $this->_scopePriorityScheme[] = $scope; } foreach ($this->_scopePriorityScheme as $scopeCode) { if (false == isset($this->_loadedScopes[$scopeCode])) { if ($scopeCode !== 'primary' && ($data = $this->_cache->load($scopeCode . '::' . $this->_cacheId)) ) { $data = $this->serializer->unserialize($data); } else { $data = $this->_reader->read($scopeCode); if ($scopeCode !== 'primary') { $this->_cache->save( $this->serializer->serialize($data), $scopeCode . '::' . $this->_cacheId ); } } $this->merge($data); $this->_loadedScopes[$scopeCode] = true; } if ($scopeCode == $scope) { break; } } } } }