-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathConditionalLogicGroup.php
54 lines (48 loc) · 1.54 KB
/
ConditionalLogicGroup.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<?php
/**
* ACF Codifier conditional logic class.
*/
namespace Geniem\ACF;
/**
* Class ConditionalLogicGroup
*/
class ConditionalLogicGroup {
/**
* The conditional logic rules
*
* @var array Conditional Logic rules to be stored
*/
protected $rules = [];
/**
* Add a conditional logic rule.
*
* @param mixed $field The slug of the field to be compared to.
* @param string $operator Operator to be used, either '==' or '!='.
* @param mixed $value Value to be used in comparison.
* @throws \Geniem\ACF\Exception Throw error if given parameter is not valid.
* @return self
*/
public function add_rule( $field, string $operator, $value ) {
// Check for valid values for the parameters.
if ( ! in_array( $operator, [ '==', '!=' ], true ) ) {
throw new \Geniem\ACF\Exception( 'Geniem\ACF\ConditionalRule: add_role() does not accept argument "' . $operator . '"' );
}
if ( ! ( $field instanceof \Geniem\ACF\Field || is_string( $field ) ) ) {
throw new \Geniem\ACF\Exception( 'Geniem\ACF\Field\Clone: add_role() requires an argument that is a string or type "\Geniem\ACF\Field"' );
}
$this->rules[] = [
'field' => $field,
'operator' => $operator,
'value' => $value,
];
return $this;
}
/**
* Get added conditional logic rules.
*
* @return array
*/
public function get_rules() {
return $this->rules;
}
}