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 Yiisoft\Validator\DataSet\SingleValueDataSet by \Yiisoft\Validator\DataSet\DataSetNormalizer during validation.
For arrays and objects Yiisoft\Validator\DataSet\ArrayDataSet and 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. Yiisoft\Validator\DataSet\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 __construct( mixed $value ): mixed | ||
| $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 getData( ): array|null |
public function getData(): ?array
{
return null;
}
Returns a property value by its name. Yiisoft\Validator\DataSet\SingleValueDataSet does not support properties so null is always
returned regardless of the property name.
| public getPropertyValue( string $property ): mixed | ||
| $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 hasProperty( string $property ): boolean | ||
| $property | string |
Property name. |
| return | boolean |
|
|---|---|---|
public function hasProperty(string $property): bool
{
return false;
}
Signup or Login in order to comment.