private function transformTypeToValidTingType($type) { if ('enum' === $type) { return 'string'; } $datatype = $this->typeFactory->getTypeFromName($type); $map = [ObjectType::class => 'string', ArrayType::class => 'json', BooleanType::class => 'bool', DateTimeType::class => 'datetime', DateType::class => 'datetime', FloatType::class => 'double', IntegerType::class => 'int', JsonArrayType::class => 'json', StringType::class => 'string', TimeType::class => 'datetime']; return $map[get_class($datatype)]; }
/** * @param $propertyName * @param $propertyConfig * @return PropertyDefinition * @throws \Exception */ private function createProperty($propertyName, $propertyConfig) { $defaultValue = null; switch ($propertyConfig['type']) { case "relation": if (false === array_key_exists('entity', $propertyConfig)) { throw new \Exception(sprintf('property[type: Relation] %s must define "entity" key', $propertyName)); } $fqcn = $this->createEntityFqcn($this->configuration, $propertyConfig['entity']); if (true === array_key_exists('inverse', $propertyConfig)) { //Inversed side if (false === array_key_exists($propertyConfig['entity'], $this->configuration['entities'])) { throw new \Exception(sprintf('property[type: Relation] %s is inversed by %s but this entity does not exist ', $propertyName, $propertyConfig['entity'])); } if (false === array_key_exists($propertyConfig['inverse'], $this->configuration['entities'][$propertyConfig['entity']]['properties'])) { throw new \Exception(sprintf('property %s as %s for inverse property, but this property does not exist ', $propertyName, $propertyConfig['inverse'])); } $inversedProperty = $this->configuration['entities'][$propertyConfig['entity']]['properties'][$propertyConfig['inverse']]; if (false === array_key_exists('cardinality', $inversedProperty)) { throw new \Exception(sprintf('property[type: Relation] %s must define "cardinality" key', $propertyConfig['entity'])); } /** @var Cardinality $cardinality */ $cardinality = new Cardinality($inversedProperty['cardinality']); $type = new ObjectType($fqcn); if (true === $cardinality->hasSourceMany()) { $type = new ArrayType($type); } } else { //Relation Side $type = new ObjectType($fqcn); if (false === array_key_exists('cardinality', $propertyConfig)) { throw new \Exception(sprintf('property[type: Relation] %s must define "cardinality" key', $propertyName)); } /** @var Cardinality $cardinality */ $cardinality = new Cardinality($propertyConfig['cardinality']); if (true === $cardinality->hasTargetMany()) { $type = new ArrayType($type); } } break; case "enum": $fqcn = $this->createEnumFqcn($this->configuration, $propertyConfig['enum']); $type = new ObjectType($fqcn); if (true === array_key_exists('default', $propertyConfig)) { $defaultValue = new ObjectValue($fqcn, [new StringValue($propertyConfig['default'])]); } break; case "enum[]": $fqcn = $this->createEnumFqcn($this->configuration, $propertyConfig['enum']); $type = new ArrayType(new ObjectType($fqcn)); $defaultValue = new ArrayValue([]); break; default: $type = $this->typeFactory->getTypeFromName($propertyConfig['type']); if (true === array_key_exists('default', $propertyConfig)) { $defaultValue = $this->valueFactory->createValue($type, $propertyConfig['default']); } } $name = new PhpVariableName($propertyName); $property = new PropertyDefinition($propertyName, $propertyConfig, $type, $name, $defaultValue); return $property; }