0 follower

Trait Yiisoft\Validator\Rule\Trait\CountableLimitTrait

Implemented byYiisoft\Validator\Rule\Count, Yiisoft\Validator\Rule\Length

An implementation for CountableLimitInterface intended to be included in rules. The following arguments need to be added in constructor and passed with 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 \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 Yiisoft\Validator\Rule\Trait\CountableLimitHandlerTrait in according handler as well.

Public Methods

Hide inherited methods

Method Description Defined By
getExactly() A getter for $exactly property. Yiisoft\Validator\Rule\Trait\CountableLimitTrait
getGreaterThanMaxMessage() A getter for $greaterThanMaxMessage property. Yiisoft\Validator\Rule\Trait\CountableLimitTrait
getLessThanMinMessage() A getter for $lessThanMinMessage property. Yiisoft\Validator\Rule\Trait\CountableLimitTrait
getMax() A getter for $max property. Yiisoft\Validator\Rule\Trait\CountableLimitTrait
getMin() A getter for $min property. Yiisoft\Validator\Rule\Trait\CountableLimitTrait
getNotExactlyMessage() A getter for $notExactlyMessage property. Yiisoft\Validator\Rule\Trait\CountableLimitTrait

Method Details

Hide inherited methods

getExactly() public method

A getter for $exactly property.

public getExactly( ): integer|null
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 $greaterThanMaxMessage property.

public getGreaterThanMaxMessage( ): string
return string

Validation error message.

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

            
getLessThanMinMessage() public method

A getter for $lessThanMinMessage property.

public getLessThanMinMessage( ): string
return string

Validation error message.

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

            
getMax() public method

A getter for $max property.

public getMax( ): integer|null
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 $min property.

public getMin( ): integer|null
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 $notExactlyMessage property.

public getNotExactlyMessage( ): string
return string

Validation error message.

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