0 follower

Final Class Yiisoft\Validator\Rule\FilledAtLeast

InheritanceYiisoft\Validator\Rule\FilledAtLeast
ImplementsYiisoft\Validator\DumpedRuleInterface, Yiisoft\Validator\SkipOnEmptyInterface, Yiisoft\Validator\SkipOnErrorInterface, Yiisoft\Validator\WhenInterface
Uses TraitsYiisoft\Validator\Rule\Trait\SkipOnEmptyTrait, Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait, Yiisoft\Validator\Rule\Trait\WhenTrait

Defines validation options to check that a minimum number of specified properties are filled.

Both arrays and objects with public properties are supported as validated values.

See also Yiisoft\Validator\Rule\FilledAtLeastHandler.

Public Methods

Hide inherited methods

Method Description Defined By
__construct() Yiisoft\Validator\Rule\FilledAtLeast
getHandler() Yiisoft\Validator\Rule\FilledAtLeast
getIncorrectInputMessage() Get the message used when the input is incorrect. Yiisoft\Validator\Rule\FilledAtLeast
getMessage() Get the message used when the value is not valid. Yiisoft\Validator\Rule\FilledAtLeast
getMin() Get the minimum required quantity of filled properties to pass the validation. Yiisoft\Validator\Rule\FilledAtLeast
getName() Yiisoft\Validator\Rule\FilledAtLeast
getOptions() Yiisoft\Validator\Rule\FilledAtLeast
getProperties() Get the list of required properties that will be checked. Yiisoft\Validator\Rule\FilledAtLeast
getSkipOnEmpty() A getter for $skipOnEmpty property. Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait
getWhen() A getter for $when property. Yiisoft\Validator\Rule\Trait\WhenTrait
shouldSkipOnError() A getter for $skipOnError property. Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait
skipOnEmpty() An immutable setter to change $skipOnEmpty property. Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait
skipOnError() An immutable setter to change $skipOnError property. Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait
when() An immutable setter to change $when property. Yiisoft\Validator\Rule\Trait\WhenTrait

Method Details

Hide inherited methods

__construct() public method

public mixed __construct ( string[] $properties, integer $min 1, string $incorrectInputMessage '{Property} must be an array or an object. {type} given.', string $message 'At least {min, number} {min, plural, one{property} other{properties}} from this list must be filled for {property}: {properties}.', boolean|callable|null $skipOnEmpty null, boolean $skipOnError false, Closure|null $when null )
$properties string[]

The list of required properties that will be checked.

$min integer

The minimum required quantity of filled properties to pass the validation. Defaults to 1.

$incorrectInputMessage string

A message used when the input is incorrect.

You may use the following placeholders in the message:

  • {property}: the translated label of the property being validated.
  • {type}: the type of the value being validated.
$message string

A message used when the value is not valid.

You may use the following placeholders in the message:

  • {property}: the translated label of the property being validated.
  • `{properties} - the translated labels of the properties some of which must be filled (within the property being validated).
  • {min}: the minimum number of property values that was not met.
$skipOnEmpty boolean|callable|null

Whether to skip this rule if the value validated is empty. See {@see \Yiisoft\Validator\SkipOnEmptyInterface}.

$skipOnError boolean

Whether to skip this rule if any of the previous rules gave an error. See {@see \Yiisoft\Validator\SkipOnErrorInterface}.

$when Closure|null

A callable to define a condition for applying the rule. See {@see \Yiisoft\Validator\WhenInterface}.

                public function __construct(
    private array $properties,
    private int $min = 1,
    private string $incorrectInputMessage = '{Property} must be an array or an object. {type} given.',
    private string $message = 'At least {min, number} {min, plural, one{property} other{properties}} from this list must be filled for {property}: {properties}.',
    bool|callable|null $skipOnEmpty = null,
    private bool $skipOnError = false,
    private ?Closure $when = null,
) {
    if ($min > count($this->properties)) {
        throw new InvalidArgumentException('$min must be no greater than amount of $properties.');
    }
    $this->skipOnEmpty = $skipOnEmpty;
}

            
getHandler() public method

public string getHandler ( )

                public function getHandler(): string
{
    return FilledAtLeastHandler::class;
}

            
getIncorrectInputMessage() public method

Get the message used when the input is incorrect.

public string getIncorrectInputMessage ( )
return string

Error message.

                public function getIncorrectInputMessage(): string
{
    return $this->incorrectInputMessage;
}

            
getMessage() public method

Get the message used when the value is not valid.

public string getMessage ( )
return string

Error message.

                public function getMessage(): string
{
    return $this->message;
}

            
getMin() public method

Get the minimum required quantity of filled properties to pass the validation.

public integer getMin ( )
return integer

Minimum require quantity.

                public function getMin(): int
{
    return $this->min;
}

            
getName() public method

public string getName ( )

                public function getName(): string
{
    return self::class;
}

            
getOptions() public method

public array getOptions ( )

                public function getOptions(): array
{
    return [
        'properties' => $this->properties,
        'min' => $this->min,
        'incorrectInputMessage' => [
            'template' => $this->incorrectInputMessage,
            'parameters' => [],
        ],
        'message' => [
            'template' => $this->message,
            'parameters' => ['min' => $this->min],
        ],
        'skipOnEmpty' => $this->getSkipOnEmptyOption(),
        'skipOnError' => $this->skipOnError,
    ];
}

            
getProperties() public method

Get the list of required properties that will be checked.

public string[] getProperties ( )
return string[]

The list of properties.

                public function getProperties(): array
{
    return $this->properties;
}

            
getSkipOnEmpty() public method

Defined in: Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait::getSkipOnEmpty()

A getter for $skipOnEmpty property.

public boolean|callable|null getSkipOnEmpty ( )
return boolean|callable|null

A current raw (non-normalized) value.

                public function getSkipOnEmpty(): bool|callable|null
{
    return $this->skipOnEmpty;
}

            
getWhen() public method

Defined in: Yiisoft\Validator\Rule\Trait\WhenTrait::getWhen()

A getter for $when property.

public Closure|null getWhen ( )
return Closure|null

Current value:

  • null - always apply the validation.
  • callable - apply the validation depending on a return value: true - apply, false - do not apply.

                public function getWhen(): ?Closure
{
    return $this->when;
}

            
shouldSkipOnError() public method

Defined in: Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait::shouldSkipOnError()

A getter for $skipOnError property.

public boolean shouldSkipOnError ( )
return boolean

Current value. true means to skip the current rule when the previous one errored and false - do not skip.

                public function shouldSkipOnError(): bool
{
    return $this->skipOnError;
}

            
skipOnEmpty() public method

Defined in: Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait::skipOnEmpty()

An immutable setter to change $skipOnEmpty property.

public $this skipOnEmpty ( boolean|callable|null $value )
$value boolean|callable|null

A new value.

return $this

The new instance with a changed value.

                public function skipOnEmpty(bool|callable|null $value): static
{
    $new = clone $this;
    $new->skipOnEmpty = $value;
    return $new;
}

            
skipOnError() public method

Defined in: Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait::skipOnError()

An immutable setter to change $skipOnError property.

public $this skipOnError ( boolean $value )
$value boolean

A new value. true means to skip the current rule when the previous one errored and false - do not skip.

return $this

The new instance with a changed value.

                public function skipOnError(bool $value): static
{
    $new = clone $this;
    $new->skipOnError = $value;
    return $new;
}

            
when() public method

Defined in: Yiisoft\Validator\Rule\Trait\WhenTrait::when()

An immutable setter to change $when property.

public $this when ( Closure|null $value )
$value Closure|null

A new value:

  • null - always apply the validation.
  • callable - apply the validation depending on a return value: true - apply, false - do not apply.
return $this

The new instance with a changed value.

                public function when(?Closure $value): static
{
    $new = clone $this;
    $new->when = $value;
    return $new;
}