0 follower

Final Class Yiisoft\Validator\DataSet\SingleValueDataSet

InheritanceYiisoft\Validator\DataSet\SingleValueDataSet
ImplementsYiisoft\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

Hide inherited 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

Hide inherited methods

__construct() public method

public mixed __construct ( mixed $value )
$value mixed

                public function __construct(
    /**
     * @var mixed Single value of any (mixed) data type.
     */
    private readonly mixed $value,
) {}

            
getData() public method

Returns the validated data as array.

public array|null getData ( )

                public function getData(): ?array
{
    return null;
}

            
getPropertyValue() public method

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

null value indicating that properties are not supported.

                public function getPropertyValue(string $property): mixed
{
    return null;
}

            
getSource() public method

public mixed getSource ( )

                public function getSource(): mixed
{
    return $this->value;
}

            
hasProperty() public method

Whether this data set has the property with a given name.

public boolean hasProperty ( string $property )
$property string

Property name.

return boolean

false value indicating that properties are not supported.

                public function hasProperty(string $property): bool
{
    return false;
}