[Flow] Uniform Converting Behaviou (at least for simple types)

Carsten Bleicker carsten at bleicker.de
Sat Dec 13 18:42:41 CET 2014


Let's say we have an api receiving json to create an object:

/**
 * Class Bar
 *
 * @package ACME\Foo\Domain\Model
 * @Flow\Entity
 */
class Bar {

	/**
	 * @var string
	 * @ORM\Column(nullable=true)
	 */
	protected $string;

	/**
	 * @var integer
	 * @ORM\Column(nullable=true)
	 */
	protected $integer;

	/**
	 * @var float
	 * @ORM\Column(nullable=true)
	 */
	protected $float;

	/**
	 * @param float $float
	 * @param integer $integer
	 * @param string $string
	 */
	public function __construct($float = NULL, $integer = NULL, $string = NULL) {
		$this->float = $float;
		$this->integer = $integer;
		$this->string = $string;
	}
}


Incoming Request Json Body to create 
{
	"string":	null,
	"integer":	null,
	"float":	null
}


The Flow Core Converter for these simple types working different.
The Converted Result will be:

Bar::$string === ''
Bar::$integer === NULL
Bar::$float === NULL

So you can't set an NULL per API for strings.
In general at leas simple types wich can be nullable in the DB
should act the same way. They should respect NULL.

We can say: "Use initialize{n}Action" to handle the concrete mapping.
Okay, thats an argument. But at least the simple type converter should deliver uniform behavior.
If string converts strictly to '', also integer/float should convert strictly to 0.
The current behaviour is not uniform, imho and you always have to keep in mind,
that string handles different to others.

i would prefer to change AbstractConverter to make sure any converter handles NULL as return NULL:

public final function convertFrom($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL){
	if($source === NULL){
		return NULL;
	}else{
		return $this->
	}
	
}

abstract protected function convertFromImplementation($source, $targetType, array $convertedChildProperties = array(), \TYPO3\Flow\Property\PropertyMappingConfigurationInterface $configuration = NULL);

this would ensure to have a uniform NULL Behaviour

----------------------

Carsten Bleicker
Wülfingstraße 1
42477 Radevormwald

E-Mail:	carsten at bleicker.de
Web:	www.bleicker.de
Twitter:	@carstenbleicker
Jabber:	cbleicker at jabber.ccc.de
Telefon:	+49 (0)171-2690845



More information about the Flow mailing list