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

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. 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

Hide inherited methods

__construct() public method

public __construct( mixed $value ): mixed
$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 getData( ): array|null

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

            
getPropertyValue() public method

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

null value indicating that properties are not supported.

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

            
getSource() public method

public getSource( ): mixed

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

            
hasProperty() public method

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

public hasProperty( string $property ): boolean
$property string

Property name.

return boolean

false value indicating that properties are not supported.

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