/** * {@inheritdoc} */ public function isApplicableTarget(ConfigIdInterface $configId, ConfigManager $configManager) { if ($configId->getClassName() === 'Acme\\DemoBundle\\Entity\\CorrectEntity') { return true; } return false; }
/** * Returns a field type from the given config identifier if it represents a field * * @param ConfigIdInterface $configId * * @return string|null A field type if $configId represents a field; otherwise, null */ public function getFieldType(ConfigIdInterface $configId) { if ($configId instanceof FieldConfigId) { return $configId->getFieldType(); } return null; }
/** * {@inheritdoc} */ public function isApplicableTarget(ConfigIdInterface $configId, ConfigManager $configManager) { if ($configId->getClassName() === self::SUPPORTED_TARGET_CLASS_NAME) { return true; } return false; }
/** * @param ConfigIdInterface $configId * @param bool $immutable */ protected function setIsReadOnlyExpectations(ConfigIdInterface $configId, $immutable) { $className = $configId->getClassName(); if (empty($className)) { $this->typeHelper->expects($this->never())->method('isImmutable'); } else { $this->typeHelper->expects($this->once())->method('getFieldName')->with($this->identicalTo($configId))->will($this->returnValue($configId instanceof FieldConfigId ? $configId->getFieldName() : null)); $this->typeHelper->expects($this->once())->method('isImmutable')->with($configId->getScope(), $configId->getClassName(), $configId instanceof FieldConfigId ? $configId->getFieldName() : null)->will($this->returnValue($immutable)); } }
/** * @dataProvider setDefaultOptionsProvider */ public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $enumCode, $isImmutableAdd, $isImmutableDelete, $options, $expectedOptions) { $enumValueClassName = $enumCode ? ExtendHelper::buildEnumValueClassName($enumCode) : null; $this->typeHelper->expects($this->any())->method('getEnumCode')->with($configId->getClassName(), $configId instanceof FieldConfigId ? $configId->getFieldName() : null)->will($this->returnValue($enumCode)); $this->typeHelper->expects($this->any())->method('isImmutable')->will($this->returnValueMap([['enum', $enumValueClassName, null, 'add', $isImmutableAdd], ['enum', $enumValueClassName, null, 'delete', $isImmutableDelete]])); $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); $options['config_id'] = $configId; $options['config_is_new'] = $isNewConfig; $resolvedOptions = $resolver->resolve($options); $this->assertSame($configId, $resolvedOptions['config_id']); unset($resolvedOptions['config_id']); $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']); unset($resolvedOptions['config_is_new']); $this->assertFalse($resolvedOptions['handle_primary']); unset($resolvedOptions['handle_primary']); $this->assertEquals('oro_entity_extend_enum_value', $resolvedOptions['type']); unset($resolvedOptions['type']); $this->assertEquals($expectedOptions, $resolvedOptions); }
/** * @dataProvider setDefaultOptionsProvider */ public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $hasEnumCode, $options, $expectedOptions) { $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null; $this->typeHelper->expects($this->any())->method('hasEnumCode')->with($configId->getClassName(), $fieldName)->will($this->returnValue($hasEnumCode)); $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); $options['config_id'] = $configId; $options['config_is_new'] = $isNewConfig; $resolvedOptions = $resolver->resolve($options); $this->assertSame($configId, $resolvedOptions['config_id']); unset($resolvedOptions['config_id']); $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']); unset($resolvedOptions['config_is_new']); if ($hasEnumCode) { $this->assertCount(2, $resolvedOptions['constraints']); } else { $this->assertCount(5, $resolvedOptions['constraints']); } unset($resolvedOptions['constraints']); $this->assertEquals($expectedOptions, $resolvedOptions); }
/** * @dataProvider setDefaultOptionsProvider */ public function testSetDefaultOptions(ConfigIdInterface $configId, $isNewConfig, $enumCode, $isSystem, $isImmutablePublic, $hasOtherReferences, $options, $expectedOptions) { $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null; $enumValueClassName = $enumCode ? ExtendHelper::buildEnumValueClassName($enumCode) : null; $this->typeHelper->expects($this->any())->method('getEnumCode')->with($configId->getClassName(), $fieldName)->will($this->returnValue($enumCode)); $this->typeHelper->expects($this->any())->method('isSystem')->with($configId->getClassName(), $fieldName)->will($this->returnValue($isSystem)); $this->typeHelper->expects($this->any())->method('isImmutable')->with('enum', $enumValueClassName, null, 'public')->will($this->returnValue($isImmutablePublic)); $this->typeHelper->expects($this->any())->method('hasOtherReferences')->with($enumCode, $configId->getClassName(), $fieldName)->will($this->returnValue($hasOtherReferences)); $resolver = $this->getOptionsResolver(); $this->type->setDefaultOptions($resolver); $options['config_id'] = $configId; $options['config_is_new'] = $isNewConfig; $resolvedOptions = $resolver->resolve($options); $this->assertSame($configId, $resolvedOptions['config_id']); unset($resolvedOptions['config_id']); $this->assertEquals($isNewConfig, $resolvedOptions['config_is_new']); unset($resolvedOptions['config_is_new']); $this->assertEquals($expectedOptions, $resolvedOptions); }
/** * Creates an instance if Config class which stores configuration data for an object * which is represented by the given id. * The returned object is initialized with data specified $values argument. * * @param ConfigIdInterface $configId * @param array $values An associative array contains configuration properties * key = property name * value = property value * @return Config */ public function createConfig(ConfigIdInterface $configId, array $values) { $config = new Config($configId); if ($configId instanceof FieldConfigId) { $type = PropertyConfigContainer::TYPE_FIELD; $defaultValues = $this->getPropertyConfig()->getDefaultValues($type, $configId->getFieldType()); } else { $type = PropertyConfigContainer::TYPE_ENTITY; $defaultValues = $this->getPropertyConfig()->getDefaultValues($type); } $values = array_merge($defaultValues, $values); foreach ($values as $key => $value) { $config->set($key, $value); } $this->merge($config); return $config; }
/** * {@inheritdoc} */ public function getConfigById(ConfigIdInterface $configId) { if ($configId instanceof FieldConfigId) { return $this->configManager->getConfig($this->getId($configId->getClassName(), $configId->getFieldName())); } else { return $this->configManager->getConfig($this->getId($configId->getClassName())); } }
/** * Gets configuration data for the given entity or field. * * @param ConfigIdInterface $configId * * @return ConfigInterface */ public function getConfigById(ConfigIdInterface $configId) { $className = $configId->getClassName(); if ($configId instanceof FieldConfigId) { return $this->configManager->getFieldConfig($this->scope, $className, $configId->getFieldName()); } elseif ($className) { return $this->configManager->getEntityConfig($this->scope, $className); } else { return $this->configManager->createEntityConfig($this->scope); } }
/** * {@inheritdoc} */ public function getConfigById(ConfigIdInterface $configId) { return $configId instanceof FieldConfigId ? $this->getConfig($configId->getClassName(), $configId->getFieldName()) : $this->getConfig($configId->getClassName()); }
/** * Returns a string unique identifies each config item * * @param ConfigIdInterface $configId * @return string */ protected function buildConfigKey(ConfigIdInterface $configId) { return $configId instanceof FieldConfigId ? sprintf('%s_%s_%s', $configId->getScope(), $configId->getClassName(), $configId->getFieldName()) : sprintf('%s_%s', $configId->getScope(), $configId->getClassName()); }
/** * @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()); }
/** * @dataProvider getConfigNotCachedProvider */ public function testGetConfigNotCached(ConfigIdInterface $configId, $getModelResult, $expectedConfig) { $this->modelManager->expects($this->any())->method('checkDatabase')->willReturn(true); if ($configId instanceof FieldConfigId) { $this->configCache->expects($this->exactly(2))->method('getConfigurable')->willReturnMap([[$configId->getClassName(), null, true], [$configId->getClassName(), $configId->getFieldName(), true]]); $this->configCache->expects($this->once())->method('getFieldConfig')->with($configId->getScope(), $configId->getClassName(), $configId->getFieldName())->willReturn(null); } else { $this->configCache->expects($this->once())->method('getConfigurable')->with($configId->getClassName())->willReturn(true); $this->configCache->expects($this->once())->method('getEntityConfig')->with($configId->getScope(), $configId->getClassName())->willReturn(null); } $this->configCache->expects($this->once())->method('saveConfig')->with($this->equalTo($expectedConfig)); if ($configId instanceof FieldConfigId) { $this->modelManager->expects($this->never())->method('getEntityModel'); $this->modelManager->expects($this->once())->method('getFieldModel')->with($configId->getClassName(), $configId->getFieldName())->willReturn($getModelResult); } else { $this->modelManager->expects($this->once())->method('getEntityModel')->with($configId->getClassName())->willReturn($getModelResult); $this->modelManager->expects($this->never())->method('getFieldModel'); } $result = $this->configManager->getConfig($configId); $this->assertEquals($expectedConfig, $result); $this->configManager->calculateConfigChangeSet($result); $this->assertEquals([], $this->configManager->getConfigChangeSet($result)); }
/** * @param ConfigIdInterface $configId * * @return string */ protected function buildConfigCacheKey(ConfigIdInterface $configId) { return $configId instanceof FieldConfigId ? $configId->getClassName() . '_' . $configId->getFieldName() : $configId->getClassName(); }
/** * @param ConfigIdInterface $configId * @return AbstractConfigModel */ public function getModelByConfigId(ConfigIdInterface $configId) { $fieldName = $configId instanceof FieldConfigId ? $configId->getFieldName() : null; return $this->getModel($configId->getClassName(), $fieldName); }