Beispiel #1
0
 /**
  * @param ConfigIdInterface $configId
  * @throws RuntimeException
  * @throws LogicException
  * @return ConfigInterface
  */
 public function getConfig(ConfigIdInterface $configId)
 {
     if ($configId instanceof EntityConfigId && !$configId->getClassName()) {
         $config = new Config($configId);
         $config->setValues($this->getEntityDefaultValues($this->getProvider($configId->getScope())));
         return $config;
     }
     $configKey = $this->buildConfigKey($configId);
     if (isset($this->localCache[$configKey])) {
         return $this->localCache[$configKey];
     }
     if (!$this->modelManager->checkDatabase()) {
         throw $this->createDatabaseNotSyncedException();
     }
     if (!$this->hasConfig($configId->getClassName())) {
         throw new RuntimeException(sprintf('Entity "%s" is not configurable', $configId->getClassName()));
     }
     $config = null !== $this->cache ? $this->cache->loadConfigFromCache($configId) : null;
     if (!$config) {
         $model = $configId instanceof FieldConfigId ? $this->modelManager->getFieldModel($configId->getClassName(), $configId->getFieldName()) : $this->modelManager->getEntityModel($configId->getClassName());
         $config = new Config($configId);
         $config->setValues($model->toArray($configId->getScope()));
         if (null !== $this->cache) {
             $this->cache->putConfigInCache($config);
         }
     }
     // local cache
     $this->localCache[$configKey] = $config;
     // for calculate change set
     $this->originalConfigs[$configKey] = clone $config;
     return $config;
 }
 /**
  * @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;
 }
 public function testCache()
 {
     $cacheProvider = $this->getMockBuilder('Doctrine\\Common\\Cache\\CacheProvider')->disableOriginalConstructor()->setMethods(array('fetch', 'save', 'delete', 'deleteAll'))->getMockForAbstractClass();
     $modelCacheProvider = $this->getMockBuilder('Doctrine\\Common\\Cache\\CacheProvider')->disableOriginalConstructor()->setMethods(array('fetch', 'save', 'delete', 'deleteAll'))->getMockForAbstractClass();
     $className = 'testClass';
     $scope = 'testScope';
     $configId = new EntityConfigId($className, $scope);
     $config = new Config($configId);
     $configCache = new ConfigCache($cacheProvider, $modelCacheProvider);
     $cacheProvider->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->assertTrue($configCache->putConfigInCache($config));
     $cacheProvider->expects($this->once())->method('delete')->will($this->returnValue(true));
     $this->assertTrue($configCache->removeConfigFromCache($configId));
     $cacheProvider->expects($this->once())->method('deleteAll')->will($this->returnValue(true));
     $this->assertTrue($configCache->removeAll());
     $cacheProvider->expects($this->once())->method('fetch')->will($this->returnValue(serialize($config)));
     $this->assertEquals($config, $configCache->loadConfigFromCache($configId));
     $value = 'testValue';
     $modelCacheProvider->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->assertTrue($configCache->setConfigurable($value, $className));
     $modelCacheProvider->expects($this->once())->method('fetch')->will($this->returnValue($value));
     $this->assertEquals($value, $configCache->getConfigurable($className));
     $modelCacheProvider->expects($this->once())->method('deleteAll')->will($this->returnValue(true));
     $this->assertTrue($configCache->removeAllConfigurable());
 }
Beispiel #4
0
 public function testPutConfigInCache()
 {
     $className = 'testClass';
     $scope = 'testScope';
     $configId = new EntityConfigId($scope, $className);
     $config = new Config($configId);
     $configCache = new ConfigCache($this->cacheProvider, $this->modelCacheProvider);
     $this->cacheProvider->expects($this->once())->method('save')->will($this->returnValue(true));
     $this->assertTrue($configCache->putConfigInCache($config));
 }