public function parseField($value, string $fieldType)
{
// Uses $fieldType method of the schema to parse the value
if (method_exists($this->schema, $fieldType)) {
return $this->schema->{$fieldType}($value);
}
// Returns null or an empty array
if (null === $value || is_array($value) && empty($value)) {
return $value;
}
// If fieldType is castable (Ex: 'int')
if (in_array($fieldType, $this->castableTypes)) {
return $this->cast($value, $fieldType);
}
// If the field type points to another schema.
if (substr($fieldType, 0, 7) == 'schema.') {
return $this->mapToSchema($value, substr($fieldType, 7));
}
return $value;
}