/** * @param ConfigIdInterface $configId * @throws RuntimeException * @throws LogicException * @return ConfigInterface */ public function getConfig(ConfigIdInterface $configId) { if ($this->localCache->containsKey($configId->toString())) { return $this->localCache->get($configId->toString()); } if (!$this->modelManager->checkDatabase()) { throw new LogicException('Database is not synced, if you use ConfigManager, when a db schema may be hasn\'t synced.' . ' check it by ConfigManager::modelManager::checkDatabase'); } if (!$this->hasConfig($configId->getClassName())) { throw new RuntimeException(sprintf('Entity "%s" is not configurable', $configId->getClassName())); } $resultConfig = null !== $this->cache ? $this->cache->loadConfigFromCache($configId) : null; if (!$resultConfig) { $model = $this->modelManager->getModelByConfigId($configId); $config = new Config($this->getConfigIdByModel($model, $configId->getScope())); $config->setValues($model->toArray($configId->getScope())); if (null !== $this->cache) { $this->cache->putConfigInCache($config); } $resultConfig = $config; } //local cache $this->localCache->set($resultConfig->getId()->toString(), $resultConfig); //for calculate change set $this->originalConfigs->set($resultConfig->getId()->toString(), clone $resultConfig); return $resultConfig; }
/** * @param ConfigIdInterface $configId * @return bool */ public function removeConfigFromCache(ConfigIdInterface $configId) { return $this->cache->delete($configId->toString()); }