| 1 |
<?php |
| 2 |
|
| 3 |
namespace Give\Framework\FieldsAPI\Concerns; |
| 4 |
|
| 5 |
use Give\Vendors\StellarWP\Validation\Rules\Min; |
| 6 |
|
| 7 |
/** |
| 8 |
* @since 2.24.0 update to new validation system |
| 9 |
* @since 2.14.0 |
| 10 |
*/ |
| 11 |
trait HasMinLength |
| 12 |
{ |
| 13 |
/** |
| 14 |
* Set the value’s minimum length. |
| 15 |
* |
| 16 |
* @since 2.24.0 update to new validation system |
| 17 |
* @since 2.14.0 |
| 18 |
*/ |
| 19 |
public function minLength(int $minLength): self |
| 20 |
{ |
| 21 |
if ( $this->hasRule('min') ) { |
| 22 |
/** @var Min $rule */ |
| 23 |
$rule = $this->getRule('min'); |
| 24 |
$rule->size($minLength); |
| 25 |
} |
| 26 |
|
| 27 |
$this->rules("min:$minLength"); |
| 28 |
|
| 29 |
return $this; |
| 30 |
} |
| 31 |
|
| 32 |
/** |
| 33 |
* Get the value’s minimum length. |
| 34 |
* |
| 35 |
* @since 2.24.0 update to use the new validation system |
| 36 |
* @since 2.14.0 |
| 37 |
* |
| 38 |
* @return int|null |
| 39 |
*/ |
| 40 |
public function getMinLength() |
| 41 |
{ |
| 42 |
$rule = $this->getRule('min'); |
| 43 |
|
| 44 |
return $rule instanceof Min ? $rule->getSize() : null; |
| 45 |
} |
| 46 |
} |
| 47 |
|