0 follower

Trait Yiisoft\Validator\Rule\Trait\CountableLimitTrait

Implemented byYiisoft\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

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

Hide inherited methods

getExactly() public method

A getter for {@see $exactly} property.

public integer|null getExactly ( )
return integer|null

A number representing "exactly" value. null means no strict comparison so lower / upper limits / both must be set.

                public function getExactly(): ?int
{
    return $this->exactly;
}

            
getGreaterThanMaxMessage() public method

A getter for {@see $greaterThanMaxMessage} property.

public string getGreaterThanMaxMessage ( )
return string

Validation error message.

                public function getGreaterThanMaxMessage(): string
{
    return $this->greaterThanMaxMessage;
}

            
getLessThanMinMessage() public method

A getter for {@see $lessThanMinMessage} property.

public string getLessThanMinMessage ( )
return string

Validation error message.

                public function getLessThanMinMessage(): string
{
    return $this->lessThanMinMessage;
}

            
getMax() public method

A getter for {@see $max property}.

public integer|null getMax ( )
return integer|null

A number representing maximum boundary. null means no upper bound.

                public function getMax(): ?int
{
    return $this->max;
}

            
getMin() public method

A getter for {@see $min} property.

public integer|null getMin ( )
return integer|null

A number representing minimum boundary. null means no lower bound.

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

            
getNotExactlyMessage() public method

A getter for {@see $notExactlyMessage} property.

public string getNotExactlyMessage ( )
return string

Validation error message.

                public function getNotExactlyMessage(): string
{
    return $this->notExactlyMessage;
}