/** * @param SchemaId $schemaId * @param array $field * * @return FieldDescriptor|null */ private function getFieldDescriptor(SchemaId $schemaId, array $field) { // force default type to be "string" if (!isset($field['type'])) { $field['type'] = 'string'; } if (!isset($field['options'])) { $field['options'] = []; } if (isset($field['any-of']) && in_array($field['type'], [TypeName::GEO_POINT(), TypeName::IDENTIFIER(), TypeName::MESSAGE_REF()])) { unset($field['any-of']); } if (isset($field['any-of']['curie'])) { $field['any-of'] = $this->getAnyOf($schemaId, $this->fixArray($field['any-of']['curie'])); } if (isset($field['any-of']) && count($field['any-of']) === 0) { unset($field['any-of']); } if (isset($field['enum'])) { /** @var $enum EnumDescriptor */ if (!($enum = $this->getEnumById($field['enum']['id']))) { throw new \RuntimeException(sprintf('No Enum with id ["%s"] exist.', $field['enum']['id'])); } switch ($field['type']) { case 'int-enum': case 'string-enum': if (substr($field['type'], 0, -5) != $enum->getType()) { throw new \RuntimeException(sprintf('Invalid Enum ["%s"] type. A ["%s-enum"] is required.', $field['enum']['name'], $enum->getType())); } break; default: throw new \RuntimeException(sprintf('Invalid Enum type.')); } $field['enum'] = $enum; } return new FieldDescriptor($field['name'], $field); }
/** * {@inheritdoc} */ public final function getTypeValue() { return $this->typeName->getValue(); }