Ocramius / GeneratedHydrator

:bullettrain_side: Fast Generated Object Hydrator for PHP
MIT License
726 stars 69 forks source link

Property: @var bool[] #647

Closed dliebner closed 1 year ago

dliebner commented 1 year ago
class ExampleDTO {
    public int $foo;
    protected string $bar;
    /** @var bool[] */
    protected $baz;
}

$config        = new Configuration('ExampleDTO');
$hydratorClass = $config->createFactory()->getHydratorClass();
$hydrator      = new $hydratorClass();

$hydrator->hydrate(
    ['foo' => '150', 'bar' => 5, 'baz' => [1,0,0]],
    $object = new ExampleDTO()
);

var_dump($object);

baz array isn't getting converted to bools. Is there a proper way to hint this that will enforce the casting of baz to bool[]?

Ocramius commented 1 year ago

Hydration is just hydration: conversion is up to you.

If you are looking for a mapper, see cuyz/valinor