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

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

Actually convert from $source to $targetType
public convertFrom ( mixed $source, string $targetType, array $convertedChildProperties = [], Neos\Flow\Property\PropertyMappingConfigurationInterface $configuration = null ) : boolean
$source mixed
$targetType string
$convertedChildProperties array
$configuration Neos\Flow\Property\PropertyMappingConfigurationInterface
Результат boolean
    public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
    {
        if (is_bool($source)) {
            return $source;
        }
        if (is_int($source) || is_float($source)) {
            return (bool) $source;
        }
        return !empty($source) && !in_array(strtolower($source), ['off', 'n', 'no', 'false']);
    }

Usage Example

 /**
  * @test
  * @param mixed $source
  * @param boolean $expected
  * @dataProvider convertFromDataProvider
  */
 public function convertFromTests($source, $expected)
 {
     $this->assertSame($expected, $this->converter->convertFrom($source, 'boolean'));
 }
BooleanConverter