mini\Converter\ConverterRegistryInterface::convert()
Method
public
abstract
Signature
public abstract function convert(mixed $input, string $targetType, ?string $sourceType = NULL): mixed
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
$input |
mixed |
required | Documentation missing |
$targetType |
string |
required | Documentation missing |
$sourceType |
?string |
NULL
|
Documentation missing |
Returns
mixed
Documentation
Convert a value to target type
Finds the most specific converter and performs the conversion. Throws if no suitable converter is found.
Use has() to check if a converter exists before calling convert():
if ($registry->has($value, ResponseInterface::class)) {
$response = $registry->convert($value, ResponseInterface::class);
}
// With named source type for database hydration
$datetime = $registry->convert($dbString, \DateTimeImmutable::class, 'sql-value');