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