Final Class Yiisoft\Validator\Helper\DataSetNormalizer
| Inheritance | Yiisoft\Validator\Helper\DataSetNormalizer |
|---|
A helper class used to normalize different types of validated data to a data set (Yiisoft\Validator\DataSetInterface).
Public Methods
| Method | Description | Defined By |
|---|---|---|
| normalize() | Normalizes different types of validated data to a data set: | Yiisoft\Validator\Helper\DataSetNormalizer |
Method Details
Normalizes different types of validated data to a data set:
- If $data is already a data set, it will be left as is.
- An object is normalized to Yiisoft\Validator\DataSet\ObjectDataSet.
- An array is normalized to Yiisoft\Validator\DataSet\ArrayDataSet.
- Everything else is normalized to Yiisoft\Validator\DataSet\SingleValueDataSet.
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);
}
Signup or Login in order to comment.