Final Class Yiisoft\Validator\DataSet\ArrayDataSet
| Inheritance | Yiisoft\Validator\DataSet\ArrayDataSet |
|---|---|
| Implements | Yiisoft\Validator\DataWrapperInterface |
A data set for storing data as an associative array, where keys are property names and values are their corresponding values. An example of usage:
$dataSet = new ArrayDataSet(['name' => 'John', 'age' => 18]);
When using validator, there is no need to wrap your data manually. Array will be automatically wrapped with {@see \Yiisoft\Validator\DataSet\ArrayDataSet} by {@see \Yiisoft\Validator\Helper\DataSetNormalizer} during validation.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Validator\DataSet\ArrayDataSet | |
| getData() | A getter for {@see $data} property. Returns the validated data as a whole in a form of array. | Yiisoft\Validator\DataSet\ArrayDataSet |
| getPropertyValue() | Returns a property value by its name. | Yiisoft\Validator\DataSet\ArrayDataSet |
| getSource() | Yiisoft\Validator\DataSet\ArrayDataSet | |
| hasProperty() | Whether this data set has the property with a given name. Note that this means existence only and properties with empty values are treated as present too. | Yiisoft\Validator\DataSet\ArrayDataSet |
Method Details
| public mixed __construct ( array $data = [] ) | ||
| $data | array | |
public function __construct(
/**
* @var array A mapping between property names and their values.
*/
private array $data = [],
) {}
A getter for {@see $data} property. Returns the validated data as a whole in a form of array.
| public array getData ( ) | ||
| return | array |
A mapping between property names and their values. |
|---|---|---|
public function getData(): array
{
return $this->data;
}
Returns a property value by its name.
Note that in case of non-existing property a default null value is returned. If you need to check the presence
of property or return a different default value, use {@see \Yiisoft\Validator\DataSet\hasProperty()} instead.
| public mixed getPropertyValue ( string $property ) | ||
| $property | string |
Property name. |
| return | mixed |
Property value. |
|---|---|---|
public function getPropertyValue(string $property): mixed
{
return $this->data[$property] ?? null;
}
Whether this data set has the property with a given name. Note that this means existence only and properties with empty values are treated as present too.
| public boolean hasProperty ( string $property ) | ||
| $property | string |
Property name. |
| return | boolean |
Whether the property exists: |
|---|---|---|
public function hasProperty(string $property): bool
{
return array_key_exists($property, $this->data);
}
Signup or Login in order to comment.