/** * Checks whether the name of a new field conflicts with the name of existing field. * * @param string $newFieldName * @param Config $existingFieldConfig * * @return bool */ public function hasFieldNameConflict($newFieldName, Config $existingFieldConfig) { $existingFieldName = $existingFieldConfig->getId()->getFieldName(); if (strtolower($newFieldName) === strtolower($existingFieldName)) { return true; } if ($this->normalizeFieldName($newFieldName) === $this->normalizeFieldName($existingFieldName) && !$existingFieldConfig->is('is_deleted') && !$existingFieldConfig->is('state', ExtendScope::STATE_DELETE)) { return true; } return false; }
public function testValueConfig() { $config = new Config(new EntityConfigId('testScope', 'testClass')); $values = array('firstKey' => 'firstValue', 'secondKey' => 'secondValue', 'thirdKey' => 3, 'fourthKey' => new \stdClass(), 'falseKey' => false, 'nullKey' => null); $config->setValues($values); $this->assertEquals($values, $config->all()); $this->assertEquals(array('firstKey' => 'firstValue'), $config->all(function ($value) { return $value == 'firstValue'; })); $this->assertEquals('firstValue', $config->get('firstKey')); $this->assertEquals('secondValue', $config->get('secondKey')); $this->assertTrue($config->is('secondKey')); $this->assertTrue($config->in('thirdKey', ['3'])); $this->assertFalse($config->in('thirdKey', ['3'], true)); $this->assertTrue($config->in('thirdKey', [3])); $this->assertTrue($config->in('thirdKey', [3], true)); $this->assertFalse($config->in('thirdKey', [100])); $this->assertTrue($config->has('secondKey')); $this->assertFalse($config->has('nonExistKey')); $this->assertTrue($config->has('falseKey')); $this->assertTrue($config->has('nullKey')); $this->assertNull($config->get('nonExistKey')); $this->assertFalse($config->get('falseKey')); $this->assertNull($config->get('nullKey')); $this->assertEquals($config, unserialize(serialize($config))); $config->set('secondKey', 'secondValue2'); $this->assertEquals('secondValue2', $config->get('secondKey')); $this->assertEquals(112233, $config->get('nonExistKey', false, 112233)); $this->assertEquals('default', $config->get('nonExistKey', false, 'default')); $this->assertEquals([], $config->get('nonExistKey', false, [])); $this->setExpectedException('Oro\\Bundle\\EntityConfigBundle\\Exception\\RuntimeException'); $config->get('nonExistKey', true); }
public function testValueConfig() { $values = array('firstKey' => 'firstValue', 'secondKey' => 'secondValue', 'fourthKey' => new \stdClass()); $this->config->setValues($values); $this->assertEquals($values, $this->config->all()); $this->assertEquals(array('firstKey' => 'firstValue'), $this->config->all(function ($value) { return $value == 'firstValue'; })); $this->assertEquals('firstValue', $this->config->get('firstKey')); $this->assertEquals('secondValue', $this->config->get('secondKey')); $this->assertEquals(true, $this->config->is('secondKey')); $this->assertEquals(true, $this->config->has('secondKey')); $this->assertEquals(false, $this->config->has('thirdKey')); $this->assertEquals(null, $this->config->get('thirdKey')); $this->assertEquals($this->config, unserialize(serialize($this->config))); $this->config->set('secondKey', 'secondValue2'); $this->assertEquals('secondValue2', $this->config->get('secondKey')); $this->setExpectedException('Oro\\Bundle\\EntityConfigBundle\\Exception\\RuntimeException'); $this->config->get('thirdKey', true); }
/** * @param Config $extendConfig * * @return bool */ protected function checkAvailability(Config $extendConfig) { return $extendConfig->is('is_extend') && $extendConfig->get('owner') == ExtendScope::OWNER_CUSTOM && $extendConfig->in('state', [ExtendScope::STATE_ACTIVE, ExtendScope::STATE_UPDATE]); }
protected function createRelation(Config $fieldConfig) { $selfConfig = $this->extendConfigProvider->getConfig($fieldConfig->getId()->getClassName()); $relations = $selfConfig->get('relation'); foreach ($relations as $relation) { if ($relation['field_id'] == $fieldConfig->getId()) { return; } } if ($fieldConfig->is('relation_key')) { $targetConfig = $this->extendConfigProvider->getConfig($fieldConfig->get('target_entity')); $relations = $targetConfig->get('relation'); if (isset($relations[$fieldConfig->get('relation_key')])) { $this->createTargetRelation($fieldConfig, $fieldConfig->get('relation_key')); } } $this->createSelfRelation($fieldConfig); }