mini\Converter\ConverterRegistryInterface::tryConvert() Method

public abstract

Signature

public abstract function tryConvert(mixed $input, string $targetType, ?string $sourceType = NULL, bool $found = false): mixed

Parameters

Name Type Default Description
$input mixed required Documentation missing
$targetType string required Documentation missing
$sourceType ?string NULL Documentation missing
$found bool false Documentation missing

Returns

mixed

Documentation

Try to convert a value, returning null if no converter handles it

Unlike convert(), this method doesn't throw. Use the $found out-parameter to distinguish between "converted to null" and "no converter found".

This method also checks fallback handlers, which has() does not.

$result = $registry->tryConvert($value, SomeEnum::class, 'sql-value', $found);
if ($found) {
    // $result is the converted value (may be null if converter returned null)
}

Source

src/Converter/ConverterRegistryInterface.php:179