AllowMultiple.php
4 years ago
HasDefaultValue.php
4 years ago
HasEmailTag.php
4 years ago
HasHelpText.php
4 years ago
HasLabel.php
4 years ago
HasMaxLength.php
4 years ago
HasMinLength.php
4 years ago
HasName.php
4 years ago
HasNodes.php
4 years ago
HasOptions.php
4 years ago
HasPlaceholder.php
4 years ago
HasType.php
4 years ago
HasVisibilityConditions.php
4 years ago
InsertNode.php
4 years ago
IsReadOnly.php
4 years ago
IsRequired.php
4 years ago
MoveNode.php
4 years ago
MoveNodeProxy.php
4 years ago
NameCollision.php
4 years ago
RemoveNode.php
4 years ago
SerializeAsJson.php
4 years ago
ShowInReceipt.php
4 years ago
StoreAsMeta.php
4 years ago
ValidationRules.php
4 years ago
WalkNodes.php
4 years ago
ValidationRules.php
87 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\Framework\FieldsAPI\Concerns; |
| 4 | |
| 5 | use JsonSerializable; |
| 6 | |
| 7 | /** |
| 8 | * @since 2.12.0 |
| 9 | */ |
| 10 | class ValidationRules implements JsonSerializable { |
| 11 | |
| 12 | /** @var array */ |
| 13 | protected $rules; |
| 14 | |
| 15 | /** |
| 16 | * ValidationRules constructor. |
| 17 | * |
| 18 | * @param array $rules |
| 19 | */ |
| 20 | public function __construct( $rules = [] ) { |
| 21 | $this->rules = $rules; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Set a rule. |
| 26 | * |
| 27 | * @since 2.12.0 |
| 28 | * |
| 29 | * @param string $rule |
| 30 | * @param mixed $value |
| 31 | * @return $this |
| 32 | */ |
| 33 | public function rule( $rule, $value ) { |
| 34 | $this->rules[ $rule ] = $value; |
| 35 | |
| 36 | return $this; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Get a rule. |
| 41 | * |
| 42 | * @since 2.12.0 |
| 43 | * |
| 44 | * @param string $rule |
| 45 | * @return mixed |
| 46 | */ |
| 47 | public function getRule( $rule ) { |
| 48 | return array_key_exists( $rule, $this->rules ) |
| 49 | ? $this->rules[ $rule ] |
| 50 | : null; |
| 51 | } |
| 52 | |
| 53 | /** |
| 54 | * Forget a rule. |
| 55 | * |
| 56 | * @since 2.12.0 |
| 57 | * |
| 58 | * @param string $rule |
| 59 | * @return $this |
| 60 | */ |
| 61 | public function forgetRule( $rule ) { |
| 62 | if ( array_key_exists( $rule, $this->rules ) ) { |
| 63 | unset( $this->rules[ $rule ] ); |
| 64 | } |
| 65 | |
| 66 | return $this; |
| 67 | } |
| 68 | |
| 69 | /** |
| 70 | * Get all the rules. |
| 71 | * |
| 72 | * @since 2.12.0 |
| 73 | * |
| 74 | * @return array |
| 75 | */ |
| 76 | public function all() { |
| 77 | return $this->rules; |
| 78 | } |
| 79 | |
| 80 | /** |
| 81 | * {@inheritdoc}} |
| 82 | */ |
| 83 | public function jsonSerialize() { |
| 84 | return (object) $this->all(); |
| 85 | } |
| 86 | } |
| 87 |