Trait Yiisoft\Validator\Rule\Trait\CountableLimitTrait
| Implemented by | Yiisoft\Validator\Rule\Count, Yiisoft\Validator\Rule\Length |
|---|
An implementation for {@see CountableLimitInterface} intended to be included in rules. The following arguments need to be added in constructor and passed with {@see initLimitProperties()} call:
public function __construct(
// ...
int|null $min = null,
int|null $max = null,
int|null $exactly = null,
string $lessThanMinMessage = 'Less than {min}.',
string $greaterThanMinMessage = 'Greater than {max}.',
string $greaterThanMinMessage = 'Not exactly {exactly}.',
// ...
) {
// ...
$this->initLimitProperties(
$min,
$max,
$exactly,
$lessThanMinMessage,
$greaterThanMaxMessage,
$notExactlyMessage,
);
// ...
}
Also, if a rule implements {@see \Yiisoft\Validator\Rule\Trait\DumpedRuleInterface}, you can merge limit related options instead of adding it manually:
public function getOptions(): array
{
return array_merge($this->getLimitOptions(), [
// Other rule options.
]);
}
Make sure to include {@see \Yiisoft\Validator\Rule\Trait\CountableLimitHandlerTrait} in according handler as well.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| getExactly() | A getter for {@see $exactly} property. | Yiisoft\Validator\Rule\Trait\CountableLimitTrait |
| getGreaterThanMaxMessage() | A getter for {@see $greaterThanMaxMessage} property. | Yiisoft\Validator\Rule\Trait\CountableLimitTrait |
| getLessThanMinMessage() | A getter for {@see $lessThanMinMessage} property. | Yiisoft\Validator\Rule\Trait\CountableLimitTrait |
| getMax() | A getter for {@see $max property}. | Yiisoft\Validator\Rule\Trait\CountableLimitTrait |
| getMin() | A getter for {@see $min} property. | Yiisoft\Validator\Rule\Trait\CountableLimitTrait |
| getNotExactlyMessage() | A getter for {@see $notExactlyMessage} property. | Yiisoft\Validator\Rule\Trait\CountableLimitTrait |
Method Details
A getter for {@see $exactly} property.
| public integer|null getExactly ( ) | ||
| return | integer|null |
A number representing "exactly" value. |
|---|---|---|
public function getExactly(): ?int
{
return $this->exactly;
}
A getter for {@see $greaterThanMaxMessage} property.
| public string getGreaterThanMaxMessage ( ) | ||
| return | string |
Validation error message. |
|---|---|---|
public function getGreaterThanMaxMessage(): string
{
return $this->greaterThanMaxMessage;
}
A getter for {@see $lessThanMinMessage} property.
| public string getLessThanMinMessage ( ) | ||
| return | string |
Validation error message. |
|---|---|---|
public function getLessThanMinMessage(): string
{
return $this->lessThanMinMessage;
}
A getter for {@see $max property}.
| public integer|null getMax ( ) | ||
| return | integer|null |
A number representing maximum boundary. |
|---|---|---|
public function getMax(): ?int
{
return $this->max;
}
A getter for {@see $min} property.
| public integer|null getMin ( ) | ||
| return | integer|null |
A number representing minimum boundary. |
|---|---|---|
public function getMin(): ?int
{
return $this->min;
}
A getter for {@see $notExactlyMessage} property.
| public string getNotExactlyMessage ( ) | ||
| return | string |
Validation error message. |
|---|---|---|
public function getNotExactlyMessage(): string
{
return $this->notExactlyMessage;
}
Signup or Login in order to comment.