Neos\Flow\Property\TypeConverter\UriTypeConverter::convertFrom PHP Méthode

convertFrom() public méthode

Converts the given string to a Uri object.
public convertFrom ( string $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : Uri | Neos\Error\Messages\Error
$source string The URI to be converted
$targetType string
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
Résultat Neos\Flow\Http\Uri | Neos\Error\Messages\Error if the input format is not supported or could not be converted for other reasons
    public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
    {
        try {
            return new Uri($source);
        } catch (\InvalidArgumentException $exception) {
            return new Error('The given URI "%s" could not be converted', 1351594881, [$source]);
        }
    }

Usage Example

 /**
  * @test
  */
 public function typeConverterReturnsErrorOnMalformedUri()
 {
     $actual = $this->typeConverter->convertFrom('http:////localhost', Http\Uri::class);
     $this->assertInstanceOf(FlowError\Error::class, $actual);
 }
UriTypeConverter