0 follower

Final Class Yiisoft\Hydrator\ArrayData

InheritanceYiisoft\Hydrator\ArrayData
ImplementsYiisoft\Hydrator\DataInterface

Holds data to hydrate an object from and a map to use when populating an object.

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( array $data = [], array|Yiisoft\Hydrator\ObjectMap $map = [], boolean $strict false )
$data array

Data to hydrate object from.

$map array|Yiisoft\Hydrator\ObjectMap

Object property names mapped to keys in the data array that hydrator will use when hydrating an object.

$strict boolean

Whether to hydrate properties from the map only.

                public function __construct(
    private readonly array $data = [],
    array|ObjectMap $map = [],
    private readonly bool $strict = false,
) {
    $this->objectMap = is_array($map) ? new ObjectMap($map) : $map;
}

            
getValue() public method

public Yiisoft\Hydrator\Result getValue ( string $name )
$name string

                public function getValue(string $name): Result
{
    if ($this->strict && !$this->objectMap->exists($name)) {
        return Result::fail();
    }
    $path = $this->objectMap->getPath($name) ?? $name;
    if ($path instanceof ObjectMap) {
        return $this->getValueByObjectMap($this->data, $path);
    }
    return $this->getValueByPath($this->data, $path);
}