0 follower

Final Class Yiisoft\Validator\Helper\DataSetNormalizer

InheritanceYiisoft\Validator\Helper\DataSetNormalizer

A helper class used to normalize different types of validated data to a data set (Yiisoft\Validator\DataSetInterface).

Public Methods

Hide inherited methods

Method Description Defined By
normalize() Normalizes different types of validated data to a data set: Yiisoft\Validator\Helper\DataSetNormalizer

Method Details

Hide inherited methods

normalize() public static method

Normalizes different types of validated data to a data set:

In order to prevent mapping objects and arrays to corresponding data sets, wrap them with Yiisoft\Validator\DataSet\SingleValueDataSet explicitly or use a custom data set (Yiisoft\Validator\DataSetInterface).

public static normalize( mixed $data ): Yiisoft\Validator\DataSetInterface
$data mixed

Raw validated data of any type.

return Yiisoft\Validator\DataSetInterface

Data set instance.

                public static function normalize(mixed $data): DataSetInterface
{
    if ($data instanceof DataSetInterface) {
        return $data;
    }
    if (is_object($data)) {
        return new ObjectDataSet($data);
    }
    if (is_array($data)) {
        return new ArrayDataSet($data);
    }
    return new SingleValueDataSet($data);
}