Neos\Flow\Property\TypeConverter\FloatConverter::convertFrom PHP Метод

convertFrom() публичный Метод

Actually convert from $source to $targetType, by doing a typecast.
public convertFrom ( mixed $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : float | Neos\Error\Messages\Error
$source mixed
$targetType string
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
Результат float | Neos\Error\Messages\Error
    public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
    {
        if ($source === null || $source === '') {
            return null;
        } elseif (is_string($source) && $configuration instanceof PropertyMappingConfigurationInterface) {
            $source = $this->parseUsingLocaleIfConfigured($source, $configuration);
            if ($source instanceof Error) {
                return $source;
            }
        }
        if (!is_numeric($source)) {
            return new Error('"%s" cannot be converted to a float value.', 1332934124, [$source]);
        }
        return (double) $source;
    }

Usage Example

 /**
  * @test
  */
 public function convertFromDoesntUseLocaleParserIfNoConfigurationGiven()
 {
     $this->assertEquals(84, $this->converter->convertFrom('84.000', 'float'));
     $this->assertEquals(84.42, $this->converter->convertFrom('84.42', 'float'));
 }