Final Class Yiisoft\Validator\Helper\DataSetNormalizer
| Inheritance | Yiisoft\ |
|---|
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\ |
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 \
| public static Yiisoft\ | ||
| $data | mixed |
Raw validated data of any type. |
| return | Yiisoft\ |
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);
}
User Contributed Notes
Leave a comment
Join the conversation to share a note.