Final Class Yiisoft\Validator\DataSet\SingleValueDataSet
| Inheritance | Yiisoft\Validator\DataSet\SingleValueDataSet |
|---|---|
| Implements | Yiisoft\Validator\DataWrapperInterface |
A data set used for a single value of any (mixed) data type. Does not support PHP attributes.
Examples of usage:
$dataSet = new SingleValueDataSet(5);
$dataSet = new SingleValueDataSet(2.5);
$dataSet = new SingleValueDataSet('text');
$dataSet = new SingleValueDataSet(null);
$dataSet = new SingleValueDataSet(false);
$dataSet = new SingleValueDataSet([]);
$dataSet = new SingleValueDataSet(new \stdClass());
When using validator, there is no need to wrap data manually. Such types be automatically wrapped with {@see \Yiisoft\Validator\DataSet\SingleValueDataSet} by {@see \Yiisoft\Validator\DataSet\DataSetNormalizer} during validation.
For arrays and objects {@see \Yiisoft\Validator\DataSet\ArrayDataSet} and {@see \Yiisoft\Validator\DataSet\ObjectDataSet} can be used accordingly.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Validator\DataSet\SingleValueDataSet | |
| getData() | Returns the validated data as array. | Yiisoft\Validator\DataSet\SingleValueDataSet |
| getPropertyValue() | Returns a property value by its name. {@see SingleValueDataSet} does not support properties so null is always
returned regardless of the property name. |
Yiisoft\Validator\DataSet\SingleValueDataSet |
| getSource() | Yiisoft\Validator\DataSet\SingleValueDataSet | |
| hasProperty() | Whether this data set has the property with a given name. | Yiisoft\Validator\DataSet\SingleValueDataSet |
Method Details
| public mixed __construct ( mixed $value ) | ||
| $value | mixed | |
public function __construct(
/**
* @var mixed Single value of any (mixed) data type.
*/
private readonly mixed $value,
) {}
Returns the validated data as array.
| public array|null getData ( ) |
public function getData(): ?array
{
return null;
}
Returns a property value by its name. {@see SingleValueDataSet} does not support properties so null is always
returned regardless of the property name.
| public mixed getPropertyValue ( string $property ) | ||
| $property | string |
Property name. |
| return | mixed |
|
|---|---|---|
public function getPropertyValue(string $property): mixed
{
return null;
}
Whether this data set has the property with a given name.
| public boolean hasProperty ( string $property ) | ||
| $property | string |
Property name. |
| return | boolean |
|
|---|---|---|
public function hasProperty(string $property): bool
{
return false;
}
Signup or Login in order to comment.