Final Class Yiisoft\Validator\Rule\FilledOnlyOneOf
Defines validation options to check that only one of specified properties is filled.
Both arrays and objects with public properties are supported as validated values.
Public Methods
Method Details
| public __construct( string[] $properties, string $incorrectInputMessage = '{Property} must be an array or an object. {type} given.', string $message = 'Exactly 1 property from this list must be filled for {property}: {properties}.', boolean|callable|null $skipOnEmpty = null, boolean $skipOnError = false, Closure|null $when = null ): mixed | ||
| $properties | string[] |
The list of required properties that will be checked. |
| $incorrectInputMessage | string |
A message used when the input is incorrect. You may use the following placeholders in the message:
|
| $message | string |
A message used when the value is not valid. You may use the following placeholders in the message:
|
| $skipOnEmpty | boolean|callable|null |
Whether to skip this rule if the value validated is empty. See Yiisoft\Validator\SkipOnEmptyInterface. |
| $skipOnError | boolean |
Whether to skip this rule if any of the previous rules gave an error. See Yiisoft\Validator\SkipOnErrorInterface. |
| $when | Closure|null |
A callable to define a condition for applying the rule. See Yiisoft\Validator\WhenInterface. |
public function __construct(
private array $properties,
private string $incorrectInputMessage = '{Property} must be an array or an object. {type} given.',
private string $message = 'Exactly 1 property from this list must be filled for {property}: {properties}.',
bool|callable|null $skipOnEmpty = null,
private bool $skipOnError = false,
private ?Closure $when = null,
) {
$this->skipOnEmpty = $skipOnEmpty;
}
| public getHandler( ): string |
public function getHandler(): string
{
return FilledOnlyOneOfHandler::class;
}
Get the message used when the input is incorrect.
| public getIncorrectInputMessage( ): string | ||
| return | string |
Error message. |
|---|---|---|
public function getIncorrectInputMessage(): string
{
return $this->incorrectInputMessage;
}
Get the message used when the value is not valid.
| public getMessage( ): string | ||
| return | string |
Error message. |
|---|---|---|
public function getMessage(): string
{
return $this->message;
}
| public getOptions( ): array |
public function getOptions(): array
{
return [
'properties' => $this->properties,
'incorrectInputMessage' => [
'template' => $this->incorrectInputMessage,
'parameters' => [],
],
'message' => [
'template' => $this->message,
'parameters' => [],
],
'skipOnEmpty' => $this->getSkipOnEmptyOption(),
'skipOnError' => $this->skipOnError,
];
}
Get the list of required properties that will be checked.
| public getProperties( ): string[] | ||
| return | string[] |
The list of properties. |
|---|---|---|
public function getProperties(): array
{
return $this->properties;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait::getSkipOnEmpty()
A getter for $skipOnEmpty property.
| public getSkipOnEmpty( ): boolean|callable|null | ||
| return | boolean|callable|null |
A current raw (non-normalized) value. |
|---|---|---|
public function getSkipOnEmpty(): bool|callable|null
{
return $this->skipOnEmpty;
}
Defined in: Yiisoft\Validator\Rule\Trait\WhenTrait::getWhen()
A getter for $when property.
| public getWhen( ): Closure|null | ||
| return | Closure|null |
Current value:
|
|---|---|---|
public function getWhen(): ?Closure
{
return $this->when;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait::shouldSkipOnError()
A getter for $skipOnError property.
| public shouldSkipOnError( ): boolean | ||
| return | boolean |
Current value. |
|---|---|---|
public function shouldSkipOnError(): bool
{
return $this->skipOnError;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnEmptyTrait::skipOnEmpty()
An immutable setter to change $skipOnEmpty property.
| public skipOnEmpty( boolean|callable|null $value ): $this | ||
| $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;
}
Defined in: Yiisoft\Validator\Rule\Trait\SkipOnErrorTrait::skipOnError()
An immutable setter to change $skipOnError property.
| public skipOnError( boolean $value ): $this | ||
| $value | boolean |
A new value. |
| return | $this |
The new instance with a changed value. |
|---|---|---|
public function skipOnError(bool $value): static
{
$new = clone $this;
$new->skipOnError = $value;
return $new;
}
Defined in: Yiisoft\Validator\Rule\Trait\WhenTrait::when()
An immutable setter to change $when property.
| public when( Closure|null $value ): $this | ||
| $value | Closure|null |
A new value:
|
| return | $this |
The new instance with a changed value. |
|---|---|---|
public function when(?Closure $value): static
{
$new = clone $this;
$new->when = $value;
return $new;
}
Signup or Login in order to comment.