/** * @param string|null $className * @param string|null $mode * @return EntityConfigModel */ public function createConfigEntityModel($className = null, $mode = ConfigModelManager::MODE_DEFAULT) { if (empty($className)) { $entityModel = $this->modelManager->createEntityModel($className, $mode); } else { $entityModel = $this->modelManager->findEntityModel($className); if (null === $entityModel) { $metadata = $this->getEntityMetadata($className); $newEntityMode = $metadata ? $metadata->mode : $mode; $entityModel = $this->modelManager->createEntityModel($className, $newEntityMode); foreach ($this->getProviders() as $provider) { $configId = new EntityConfigId($provider->getScope(), $className); $config = new Config($configId, $this->getEntityDefaultValues($provider, $className, $metadata)); $this->merge($config); // local cache $this->cache->saveConfig($config, true); $this->cache->saveConfigurable(true, $className, null, true); // for calculate change set $this->originalConfigs[$this->buildConfigKey($configId)] = clone $config; } $this->eventDispatcher->dispatch(Events::NEW_ENTITY_CONFIG, new EntityConfigEvent($className, $this)); } } return $entityModel; }
public function testCreateEntityModel() { $expectedResult = new EntityConfigModel(self::TEST_ENTITY); $expectedResult->setMode(ConfigModelManager::MODE_DEFAULT); $this->createRepositoryMock([], [UnitOfWork::STATE_MANAGED]); $result = $this->configModelManager->createEntityModel(self::TEST_ENTITY); $this->assertEquals($expectedResult, $result); // test that the created model is stored in a local cache $this->assertSame($result, $this->configModelManager->getEntityModel(self::TEST_ENTITY)); }
/** * TODO:: check class name for custom entity * * @param string $className * @param string $mode * @return EntityConfigModel */ public function createConfigEntityModel($className, $mode = ConfigModelManager::MODE_DEFAULT) { if (!($entityModel = $this->modelManager->findModel($className))) { $entityModel = $this->modelManager->createEntityModel($className, $mode); foreach ($this->getProviders() as $provider) { $metadata = $this->getEntityMetadata($className); $defaultValues = array(); if ($metadata && isset($metadata->defaultValues[$provider->getScope()])) { $defaultValues = $metadata->defaultValues[$provider->getScope()]; } $entityId = new EntityConfigId($className, $provider->getScope()); $config = $provider->createConfig($entityId, $defaultValues); $this->localCache->set($config->getId()->toString(), $config); } $this->eventDispatcher->dispatch(Events::NEW_ENTITY_CONFIG_MODEL, new NewEntityConfigModelEvent($entityModel, $this)); } return $entityModel; }
/** * @param string|null $className * @param string|null $mode * * @return EntityConfigModel */ public function createConfigEntityModel($className = null, $mode = null) { if (empty($className)) { $entityModel = $this->modelManager->createEntityModel($className, $mode ?: ConfigModel::MODE_DEFAULT); } else { $entityModel = $this->modelManager->findEntityModel($className); if (null === $entityModel) { $metadata = $this->getEntityMetadata($className); if (!$mode) { $mode = $metadata && $metadata->mode ? $metadata->mode : ConfigModel::MODE_DEFAULT; } $entityModel = $this->modelManager->createEntityModel($className, $mode); foreach ($this->providers as $scope => $provider) { $configKey = $scope . '.' . $className; $config = new Config(new EntityConfigId($scope, $className), $this->getEntityDefaultValues($scope, $className, $metadata)); $this->mergeConfigValues($config, $configKey); // put a config to a local cache $this->cache->saveConfig($config, true); // for calculate change set if (!isset($this->originalValues[$configKey])) { $this->originalValues[$configKey] = $config->getValues(); } } // put "configurable" flag to a local cache $this->cache->saveConfigurable(true, $className, null, true); // if needed, update the list of entities in a local cache $entities = $this->cache->getEntities(true); if (null !== $entities && !isset($entities[$className])) { $entities[$className] = ['i' => null, 'h' => $mode === ConfigModel::MODE_HIDDEN]; $this->cache->saveEntities($entities, true); } // @todo: Should be removed together with deprecated events if ($this->hasListeners(Events::NEW_ENTITY_CONFIG)) { $this->eventDispatcher->dispatch(Events::NEW_ENTITY_CONFIG, new Event\EntityConfigEvent($className, $this)); } $this->eventDispatcher->dispatch(Events::CREATE_ENTITY, new Event\EntityConfigEvent($className, $this)); } } return $entityModel; }
public function testCreateEntityModel() { $result = new EntityConfigModel(DemoEntity::ENTITY_NAME); $result->setMode(ConfigModelManager::MODE_DEFAULT); $this->assertEquals($result, $this->configModelManager->createEntityModel(DemoEntity::ENTITY_NAME)); }