PluginProbe ʕ •ᴥ•ʔ
Kirki – Freeform Page Builder, Website Builder & Customizer / 6.2.2
Kirki – Freeform Page Builder, Website Builder & Customizer v6.2.2
6.2.3 6.2.2 6.2.1 6.2.0 6.1.1 6.1.0 6.0.14 6.0.13 6.0.12 6.0.11 6.0.10 6.0.9 6.0.8 6.0.7 6.0.6 6.0.5 6.0.4 6.0.3 6.0.2 6.0.1 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 4.0.19 4.0.20 4.0.21 4.0.22 4.0.23 4.0.24 4.1 4.2.0 5.0.0 5.1.0 5.1.1 5.2.0 5.2.1 5.2.2 5.2.3 6.0.0 trunk 3.0.40 3.0.41 3.0.42 3.0.43 3.0.44 3.0.45 3.1.0 3.1.1 3.1.2
kirki / libraries / framework / Validation / Rules / ProhibitedIfRule.php
kirki / libraries / framework / Validation / Rules Last commit date
ArrayRule.php 2 weeks ago BooleanRule.php 2 weeks ago ConditionalRule.php 2 weeks ago DateRule.php 2 weeks ago ExistsRule.php 2 weeks ago FileRule.php 2 weeks ago InRule.php 2 weeks ago NotInRule.php 2 weeks ago NullableRule.php 2 weeks ago NumericRule.php 2 weeks ago ObjectRule.php 2 weeks ago ProhibitedIfRule.php 2 weeks ago ProhibitedRule.php 2 weeks ago ProhibitedUnlessRule.php 2 weeks ago RequiredIfRule.php 2 weeks ago RequiredRule.php 2 weeks ago RequiredUnlessRule.php 2 weeks ago SameAsRule.php 2 weeks ago SometimesRule.php 2 weeks ago StringRule.php 2 weeks ago UniqueRule.php 2 weeks ago
ProhibitedIfRule.php
95 lines
1 <?php
2
3 /**
4 * Prohibited rule class.
5 *
6 * @package Framework
7 * @subpackage Validation
8 * @since 1.0.0
9 */
10 namespace Kirki\Framework\Validation\Rules;
11
12 use Closure;
13 use Kirki\Framework\Supports\Arr;
14 use Kirki\Framework\Validation\ValidationRule;
15 use InvalidArgumentException;
16 use function Kirki\Framework\deep_get;
17 \defined('ABSPATH') || exit;
18 /**
19 * Validates that the given field is absent or empty.
20 */
21 class ProhibitedIfRule extends ValidationRule
22 {
23 /**
24 * The rule name.
25 *
26 * @var string
27 *
28 * @since 1.0.0
29 */
30 protected string $rule = 'prohibited_if';
31 /**
32 * Whether the rule is an implicit rule.
33 *
34 * @var bool
35 *
36 * @since 1.0.0
37 */
38 public bool $is_implicit = \true;
39 /**
40 * Validate the rule.
41 *
42 * @return bool
43 *
44 * @since 1.0.0
45 */
46 public function validate() : bool
47 {
48 $callback = $this->get_callback();
49 if (!$callback()) {
50 return \true;
51 }
52 if (static::is_nullish($this->value)) {
53 return \true;
54 }
55 return $this->fails($this->default_messages['default']);
56 }
57 /**
58 * Get the callback.
59 *
60 * @return Closure
61 *
62 * @since 1.0.0
63 */
64 protected function get_callback()
65 {
66 $arguments = Arr::wrap($this->args);
67 $other = array_first($arguments);
68 $value = \array_slice($arguments, 1);
69 if (!$other instanceof Closure) {
70 $other = function () use($other, $value) {
71 if (empty($value)) {
72 throw new InvalidArgumentException('The second argument must be a non-empty string.');
73 }
74 $data = deep_get($this->data, (string) $other);
75 if (\count($value) > 1) {
76 return \in_array($data, $value);
77 }
78 return $data == array_first($value);
79 };
80 }
81 return $other;
82 }
83 /**
84 * Get the error messages.
85 *
86 * @return array
87 *
88 * @since 1.0.0
89 */
90 public function messages()
91 {
92 return $this->process_messages($this->messages);
93 }
94 }
95