コード例 #1
0
 /**
  * @param ConfigIdInterface $configId
  * @throws RuntimeException
  * @throws LogicException
  * @return ConfigInterface
  */
 public function getConfig(ConfigIdInterface $configId)
 {
     $className = $configId->getClassName();
     if ($configId instanceof EntityConfigId && !$className) {
         return new Config($configId, $this->getEntityDefaultValues($this->getProvider($configId->getScope())));
     }
     $config = $this->cache->getConfig($configId);
     if (!$config) {
         if (!$this->modelManager->checkDatabase()) {
             throw $this->createDatabaseNotSyncedException();
         }
         $isConfigurableEntity = $this->cache->getConfigurable($className);
         if (null === $isConfigurableEntity) {
             $isConfigurableEntity = null !== $this->modelManager->findEntityModel($className);
             $this->cache->saveConfigurable($isConfigurableEntity, $className);
         }
         if (!$isConfigurableEntity) {
             throw new RuntimeException(sprintf('Entity "%s" is not configurable', $className));
         }
         $config = new Config($configId, $this->getModelByConfigId($configId)->toArray($configId->getScope()));
         // put to a cache
         $this->cache->saveConfig($config);
     }
     // for calculate change set
     $cacheKey = $this->buildConfigKey($configId);
     if (!isset($this->originalConfigs[$cacheKey])) {
         $this->originalConfigs[$cacheKey] = clone $config;
     }
     return $config;
 }
コード例 #2
0
 /**
  * @dataProvider getConfigurableProvider
  */
 public function testGetConfigurable($fetchVal, $fieldName, $expectedFlag)
 {
     $this->modelCache->expects($this->once())->method('fetch')->with(self::ENTITY_CLASS)->willReturn($fetchVal);
     $this->assertSame($expectedFlag, $this->configCache->getConfigurable(self::ENTITY_CLASS, $fieldName));
     // test local cache
     $this->assertSame($expectedFlag, $this->configCache->getConfigurable(self::ENTITY_CLASS, $fieldName));
 }
コード例 #3
0
ファイル: ConfigManager.php プロジェクト: hugeval/platform
 /**
  * @param string $scope
  * @param string $className
  * @param string $fieldName
  *
  * @return ConfigInterface
  *
  * @throws RuntimeException
  */
 public function getFieldConfig($scope, $className, $fieldName)
 {
     $config = $this->cache->getFieldConfig($scope, $className, $fieldName);
     if (!$config) {
         if (!$this->modelManager->checkDatabase()) {
             throw $this->createDatabaseNotSyncedException();
         }
         $isConfigurableEntity = $this->cache->getConfigurable($className);
         if (null === $isConfigurableEntity) {
             $isConfigurableEntity = null !== $this->modelManager->findEntityModel($className);
             $this->cache->saveConfigurable($isConfigurableEntity, $className);
         }
         if (!$isConfigurableEntity) {
             throw new RuntimeException(sprintf('Entity "%s" is not configurable', $className));
         }
         $model = $this->modelManager->getFieldModel($className, $fieldName);
         $config = new Config(new FieldConfigId($scope, $className, $fieldName, $model->getType()), $model->toArray($scope));
         // put to a cache
         $this->cache->saveConfig($config);
     }
     // for calculate change set
     $cacheKey = $scope . '.' . $className . '.' . $fieldName;
     if (!isset($this->originalConfigs[$cacheKey])) {
         $this->originalConfigs[$cacheKey] = clone $config;
     }
     return $config;
 }
コード例 #4
0
ファイル: ConfigCacheTest.php プロジェクト: xamin123/platform
 /**
  * @dataProvider getConfigurableProvider
  */
 public function testGetConfigurable($expectedFlag, $cachedValue)
 {
     $className = 'testClass';
     $configCache = new ConfigCache($this->cacheProvider, $this->modelCacheProvider);
     $this->modelCacheProvider->expects($this->once())->method('fetch')->with($className)->will($this->returnValue($cachedValue));
     $this->assertTrue($expectedFlag === $configCache->getConfigurable($className));
 }
コード例 #5
0
 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());
 }
コード例 #6
0
ファイル: ConfigCacheTest.php プロジェクト: Maksold/platform
 public function testDeleteAllConfigurableLocalCacheOnly()
 {
     $this->configCache->saveConfigurable(true, self::ENTITY_CLASS, null, true);
     $this->modelCache->expects($this->never())->method('deleteAll');
     $this->assertTrue($this->configCache->deleteAllConfigurable(true));
     // test that a local cache is cleaned up
     $this->assertNull($this->configCache->getConfigurable(self::ENTITY_CLASS));
 }
コード例 #7
0
ファイル: ConfigManager.php プロジェクト: Maksold/platform
 /**
  * Checks whether a field is configurable.
  *
  * @param string $className
  * @param string $fieldName
  *
  * @return bool
  */
 protected function isConfigurableField($className, $fieldName)
 {
     $isConfigurable = $this->cache->getConfigurable($className, $fieldName);
     if (null === $isConfigurable) {
         $isConfigurable = null !== $this->modelManager->findFieldModel($className, $fieldName);
         $this->cache->saveConfigurable($isConfigurable, $className, $fieldName);
     }
     return $isConfigurable;
 }
コード例 #8
0
 /**
  * @param string $className
  * @param string $fieldName
  * @return bool
  */
 public function hasConfig($className, $fieldName = null)
 {
     if (!$this->modelManager->checkDatabase()) {
         return false;
     }
     $result = $this->cache->getConfigurable($className, $fieldName);
     if ($result === false) {
         $result = (bool) $this->modelManager->findModel($className, $fieldName) ?: null;
         $this->cache->setConfigurable($result, $className, $fieldName);
     }
     return $result;
 }
コード例 #9
0
ファイル: ConfigManager.php プロジェクト: nmallare/platform
 /**
  * @param string $className
  * @param string $fieldName
  * @return bool
  */
 public function hasConfig($className, $fieldName = null)
 {
     if (!$this->modelManager->checkDatabase()) {
         return false;
     }
     $result = $this->cache->getConfigurable($className, $fieldName);
     if (null === $result) {
         $model = $fieldName ? $this->modelManager->findFieldModel($className, $fieldName) : $this->modelManager->findEntityModel($className);
         $result = null !== $model;
         $this->cache->setConfigurable($result, $className, $fieldName);
     }
     return $result;
 }
コード例 #10
0
 protected function loadVirtualFields()
 {
     $entities = $this->cache->getEntities();
     foreach ($entities as $className => $entityData) {
         $virtualFields = $this->virtualFieldProvider->getVirtualFields($className);
         if (!empty($virtualFields)) {
             foreach ($virtualFields as $fieldName) {
                 if (null === $this->cache->getConfigurable($className, $fieldName)) {
                     $this->cache->saveConfigurable(false, $className, $fieldName);
                 }
             }
         }
         $virtualRelations = $this->virtualRelationProvider->getVirtualRelations($className);
         if (!empty($virtualRelations)) {
             foreach ($virtualRelations as $fieldName => $config) {
                 if (null === $this->cache->getConfigurable($className, $fieldName)) {
                     $this->cache->saveConfigurable(false, $className, $fieldName);
                 }
             }
         }
     }
 }