AllowMultiple.php
4 years ago
HasDefaultValue.php
4 years ago
HasDescription.php
2 years ago
HasEmailTag.php
3 years ago
HasHelpText.php
4 years ago
HasLabel.php
3 years ago
HasMaxLength.php
3 years ago
HasMinLength.php
3 years ago
HasName.php
3 years ago
HasNodes.php
3 years ago
HasOptions.php
4 years ago
HasPersistence.php
2 years ago
HasPlaceholder.php
4 years ago
HasType.php
3 years ago
HasVisibilityConditions.php
2 years ago
InsertNode.php
3 years ago
IsReadOnly.php
4 years ago
IsRequired.php
3 years ago
Macroable.php
4 years ago
MoveNode.php
3 years ago
MoveNodeProxy.php
4 years ago
NameCollision.php
2 years ago
RemoveNode.php
2 years ago
SerializeAsJson.php
3 years ago
ShowInAdmin.php
3 years ago
ShowInReceipt.php
2 years ago
TapNode.php
3 years ago
WalkNodes.php
4 years ago
HasMinLength.php
47 lines
| 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 |