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 ({@see 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 {@see $data} is already a data set, it will be left as is.
- An object is normalized to {@see \Yiisoft\Validator\DataSet\ObjectDataSet}.
- An array is normalized to {@see \Yiisoft\Validator\DataSet\ArrayDataSet}.
- Everything else is normalized to {@see \Yiisoft\Validator\DataSet\SingleValueDataSet}.
In order to prevent mapping objects and arrays to corresponding data sets, wrap them with {@see \Yiisoft\Validator\DataSet\SingleValueDataSet} explicitly or use a custom data set ({@see \Yiisoft\Validator\DataSetInterface}).
| public static Yiisoft\Validator\DataSetInterface normalize ( mixed $data ) | ||
| $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.