reader = $reader; $this->cache = $cache; $this->cacheId = $cacheId; $this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class); $this->initData(); } /** * Initialise data for configuration * * @return void */ protected function initData() { $data = $this->cache->load($this->cacheId); if (false === $data) { $data = $this->reader->read(); $this->cache->save($this->serializer->serialize($data), $this->cacheId, $this->cacheTags); } else { $data = $this->serializer->unserialize($data); } $this->merge($data); } /** * Merge config data to the object * * @param array $config * @return void */ public function merge(array $config) { $this->_data = array_replace_recursive($this->_data, $config); } /** * Get config value by key * * @param string $path * @param mixed $default * @return array|mixed|null */ public function get($path = null, $default = null) { if ($path === null) { return $this->_data; } $keys = explode('/', $path); $data = $this->_data; foreach ($keys as $key) { if (is_array($data) && array_key_exists($key, $data)) { $data = $data[$key]; } else { return $default; } } return $data; } /** * Clear cache data * * @return void */ public function reset() { $this->cache->remove($this->cacheId); } }