PluginProbe ʕ •ᴥ•ʔ
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode / 4.2.2
Cookiebot by Usercentrics – Automatic Cookie Banner for GDPR/CCPA & Google Consent Mode v4.2.2
4.7.2 4.7.1 trunk 2.3.0 2.4.0 2.4.1 2.4.2 2.5.0 3.0.0 3.0.1 3.1.0 3.10.0 3.10.1 3.11.1 3.11.2 3.11.3 3.2.0 3.3.0 3.3.1 3.4.0 3.4.1 3.4.2 3.5.0 3.6.0 3.6.1 3.6.2 3.6.5 3.6.6 3.7.0 3.7.1 3.8.0 3.9.0 4.0.0 4.0.1 4.0.2 4.0.3 4.1.0 4.1.1 4.2.0 4.2.1 4.2.10 4.2.11 4.2.12 4.2.13 4.2.14 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.3.10 4.3.11 4.3.12 4.3.2 4.3.3 4.3.4 4.3.5 4.3.6 4.3.7 4.3.7.1 4.3.8 4.3.9 4.3.9.1 4.4.0 4.4.1 4.4.2 4.5.0 4.5.1 4.5.10 4.5.11 4.5.2 4.5.3 4.5.4 4.5.5 4.5.6 4.5.7 4.5.8 4.5.9 4.6.0 4.6.1 4.6.2 4.6.3 4.6.4 4.6.5 4.6.6 4.6.7 4.7.0
cookiebot / src / lib / traits / Class_Constant_Override_Validator_Trait.php
cookiebot / src / lib / traits Last commit date
Class_Constant_Override_Validator_Trait.php 4 years ago Extra_Information_Trait.php 4 years ago
Class_Constant_Override_Validator_Trait.php
120 lines
1 <?php
2
3 namespace cybot\cookiebot\lib\traits;
4
5 use Exception;
6 use InvalidArgumentException;
7
8 trait Class_Constant_Override_Validator_Trait {
9
10 /**
11 * @param array $fixed_class_constant_names
12 *
13 * @throws Exception
14 */
15 protected function validate_fixed_class_constants( array $fixed_class_constant_names ) {
16 foreach ( $fixed_class_constant_names as $fixed_class_constant_name ) {
17 $this->validate_fixed_class_constant( $fixed_class_constant_name );
18 }
19 }
20
21 /**
22 * @param $fixed_class_constant_name
23 *
24 * @throws Exception
25 */
26 protected function validate_fixed_class_constant( $fixed_class_constant_name ) {
27 $value_self = constant( 'self::' . $fixed_class_constant_name );
28 $value_static = constant( 'static::' . $fixed_class_constant_name );
29 if ( $value_self !== $value_static ) {
30 throw new Exception( 'Class constant "' . $fixed_class_constant_name . '" should be changed by ' . static::class );
31 }
32 }
33
34 /**
35 * @param array $required_string_constant_names
36 *
37 * @throws Exception
38 */
39 protected function validate_required_string_class_constants( array $required_string_constant_names ) {
40 foreach ( $required_string_constant_names as $required_string_constant_name ) {
41 $this->validate_required_string_class_constant( $required_string_constant_name );
42 }
43 }
44
45 /**
46 * @param string $required_string_constant_name
47 *
48 * @throws Exception
49 */
50 protected function validate_required_string_class_constant( $required_string_constant_name ) {
51 if ( ! is_string( $required_string_constant_name ) ) {
52 throw new InvalidArgumentException();
53 }
54 $value = constant( 'static::' . $required_string_constant_name );
55 if ( empty( $value ) || ! is_string( $value ) ) {
56 throw new Exception( 'Class constant "' . $required_string_constant_name . '" must be a non-empty string in ' . static::class );
57 }
58 }
59
60 /**
61 * @param array $required_boolean_constant_names
62 *
63 * @throws Exception
64 */
65 protected function validate_required_boolean_class_constants( array $required_boolean_constant_names ) {
66 foreach ( $required_boolean_constant_names as $required_boolean_constant_name ) {
67 $this->validate_required_boolean_class_constant( $required_boolean_constant_name );
68 }
69 }
70
71 /**
72 * @param string $required_boolean_constant_name
73 *
74 * @throws Exception
75 */
76 protected function validate_required_boolean_class_constant( $required_boolean_constant_name ) {
77 if ( ! is_string( $required_boolean_constant_name ) ) {
78 throw new InvalidArgumentException();
79 }
80 $value = constant( 'static::' . $required_boolean_constant_name );
81 if ( ! is_bool( $value ) ) {
82 throw new Exception( 'Class constant "' . $required_boolean_constant_name . '" must be a boolean in ' . static::class );
83 }
84 }
85
86 /**
87 * @param array $required_array_constant_names
88 *
89 * @throws Exception
90 */
91 protected function validate_required_array_class_constants( array $required_array_constant_names ) {
92 foreach ( $required_array_constant_names as $required_array_constant_name ) {
93 $this->validate_required_array_class_constant( $required_array_constant_name );
94 }
95 }
96
97 /**
98 * @param $required_array_constant_name
99 * @param array|null $allowed_item_values
100 *
101 * @throws Exception
102 */
103 protected function validate_required_array_class_constant( $required_array_constant_name, array $allowed_item_values = null ) {
104 if ( ! is_string( $required_array_constant_name ) ) {
105 throw new InvalidArgumentException();
106 }
107 $value = constant( 'static::' . $required_array_constant_name );
108 if ( empty( $value ) || ! is_array( $value ) ) {
109 throw new Exception( 'Class constant "' . $required_array_constant_name . '" must be an array in ' . static::class );
110 }
111 if ( ! empty( $allowed_item_values ) ) {
112 foreach ( $value as $item ) {
113 if ( ! in_array( $item, $allowed_item_values, true ) ) {
114 throw new Exception( 'Class constant "' . $required_array_constant_name . '" array items should be one of "' . implode( ', ', $allowed_item_values ) . '" in ' . static::class );
115 }
116 }
117 }
118 }
119 }
120