@@ -19,7 +19,7 @@ |
||
19 | 19 | */ |
20 | 20 | public function __construct($validation_error_message = null) |
21 | 21 | { |
22 | - if (! $validation_error_message) { |
|
22 | + if ( ! $validation_error_message) { |
|
23 | 23 | $validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso"); |
24 | 24 | } |
25 | 25 | parent::__construct($validation_error_message); |
@@ -13,28 +13,28 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Plaintext_Validation_Strategy extends EE_Validation_Strategy_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * @param null $validation_error_message |
|
18 | - */ |
|
19 | - public function __construct($validation_error_message = null) |
|
20 | - { |
|
21 | - if (! $validation_error_message) { |
|
22 | - $validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso"); |
|
23 | - } |
|
24 | - parent::__construct($validation_error_message); |
|
25 | - } |
|
16 | + /** |
|
17 | + * @param null $validation_error_message |
|
18 | + */ |
|
19 | + public function __construct($validation_error_message = null) |
|
20 | + { |
|
21 | + if (! $validation_error_message) { |
|
22 | + $validation_error_message = esc_html__("HTML tags are not permitted in this field", "event_espresso"); |
|
23 | + } |
|
24 | + parent::__construct($validation_error_message); |
|
25 | + } |
|
26 | 26 | |
27 | - /** |
|
28 | - * @param string|null $normalized_value |
|
29 | - * @throws EE_Validation_Error |
|
30 | - */ |
|
31 | - public function validate($normalized_value) |
|
32 | - { |
|
33 | - $normalized_value = (string) $normalized_value; |
|
34 | - $no_tags = wp_strip_all_tags($normalized_value); |
|
35 | - if (strlen($no_tags) < strlen(trim($normalized_value))) { |
|
36 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'no_html_tags'); |
|
37 | - } |
|
38 | - parent::validate($normalized_value); |
|
39 | - } |
|
27 | + /** |
|
28 | + * @param string|null $normalized_value |
|
29 | + * @throws EE_Validation_Error |
|
30 | + */ |
|
31 | + public function validate($normalized_value) |
|
32 | + { |
|
33 | + $normalized_value = (string) $normalized_value; |
|
34 | + $no_tags = wp_strip_all_tags($normalized_value); |
|
35 | + if (strlen($no_tags) < strlen(trim($normalized_value))) { |
|
36 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'no_html_tags'); |
|
37 | + } |
|
38 | + parent::validate($normalized_value); |
|
39 | + } |
|
40 | 40 | } |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function __construct($validation_error_message = null, $requirement_conditions = array()) |
30 | 30 | { |
31 | - if (! $validation_error_message) { |
|
31 | + if ( ! $validation_error_message) { |
|
32 | 32 | $validation_error_message = esc_html__("This field is required.", "event_espresso"); |
33 | 33 | } |
34 | 34 | $this->set_requirement_conditions($requirement_conditions); |
@@ -116,7 +116,7 @@ discard block |
||
116 | 116 | { |
117 | 117 | $requirement_value = ''; |
118 | 118 | $conditions = $this->get_requirement_conditions(); |
119 | - if (! is_array($conditions)) { |
|
119 | + if ( ! is_array($conditions)) { |
|
120 | 120 | EE_Error::throw_exception_if_debugging( |
121 | 121 | sprintf( |
122 | 122 | esc_html__('Input requirement conditions must be an array. You provided %1$s', 'event_espresso'), |
@@ -141,7 +141,7 @@ discard block |
||
141 | 141 | } |
142 | 142 | foreach ($conditions as $input_path => $op_and_value) { |
143 | 143 | $input = $this->_input->find_section_from_path($input_path); |
144 | - if (! $input instanceof EE_Form_Input_Base) { |
|
144 | + if ( ! $input instanceof EE_Form_Input_Base) { |
|
145 | 145 | EE_Error::throw_exception_if_debugging( |
146 | 146 | sprintf( |
147 | 147 | esc_html__('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
@@ -154,9 +154,9 @@ discard block |
||
154 | 154 | ); |
155 | 155 | return false; |
156 | 156 | } |
157 | - list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
157 | + list($op, $value) = $this->_validate_op_and_value($op_and_value); |
|
158 | 158 | // ok now the jquery dependency expression depends on the input's display strategy. |
159 | - if (! $input->get_display_strategy() instanceof EE_Select_Display_Strategy) { |
|
159 | + if ( ! $input->get_display_strategy() instanceof EE_Select_Display_Strategy) { |
|
160 | 160 | EE_Error::throw_exception_if_debugging( |
161 | 161 | sprintf( |
162 | 162 | esc_html__('Required Validation Strategy can only depend on another input which uses the EE_Select_Display_Strategy, but you specified a field "%1$s" that uses display strategy "%2$s". If you need others, please add support for it! The related input is %3$s', 'event_espresso'), |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | __LINE__ |
170 | 170 | ); |
171 | 171 | } |
172 | - $requirement_value = $input->html_id(true) . ' option[value="' . $value . '"]:selected'; |
|
172 | + $requirement_value = $input->html_id(true).' option[value="'.$value.'"]:selected'; |
|
173 | 173 | } |
174 | 174 | return $requirement_value; |
175 | 175 | } |
@@ -190,7 +190,7 @@ discard block |
||
190 | 190 | $conditions = $this->get_requirement_conditions(); |
191 | 191 | foreach ($conditions as $input_path => $op_and_value) { |
192 | 192 | $input = $this->_input->find_section_from_path($input_path); |
193 | - if (! $input instanceof EE_Form_Input_Base) { |
|
193 | + if ( ! $input instanceof EE_Form_Input_Base) { |
|
194 | 194 | EE_Error::throw_exception_if_debugging( |
195 | 195 | sprintf( |
196 | 196 | esc_html__('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
@@ -203,13 +203,13 @@ discard block |
||
203 | 203 | ); |
204 | 204 | return false; |
205 | 205 | } |
206 | - list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
206 | + list($op, $value) = $this->_validate_op_and_value($op_and_value); |
|
207 | 207 | switch ($op) { |
208 | 208 | case '=': |
209 | 209 | default: |
210 | 210 | $meets_all_requirements = $input->normalized_value() === $value; |
211 | 211 | } |
212 | - if (! $meets_all_requirements) { |
|
212 | + if ( ! $meets_all_requirements) { |
|
213 | 213 | break; |
214 | 214 | } |
215 | 215 | } |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | protected function _validate_op_and_value($op_and_value) |
230 | 230 | { |
231 | - if (! isset($op_and_value[0], $op_and_value[1])) { |
|
231 | + if ( ! isset($op_and_value[0], $op_and_value[1])) { |
|
232 | 232 | EE_Error::throw_exception_if_debugging( |
233 | 233 | sprintf( |
234 | 234 | esc_html__('Required Validation Strategy conditions array\'s value must be an array with two elements: an operator, and a value. It didn\'t. The related input is %1$s', 'event_espresso'), |
@@ -252,6 +252,6 @@ discard block |
||
252 | 252 | __LINE__ |
253 | 253 | ); |
254 | 254 | } |
255 | - return array( $operator, $value ); |
|
255 | + return array($operator, $value); |
|
256 | 256 | } |
257 | 257 | } |
@@ -11,246 +11,246 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Conditionally_Required_Validation_Strategy extends EE_Validation_Strategy_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * Array describing conditions necessary to make the input required. |
|
16 | - * This is used to derive a jquery dependency expression (see http://jqueryvalidation.org/required-method) |
|
17 | - * or jquery callback; and server-side logic to determine if the field is necessary. |
|
18 | - * @var array |
|
19 | - */ |
|
20 | - protected $requirement_conditions; |
|
14 | + /** |
|
15 | + * Array describing conditions necessary to make the input required. |
|
16 | + * This is used to derive a jquery dependency expression (see http://jqueryvalidation.org/required-method) |
|
17 | + * or jquery callback; and server-side logic to determine if the field is necessary. |
|
18 | + * @var array |
|
19 | + */ |
|
20 | + protected $requirement_conditions; |
|
21 | 21 | |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * @param string $validation_error_message |
|
26 | - * @param array $requirement_conditions |
|
27 | - */ |
|
28 | - public function __construct($validation_error_message = null, $requirement_conditions = array()) |
|
29 | - { |
|
30 | - if (! $validation_error_message) { |
|
31 | - $validation_error_message = esc_html__("This field is required.", "event_espresso"); |
|
32 | - } |
|
33 | - $this->set_requirement_conditions($requirement_conditions); |
|
34 | - parent::__construct($validation_error_message); |
|
35 | - } |
|
24 | + /** |
|
25 | + * @param string $validation_error_message |
|
26 | + * @param array $requirement_conditions |
|
27 | + */ |
|
28 | + public function __construct($validation_error_message = null, $requirement_conditions = array()) |
|
29 | + { |
|
30 | + if (! $validation_error_message) { |
|
31 | + $validation_error_message = esc_html__("This field is required.", "event_espresso"); |
|
32 | + } |
|
33 | + $this->set_requirement_conditions($requirement_conditions); |
|
34 | + parent::__construct($validation_error_message); |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * just checks the field isn't blank, provided the requirement conditions |
|
41 | - * indicate this input is still required |
|
42 | - * |
|
43 | - * @param $normalized_value |
|
44 | - * @return bool |
|
45 | - * @throws \EE_Error |
|
46 | - * @throws \EE_Validation_Error |
|
47 | - */ |
|
48 | - public function validate($normalized_value) |
|
49 | - { |
|
50 | - if ( |
|
51 | - ( |
|
52 | - $normalized_value === '' |
|
53 | - || $normalized_value === null |
|
54 | - || $normalized_value === array() |
|
55 | - ) |
|
56 | - && $this->_input_is_required_server_side() |
|
57 | - ) { |
|
58 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
59 | - } else { |
|
60 | - return true; |
|
61 | - } |
|
62 | - } |
|
39 | + /** |
|
40 | + * just checks the field isn't blank, provided the requirement conditions |
|
41 | + * indicate this input is still required |
|
42 | + * |
|
43 | + * @param $normalized_value |
|
44 | + * @return bool |
|
45 | + * @throws \EE_Error |
|
46 | + * @throws \EE_Validation_Error |
|
47 | + */ |
|
48 | + public function validate($normalized_value) |
|
49 | + { |
|
50 | + if ( |
|
51 | + ( |
|
52 | + $normalized_value === '' |
|
53 | + || $normalized_value === null |
|
54 | + || $normalized_value === array() |
|
55 | + ) |
|
56 | + && $this->_input_is_required_server_side() |
|
57 | + ) { |
|
58 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'required'); |
|
59 | + } else { |
|
60 | + return true; |
|
61 | + } |
|
62 | + } |
|
63 | 63 | |
64 | 64 | |
65 | 65 | |
66 | - /** |
|
67 | - * @return array |
|
68 | - * @throws \EE_Error |
|
69 | - */ |
|
70 | - public function get_jquery_validation_rule_array() |
|
71 | - { |
|
72 | - return array( |
|
73 | - 'required' => $this->_get_jquery_requirement_value(), |
|
74 | - 'messages' => array( |
|
75 | - 'required' => $this->get_validation_error_message() |
|
76 | - ) |
|
77 | - ); |
|
78 | - } |
|
66 | + /** |
|
67 | + * @return array |
|
68 | + * @throws \EE_Error |
|
69 | + */ |
|
70 | + public function get_jquery_validation_rule_array() |
|
71 | + { |
|
72 | + return array( |
|
73 | + 'required' => $this->_get_jquery_requirement_value(), |
|
74 | + 'messages' => array( |
|
75 | + 'required' => $this->get_validation_error_message() |
|
76 | + ) |
|
77 | + ); |
|
78 | + } |
|
79 | 79 | |
80 | - /** |
|
81 | - * Sets the "required conditions". This should be an array, its top-level key |
|
82 | - * is the name of a field, its value is an array. This 2nd level array has two items: |
|
83 | - * the first is the operator (for now only '=' is accepted), and teh 2nd argument is the |
|
84 | - * the value the field should be in order to make the field required. |
|
85 | - * Eg array( 'payment_type' => array( '=', 'credit_card' ). |
|
86 | - * |
|
87 | - * @param array $requirement_conditions |
|
88 | - */ |
|
89 | - public function set_requirement_conditions($requirement_conditions) |
|
90 | - { |
|
91 | - $this->requirement_conditions = (array) $requirement_conditions; |
|
92 | - } |
|
80 | + /** |
|
81 | + * Sets the "required conditions". This should be an array, its top-level key |
|
82 | + * is the name of a field, its value is an array. This 2nd level array has two items: |
|
83 | + * the first is the operator (for now only '=' is accepted), and teh 2nd argument is the |
|
84 | + * the value the field should be in order to make the field required. |
|
85 | + * Eg array( 'payment_type' => array( '=', 'credit_card' ). |
|
86 | + * |
|
87 | + * @param array $requirement_conditions |
|
88 | + */ |
|
89 | + public function set_requirement_conditions($requirement_conditions) |
|
90 | + { |
|
91 | + $this->requirement_conditions = (array) $requirement_conditions; |
|
92 | + } |
|
93 | 93 | |
94 | - /** |
|
95 | - * Gets the array that describes when the related input should be required. |
|
96 | - * see set_requirement_conditions for a description of how it should be formatted |
|
97 | - * @return array |
|
98 | - */ |
|
99 | - public function get_requirement_conditions() |
|
100 | - { |
|
101 | - return $this->requirement_conditions; |
|
102 | - } |
|
94 | + /** |
|
95 | + * Gets the array that describes when the related input should be required. |
|
96 | + * see set_requirement_conditions for a description of how it should be formatted |
|
97 | + * @return array |
|
98 | + */ |
|
99 | + public function get_requirement_conditions() |
|
100 | + { |
|
101 | + return $this->requirement_conditions; |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | 105 | |
106 | - /** |
|
107 | - * gets jQuery dependency expression used for client-side validation |
|
108 | - * Its possible this could also return a javascript callback used for determining |
|
109 | - * if the input is required or not. That is not yet implemented, however. |
|
110 | - * |
|
111 | - * @return string see http://jqueryvalidation.org/required-method for format |
|
112 | - * @throws \EE_Error |
|
113 | - */ |
|
114 | - protected function _get_jquery_requirement_value() |
|
115 | - { |
|
116 | - $requirement_value = ''; |
|
117 | - $conditions = $this->get_requirement_conditions(); |
|
118 | - if (! is_array($conditions)) { |
|
119 | - EE_Error::throw_exception_if_debugging( |
|
120 | - sprintf( |
|
121 | - esc_html__('Input requirement conditions must be an array. You provided %1$s', 'event_espresso'), |
|
122 | - $this->_input->name() |
|
123 | - ), |
|
124 | - __FILE__, |
|
125 | - __FUNCTION__, |
|
126 | - __LINE__ |
|
127 | - ); |
|
128 | - return true; |
|
129 | - } |
|
130 | - if (count($conditions) > 1) { |
|
131 | - EE_Error::throw_exception_if_debugging( |
|
132 | - sprintf( |
|
133 | - esc_html__('Required Validation Strategy does not yet support multiple conditions. You should add it! The related input is %1$s', 'event_espresso'), |
|
134 | - $this->_input->name() |
|
135 | - ), |
|
136 | - __FILE__, |
|
137 | - __FUNCTION__, |
|
138 | - __LINE__ |
|
139 | - ); |
|
140 | - } |
|
141 | - foreach ($conditions as $input_path => $op_and_value) { |
|
142 | - $input = $this->_input->find_section_from_path($input_path); |
|
143 | - if (! $input instanceof EE_Form_Input_Base) { |
|
144 | - EE_Error::throw_exception_if_debugging( |
|
145 | - sprintf( |
|
146 | - esc_html__('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
|
147 | - $this->_input->name(), |
|
148 | - $input_path |
|
149 | - ), |
|
150 | - __FILE__, |
|
151 | - __FUNCTION__, |
|
152 | - __LINE__ |
|
153 | - ); |
|
154 | - return false; |
|
155 | - } |
|
156 | - list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
157 | - // ok now the jquery dependency expression depends on the input's display strategy. |
|
158 | - if (! $input->get_display_strategy() instanceof EE_Select_Display_Strategy) { |
|
159 | - EE_Error::throw_exception_if_debugging( |
|
160 | - sprintf( |
|
161 | - esc_html__('Required Validation Strategy can only depend on another input which uses the EE_Select_Display_Strategy, but you specified a field "%1$s" that uses display strategy "%2$s". If you need others, please add support for it! The related input is %3$s', 'event_espresso'), |
|
162 | - $input->name(), |
|
163 | - get_class($input->get_display_strategy()), |
|
164 | - $this->_input->name() |
|
165 | - ), |
|
166 | - __FILE__, |
|
167 | - __FUNCTION__, |
|
168 | - __LINE__ |
|
169 | - ); |
|
170 | - } |
|
171 | - $requirement_value = $input->html_id(true) . ' option[value="' . $value . '"]:selected'; |
|
172 | - } |
|
173 | - return $requirement_value; |
|
174 | - } |
|
106 | + /** |
|
107 | + * gets jQuery dependency expression used for client-side validation |
|
108 | + * Its possible this could also return a javascript callback used for determining |
|
109 | + * if the input is required or not. That is not yet implemented, however. |
|
110 | + * |
|
111 | + * @return string see http://jqueryvalidation.org/required-method for format |
|
112 | + * @throws \EE_Error |
|
113 | + */ |
|
114 | + protected function _get_jquery_requirement_value() |
|
115 | + { |
|
116 | + $requirement_value = ''; |
|
117 | + $conditions = $this->get_requirement_conditions(); |
|
118 | + if (! is_array($conditions)) { |
|
119 | + EE_Error::throw_exception_if_debugging( |
|
120 | + sprintf( |
|
121 | + esc_html__('Input requirement conditions must be an array. You provided %1$s', 'event_espresso'), |
|
122 | + $this->_input->name() |
|
123 | + ), |
|
124 | + __FILE__, |
|
125 | + __FUNCTION__, |
|
126 | + __LINE__ |
|
127 | + ); |
|
128 | + return true; |
|
129 | + } |
|
130 | + if (count($conditions) > 1) { |
|
131 | + EE_Error::throw_exception_if_debugging( |
|
132 | + sprintf( |
|
133 | + esc_html__('Required Validation Strategy does not yet support multiple conditions. You should add it! The related input is %1$s', 'event_espresso'), |
|
134 | + $this->_input->name() |
|
135 | + ), |
|
136 | + __FILE__, |
|
137 | + __FUNCTION__, |
|
138 | + __LINE__ |
|
139 | + ); |
|
140 | + } |
|
141 | + foreach ($conditions as $input_path => $op_and_value) { |
|
142 | + $input = $this->_input->find_section_from_path($input_path); |
|
143 | + if (! $input instanceof EE_Form_Input_Base) { |
|
144 | + EE_Error::throw_exception_if_debugging( |
|
145 | + sprintf( |
|
146 | + esc_html__('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
|
147 | + $this->_input->name(), |
|
148 | + $input_path |
|
149 | + ), |
|
150 | + __FILE__, |
|
151 | + __FUNCTION__, |
|
152 | + __LINE__ |
|
153 | + ); |
|
154 | + return false; |
|
155 | + } |
|
156 | + list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
157 | + // ok now the jquery dependency expression depends on the input's display strategy. |
|
158 | + if (! $input->get_display_strategy() instanceof EE_Select_Display_Strategy) { |
|
159 | + EE_Error::throw_exception_if_debugging( |
|
160 | + sprintf( |
|
161 | + esc_html__('Required Validation Strategy can only depend on another input which uses the EE_Select_Display_Strategy, but you specified a field "%1$s" that uses display strategy "%2$s". If you need others, please add support for it! The related input is %3$s', 'event_espresso'), |
|
162 | + $input->name(), |
|
163 | + get_class($input->get_display_strategy()), |
|
164 | + $this->_input->name() |
|
165 | + ), |
|
166 | + __FILE__, |
|
167 | + __FUNCTION__, |
|
168 | + __LINE__ |
|
169 | + ); |
|
170 | + } |
|
171 | + $requirement_value = $input->html_id(true) . ' option[value="' . $value . '"]:selected'; |
|
172 | + } |
|
173 | + return $requirement_value; |
|
174 | + } |
|
175 | 175 | |
176 | 176 | |
177 | 177 | |
178 | - /** |
|
179 | - * Returns whether or not this input is required based on the _requirement_conditions |
|
180 | - * (not whether or not the input passes validation. That's for the validate method |
|
181 | - * to decide) |
|
182 | - * |
|
183 | - * @return boolean |
|
184 | - * @throws \EE_Error |
|
185 | - */ |
|
186 | - protected function _input_is_required_server_side() |
|
187 | - { |
|
188 | - $meets_all_requirements = true; |
|
189 | - $conditions = $this->get_requirement_conditions(); |
|
190 | - foreach ($conditions as $input_path => $op_and_value) { |
|
191 | - $input = $this->_input->find_section_from_path($input_path); |
|
192 | - if (! $input instanceof EE_Form_Input_Base) { |
|
193 | - EE_Error::throw_exception_if_debugging( |
|
194 | - sprintf( |
|
195 | - esc_html__('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
|
196 | - $this->_input->name(), |
|
197 | - $input_path |
|
198 | - ), |
|
199 | - __FILE__, |
|
200 | - __FUNCTION__, |
|
201 | - __LINE__ |
|
202 | - ); |
|
203 | - return false; |
|
204 | - } |
|
205 | - list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
206 | - switch ($op) { |
|
207 | - case '=': |
|
208 | - default: |
|
209 | - $meets_all_requirements = $input->normalized_value() === $value; |
|
210 | - } |
|
211 | - if (! $meets_all_requirements) { |
|
212 | - break; |
|
213 | - } |
|
214 | - } |
|
215 | - return $meets_all_requirements; |
|
216 | - } |
|
178 | + /** |
|
179 | + * Returns whether or not this input is required based on the _requirement_conditions |
|
180 | + * (not whether or not the input passes validation. That's for the validate method |
|
181 | + * to decide) |
|
182 | + * |
|
183 | + * @return boolean |
|
184 | + * @throws \EE_Error |
|
185 | + */ |
|
186 | + protected function _input_is_required_server_side() |
|
187 | + { |
|
188 | + $meets_all_requirements = true; |
|
189 | + $conditions = $this->get_requirement_conditions(); |
|
190 | + foreach ($conditions as $input_path => $op_and_value) { |
|
191 | + $input = $this->_input->find_section_from_path($input_path); |
|
192 | + if (! $input instanceof EE_Form_Input_Base) { |
|
193 | + EE_Error::throw_exception_if_debugging( |
|
194 | + sprintf( |
|
195 | + esc_html__('Error encountered while setting requirement condition for input %1$s. The path %2$s does not correspond to a valid input', 'event_espresso'), |
|
196 | + $this->_input->name(), |
|
197 | + $input_path |
|
198 | + ), |
|
199 | + __FILE__, |
|
200 | + __FUNCTION__, |
|
201 | + __LINE__ |
|
202 | + ); |
|
203 | + return false; |
|
204 | + } |
|
205 | + list( $op, $value ) = $this->_validate_op_and_value($op_and_value); |
|
206 | + switch ($op) { |
|
207 | + case '=': |
|
208 | + default: |
|
209 | + $meets_all_requirements = $input->normalized_value() === $value; |
|
210 | + } |
|
211 | + if (! $meets_all_requirements) { |
|
212 | + break; |
|
213 | + } |
|
214 | + } |
|
215 | + return $meets_all_requirements; |
|
216 | + } |
|
217 | 217 | |
218 | 218 | |
219 | 219 | |
220 | - /** |
|
221 | - * Verifies this is an array with keys 0 and 1, where key 0 is a usable |
|
222 | - * operator (initially just '=') and key 1 is something that can be cast to a string |
|
223 | - * |
|
224 | - * @param array $op_and_value |
|
225 | - * @return array |
|
226 | - * @throws \EE_Error |
|
227 | - */ |
|
228 | - protected function _validate_op_and_value($op_and_value) |
|
229 | - { |
|
230 | - if (! isset($op_and_value[0], $op_and_value[1])) { |
|
231 | - EE_Error::throw_exception_if_debugging( |
|
232 | - sprintf( |
|
233 | - esc_html__('Required Validation Strategy conditions array\'s value must be an array with two elements: an operator, and a value. It didn\'t. The related input is %1$s', 'event_espresso'), |
|
234 | - $this->_input->name() |
|
235 | - ), |
|
236 | - __FILE__, |
|
237 | - __FUNCTION__, |
|
238 | - __LINE__ |
|
239 | - ); |
|
240 | - } |
|
241 | - $operator = $op_and_value[0]; |
|
242 | - $value = (string) $op_and_value[1]; |
|
243 | - if ($operator !== '=') { |
|
244 | - EE_Error::throw_exception_if_debugging( |
|
245 | - sprintf( |
|
246 | - esc_html__('Required Validation Strategy conditions can currently only use the equals operator. If you need others, please add support for it! The related input is %1$s', 'event_espresso'), |
|
247 | - $this->_input->name() |
|
248 | - ), |
|
249 | - __FILE__, |
|
250 | - __FUNCTION__, |
|
251 | - __LINE__ |
|
252 | - ); |
|
253 | - } |
|
254 | - return array( $operator, $value ); |
|
255 | - } |
|
220 | + /** |
|
221 | + * Verifies this is an array with keys 0 and 1, where key 0 is a usable |
|
222 | + * operator (initially just '=') and key 1 is something that can be cast to a string |
|
223 | + * |
|
224 | + * @param array $op_and_value |
|
225 | + * @return array |
|
226 | + * @throws \EE_Error |
|
227 | + */ |
|
228 | + protected function _validate_op_and_value($op_and_value) |
|
229 | + { |
|
230 | + if (! isset($op_and_value[0], $op_and_value[1])) { |
|
231 | + EE_Error::throw_exception_if_debugging( |
|
232 | + sprintf( |
|
233 | + esc_html__('Required Validation Strategy conditions array\'s value must be an array with two elements: an operator, and a value. It didn\'t. The related input is %1$s', 'event_espresso'), |
|
234 | + $this->_input->name() |
|
235 | + ), |
|
236 | + __FILE__, |
|
237 | + __FUNCTION__, |
|
238 | + __LINE__ |
|
239 | + ); |
|
240 | + } |
|
241 | + $operator = $op_and_value[0]; |
|
242 | + $value = (string) $op_and_value[1]; |
|
243 | + if ($operator !== '=') { |
|
244 | + EE_Error::throw_exception_if_debugging( |
|
245 | + sprintf( |
|
246 | + esc_html__('Required Validation Strategy conditions can currently only use the equals operator. If you need others, please add support for it! The related input is %1$s', 'event_espresso'), |
|
247 | + $this->_input->name() |
|
248 | + ), |
|
249 | + __FILE__, |
|
250 | + __FUNCTION__, |
|
251 | + __LINE__ |
|
252 | + ); |
|
253 | + } |
|
254 | + return array( $operator, $value ); |
|
255 | + } |
|
256 | 256 | } |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public function __construct($validation_error_message = null) |
19 | 19 | { |
20 | - if (! $validation_error_message) { |
|
20 | + if ( ! $validation_error_message) { |
|
21 | 21 | $validation_error_message = sprintf(esc_html__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso")); |
22 | 22 | } |
23 | 23 | parent::__construct($validation_error_message); |
@@ -42,6 +42,6 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function get_jquery_validation_rule_array() |
44 | 44 | { |
45 | - return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) ); |
|
45 | + return array('number' => true, 'messages' => array('number' => $this->get_validation_error_message())); |
|
46 | 46 | } |
47 | 47 | } |
@@ -11,36 +11,36 @@ |
||
11 | 11 | */ |
12 | 12 | class EE_Float_Validation_Strategy extends EE_Validation_Strategy_Base |
13 | 13 | { |
14 | - /** |
|
15 | - * @param null $validation_error_message |
|
16 | - */ |
|
17 | - public function __construct($validation_error_message = null) |
|
18 | - { |
|
19 | - if (! $validation_error_message) { |
|
20 | - $validation_error_message = sprintf(esc_html__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso")); |
|
21 | - } |
|
22 | - parent::__construct($validation_error_message); |
|
23 | - } |
|
14 | + /** |
|
15 | + * @param null $validation_error_message |
|
16 | + */ |
|
17 | + public function __construct($validation_error_message = null) |
|
18 | + { |
|
19 | + if (! $validation_error_message) { |
|
20 | + $validation_error_message = sprintf(esc_html__("Only numeric characters, commas, periods, and spaces, please!", "event_espresso")); |
|
21 | + } |
|
22 | + parent::__construct($validation_error_message); |
|
23 | + } |
|
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * |
|
29 | - * @param $normalized_value |
|
30 | - * @return bool |
|
31 | - */ |
|
32 | - public function validate($normalized_value) |
|
33 | - { |
|
34 | - // errors should have been detected by the normalization strategy |
|
35 | - } |
|
27 | + /** |
|
28 | + * |
|
29 | + * @param $normalized_value |
|
30 | + * @return bool |
|
31 | + */ |
|
32 | + public function validate($normalized_value) |
|
33 | + { |
|
34 | + // errors should have been detected by the normalization strategy |
|
35 | + } |
|
36 | 36 | |
37 | 37 | |
38 | 38 | |
39 | - /** |
|
40 | - * @return array |
|
41 | - */ |
|
42 | - public function get_jquery_validation_rule_array() |
|
43 | - { |
|
44 | - return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) ); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @return array |
|
41 | + */ |
|
42 | + public function get_jquery_validation_rule_array() |
|
43 | + { |
|
44 | + return array('number' => true, 'messages' => array( 'number' => $this->get_validation_error_message() ) ); |
|
45 | + } |
|
46 | 46 | } |
@@ -19,7 +19,7 @@ discard block |
||
19 | 19 | */ |
20 | 20 | public function __construct($validation_error_message = null) |
21 | 21 | { |
22 | - if (! $validation_error_message) { |
|
22 | + if ( ! $validation_error_message) { |
|
23 | 23 | $allowedtags = $this->_get_allowed_tags(); |
24 | 24 | $validation_error_message = sprintf(esc_html__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags))); |
25 | 25 | } |
@@ -62,7 +62,7 @@ discard block |
||
62 | 62 | { |
63 | 63 | $allowedtags = $this->_get_allowed_tags(); |
64 | 64 | parent::validate($normalized_value); |
65 | - $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags); |
|
65 | + $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags); |
|
66 | 66 | if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
67 | 67 | throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
68 | 68 | } |
@@ -13,57 +13,57 @@ |
||
13 | 13 | */ |
14 | 14 | class EE_Simple_HTML_Validation_Strategy extends EE_Validation_Strategy_Base |
15 | 15 | { |
16 | - /** |
|
17 | - * @param null $validation_error_message |
|
18 | - */ |
|
19 | - public function __construct($validation_error_message = null) |
|
20 | - { |
|
21 | - if (! $validation_error_message) { |
|
22 | - $allowedtags = $this->_get_allowed_tags(); |
|
23 | - $validation_error_message = sprintf(esc_html__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags))); |
|
24 | - } |
|
25 | - parent::__construct($validation_error_message); |
|
26 | - } |
|
16 | + /** |
|
17 | + * @param null $validation_error_message |
|
18 | + */ |
|
19 | + public function __construct($validation_error_message = null) |
|
20 | + { |
|
21 | + if (! $validation_error_message) { |
|
22 | + $allowedtags = $this->_get_allowed_tags(); |
|
23 | + $validation_error_message = sprintf(esc_html__("Only simple HTML tags are allowed. Eg, %s", "event_espresso"), implode(",", array_keys($allowedtags))); |
|
24 | + } |
|
25 | + parent::__construct($validation_error_message); |
|
26 | + } |
|
27 | 27 | |
28 | 28 | |
29 | 29 | |
30 | - /** |
|
31 | - * get tags allowed |
|
32 | - */ |
|
33 | - protected function _get_allowed_tags() |
|
34 | - { |
|
35 | - return EEH_HTML::get_simple_tags(); |
|
36 | - } |
|
30 | + /** |
|
31 | + * get tags allowed |
|
32 | + */ |
|
33 | + protected function _get_allowed_tags() |
|
34 | + { |
|
35 | + return EEH_HTML::get_simple_tags(); |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * add_more_tags |
|
42 | - * |
|
43 | - * generates and returns a string that lists the top-level HTML tags that are allowable for this input |
|
44 | - * |
|
45 | - * @return string |
|
46 | - */ |
|
47 | - public function get_list_of_allowed_tags() |
|
48 | - { |
|
49 | - $allowed_tags = $this->_get_allowed_tags(); |
|
50 | - ksort($allowed_tags); |
|
51 | - return implode(', ', array_keys($allowed_tags)); |
|
52 | - } |
|
40 | + /** |
|
41 | + * add_more_tags |
|
42 | + * |
|
43 | + * generates and returns a string that lists the top-level HTML tags that are allowable for this input |
|
44 | + * |
|
45 | + * @return string |
|
46 | + */ |
|
47 | + public function get_list_of_allowed_tags() |
|
48 | + { |
|
49 | + $allowed_tags = $this->_get_allowed_tags(); |
|
50 | + ksort($allowed_tags); |
|
51 | + return implode(', ', array_keys($allowed_tags)); |
|
52 | + } |
|
53 | 53 | |
54 | 54 | |
55 | 55 | |
56 | - /** |
|
57 | - * @param $normalized_value |
|
58 | - * @throws \EE_Validation_Error |
|
59 | - */ |
|
60 | - public function validate($normalized_value) |
|
61 | - { |
|
62 | - $allowedtags = $this->_get_allowed_tags(); |
|
63 | - parent::validate($normalized_value); |
|
64 | - $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags); |
|
65 | - if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
66 | - throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
67 | - } |
|
68 | - } |
|
56 | + /** |
|
57 | + * @param $normalized_value |
|
58 | + * @throws \EE_Validation_Error |
|
59 | + */ |
|
60 | + public function validate($normalized_value) |
|
61 | + { |
|
62 | + $allowedtags = $this->_get_allowed_tags(); |
|
63 | + parent::validate($normalized_value); |
|
64 | + $normalized_value_sans_tags = wp_kses("$normalized_value", $allowedtags); |
|
65 | + if (strlen($normalized_value) > strlen($normalized_value_sans_tags)) { |
|
66 | + throw new EE_Validation_Error($this->get_validation_error_message(), 'complex_html_tags'); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
34 | 34 | return (float) $value_to_normalize; |
35 | 35 | } |
36 | - if (! is_string($value_to_normalize)) { |
|
36 | + if ( ! is_string($value_to_normalize)) { |
|
37 | 37 | throw new EE_Validation_Error( |
38 | 38 | sprintf( |
39 | 39 | esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | } |
70 | 70 | // this really shouldn't ever happen because fields with a float normalization strategy |
71 | 71 | // should also have a float validation strategy, but in case it doesn't use the default |
72 | - if (! $validation_error_message) { |
|
72 | + if ( ! $validation_error_message) { |
|
73 | 73 | $default_validation_strategy = new EE_Float_Validation_Strategy(); |
74 | 74 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
75 | 75 | } |
@@ -10,84 +10,84 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Float_Normalization extends EE_Normalization_Strategy_Base |
12 | 12 | { |
13 | - /* |
|
13 | + /* |
|
14 | 14 | * regex pattern that matches for the following: |
15 | 15 | * * optional negative sign |
16 | 16 | * * one or more digits or decimals |
17 | 17 | */ |
18 | - const REGEX = '/^(-?)([\d.]+)$/'; |
|
18 | + const REGEX = '/^(-?)([\d.]+)$/'; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $value_to_normalize |
|
24 | - * @return float |
|
25 | - * @throws \EE_Validation_Error |
|
26 | - */ |
|
27 | - public function normalize($value_to_normalize) |
|
28 | - { |
|
29 | - if ($value_to_normalize === null) { |
|
30 | - return null; |
|
31 | - } |
|
32 | - if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
33 | - return (float) $value_to_normalize; |
|
34 | - } |
|
35 | - if (! is_string($value_to_normalize)) { |
|
36 | - throw new EE_Validation_Error( |
|
37 | - sprintf( |
|
38 | - esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | - print_r($value_to_normalize, true), |
|
40 | - gettype($value_to_normalize) |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - $normalized_value = filter_var( |
|
45 | - $value_to_normalize, |
|
46 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | - FILTER_FLAG_ALLOW_FRACTION |
|
48 | - ); |
|
49 | - if ($normalized_value === '') { |
|
50 | - return null; |
|
51 | - } |
|
52 | - if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
53 | - if (count($matches) === 3) { |
|
54 | - // if first match is the negative sign, |
|
55 | - // then the number needs to be multiplied by -1 to remain negative |
|
56 | - return $matches[1] === '-' |
|
57 | - ? (float) $matches[2] * -1 |
|
58 | - : (float) $matches[2]; |
|
59 | - } |
|
60 | - } |
|
61 | - // find if this input has a float validation strategy |
|
62 | - // in which case, use its message |
|
63 | - $validation_error_message = null; |
|
64 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
65 | - if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
66 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
67 | - } |
|
68 | - } |
|
69 | - // this really shouldn't ever happen because fields with a float normalization strategy |
|
70 | - // should also have a float validation strategy, but in case it doesn't use the default |
|
71 | - if (! $validation_error_message) { |
|
72 | - $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
73 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
74 | - } |
|
75 | - throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
76 | - } |
|
22 | + /** |
|
23 | + * @param string $value_to_normalize |
|
24 | + * @return float |
|
25 | + * @throws \EE_Validation_Error |
|
26 | + */ |
|
27 | + public function normalize($value_to_normalize) |
|
28 | + { |
|
29 | + if ($value_to_normalize === null) { |
|
30 | + return null; |
|
31 | + } |
|
32 | + if (is_float($value_to_normalize) || is_int($value_to_normalize)) { |
|
33 | + return (float) $value_to_normalize; |
|
34 | + } |
|
35 | + if (! is_string($value_to_normalize)) { |
|
36 | + throw new EE_Validation_Error( |
|
37 | + sprintf( |
|
38 | + esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | + print_r($value_to_normalize, true), |
|
40 | + gettype($value_to_normalize) |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + $normalized_value = filter_var( |
|
45 | + $value_to_normalize, |
|
46 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | + FILTER_FLAG_ALLOW_FRACTION |
|
48 | + ); |
|
49 | + if ($normalized_value === '') { |
|
50 | + return null; |
|
51 | + } |
|
52 | + if (preg_match(EE_Float_Normalization::REGEX, $normalized_value, $matches)) { |
|
53 | + if (count($matches) === 3) { |
|
54 | + // if first match is the negative sign, |
|
55 | + // then the number needs to be multiplied by -1 to remain negative |
|
56 | + return $matches[1] === '-' |
|
57 | + ? (float) $matches[2] * -1 |
|
58 | + : (float) $matches[2]; |
|
59 | + } |
|
60 | + } |
|
61 | + // find if this input has a float validation strategy |
|
62 | + // in which case, use its message |
|
63 | + $validation_error_message = null; |
|
64 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
65 | + if ($validation_strategy instanceof EE_Float_Validation_Strategy) { |
|
66 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
67 | + } |
|
68 | + } |
|
69 | + // this really shouldn't ever happen because fields with a float normalization strategy |
|
70 | + // should also have a float validation strategy, but in case it doesn't use the default |
|
71 | + if (! $validation_error_message) { |
|
72 | + $default_validation_strategy = new EE_Float_Validation_Strategy(); |
|
73 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
74 | + } |
|
75 | + throw new EE_Validation_Error($validation_error_message, 'float_only'); |
|
76 | + } |
|
77 | 77 | |
78 | 78 | |
79 | 79 | |
80 | - /** |
|
81 | - * Converts a float into a string |
|
82 | - * |
|
83 | - * @param float $normalized_value |
|
84 | - * @return string |
|
85 | - */ |
|
86 | - public function unnormalize($normalized_value) |
|
87 | - { |
|
88 | - if (empty($normalized_value)) { |
|
89 | - return '0.00'; |
|
90 | - } |
|
91 | - return "{$normalized_value}"; |
|
92 | - } |
|
80 | + /** |
|
81 | + * Converts a float into a string |
|
82 | + * |
|
83 | + * @param float $normalized_value |
|
84 | + * @return string |
|
85 | + */ |
|
86 | + public function unnormalize($normalized_value) |
|
87 | + { |
|
88 | + if (empty($normalized_value)) { |
|
89 | + return '0.00'; |
|
90 | + } |
|
91 | + return "{$normalized_value}"; |
|
92 | + } |
|
93 | 93 | } |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
34 | 34 | return (int) $value_to_normalize; |
35 | 35 | } |
36 | - if (! is_string($value_to_normalize)) { |
|
36 | + if ( ! is_string($value_to_normalize)) { |
|
37 | 37 | throw new EE_Validation_Error( |
38 | 38 | sprintf( |
39 | 39 | esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
@@ -70,7 +70,7 @@ discard block |
||
70 | 70 | } |
71 | 71 | // this really shouldn't ever happen because fields with a int normalization strategy |
72 | 72 | // should also have a int validation strategy, but in case it doesn't use the default |
73 | - if (! $validation_error_message) { |
|
73 | + if ( ! $validation_error_message) { |
|
74 | 74 | $default_validation_strategy = new EE_Int_Validation_Strategy(); |
75 | 75 | $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
76 | 76 | } |
@@ -10,88 +10,88 @@ |
||
10 | 10 | */ |
11 | 11 | class EE_Int_Normalization extends EE_Normalization_Strategy_Base |
12 | 12 | { |
13 | - /* |
|
13 | + /* |
|
14 | 14 | * regex pattern that matches for the following: |
15 | 15 | * * optional negative sign |
16 | 16 | * * one or more digits |
17 | 17 | */ |
18 | - const REGEX = '/^(-?)(\d+)(?:\.0+)?$/'; |
|
18 | + const REGEX = '/^(-?)(\d+)(?:\.0+)?$/'; |
|
19 | 19 | |
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @param string $value_to_normalize |
|
24 | - * @return int|mixed|string |
|
25 | - * @throws \EE_Validation_Error |
|
26 | - */ |
|
27 | - public function normalize($value_to_normalize) |
|
28 | - { |
|
29 | - if ($value_to_normalize === null) { |
|
30 | - return null; |
|
31 | - } |
|
32 | - if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
|
33 | - return (int) $value_to_normalize; |
|
34 | - } |
|
35 | - if (! is_string($value_to_normalize)) { |
|
36 | - throw new EE_Validation_Error( |
|
37 | - sprintf( |
|
38 | - esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | - print_r($value_to_normalize, true), |
|
40 | - gettype($value_to_normalize) |
|
41 | - ) |
|
42 | - ); |
|
43 | - } |
|
44 | - $value_to_normalize = filter_var( |
|
45 | - $value_to_normalize, |
|
46 | - FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | - FILTER_FLAG_ALLOW_FRACTION |
|
48 | - ); |
|
49 | - if ($value_to_normalize === '') { |
|
50 | - return null; |
|
51 | - } |
|
52 | - $matches = array(); |
|
53 | - if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) { |
|
54 | - if (count($matches) === 3) { |
|
55 | - // if first match is the negative sign, |
|
56 | - // then the number needs to be multiplied by -1 to remain negative |
|
57 | - return $matches[1] === '-' |
|
58 | - ? (int) $matches[2] * -1 |
|
59 | - : (int) $matches[2]; |
|
60 | - } |
|
61 | - } |
|
62 | - // find if this input has a int validation strategy |
|
63 | - // in which case, use its message |
|
64 | - $validation_error_message = null; |
|
65 | - foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
66 | - if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
67 | - $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
68 | - } |
|
69 | - } |
|
70 | - // this really shouldn't ever happen because fields with a int normalization strategy |
|
71 | - // should also have a int validation strategy, but in case it doesn't use the default |
|
72 | - if (! $validation_error_message) { |
|
73 | - $default_validation_strategy = new EE_Int_Validation_Strategy(); |
|
74 | - $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
75 | - } |
|
76 | - throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
77 | - } |
|
22 | + /** |
|
23 | + * @param string $value_to_normalize |
|
24 | + * @return int|mixed|string |
|
25 | + * @throws \EE_Validation_Error |
|
26 | + */ |
|
27 | + public function normalize($value_to_normalize) |
|
28 | + { |
|
29 | + if ($value_to_normalize === null) { |
|
30 | + return null; |
|
31 | + } |
|
32 | + if (is_int($value_to_normalize) || is_float($value_to_normalize)) { |
|
33 | + return (int) $value_to_normalize; |
|
34 | + } |
|
35 | + if (! is_string($value_to_normalize)) { |
|
36 | + throw new EE_Validation_Error( |
|
37 | + sprintf( |
|
38 | + esc_html__('The value "%s" must be a string submitted for normalization, it was %s', 'event_espresso'), |
|
39 | + print_r($value_to_normalize, true), |
|
40 | + gettype($value_to_normalize) |
|
41 | + ) |
|
42 | + ); |
|
43 | + } |
|
44 | + $value_to_normalize = filter_var( |
|
45 | + $value_to_normalize, |
|
46 | + FILTER_SANITIZE_NUMBER_FLOAT, |
|
47 | + FILTER_FLAG_ALLOW_FRACTION |
|
48 | + ); |
|
49 | + if ($value_to_normalize === '') { |
|
50 | + return null; |
|
51 | + } |
|
52 | + $matches = array(); |
|
53 | + if (preg_match(EE_Int_Normalization::REGEX, $value_to_normalize, $matches)) { |
|
54 | + if (count($matches) === 3) { |
|
55 | + // if first match is the negative sign, |
|
56 | + // then the number needs to be multiplied by -1 to remain negative |
|
57 | + return $matches[1] === '-' |
|
58 | + ? (int) $matches[2] * -1 |
|
59 | + : (int) $matches[2]; |
|
60 | + } |
|
61 | + } |
|
62 | + // find if this input has a int validation strategy |
|
63 | + // in which case, use its message |
|
64 | + $validation_error_message = null; |
|
65 | + foreach ($this->_input->get_validation_strategies() as $validation_strategy) { |
|
66 | + if ($validation_strategy instanceof EE_Int_Validation_Strategy) { |
|
67 | + $validation_error_message = $validation_strategy->get_validation_error_message(); |
|
68 | + } |
|
69 | + } |
|
70 | + // this really shouldn't ever happen because fields with a int normalization strategy |
|
71 | + // should also have a int validation strategy, but in case it doesn't use the default |
|
72 | + if (! $validation_error_message) { |
|
73 | + $default_validation_strategy = new EE_Int_Validation_Strategy(); |
|
74 | + $validation_error_message = $default_validation_strategy->get_validation_error_message(); |
|
75 | + } |
|
76 | + throw new EE_Validation_Error($validation_error_message, 'numeric_only'); |
|
77 | + } |
|
78 | 78 | |
79 | 79 | |
80 | 80 | |
81 | - /** |
|
82 | - * Converts the int into a string for use in teh html form |
|
83 | - * |
|
84 | - * @param int $normalized_value |
|
85 | - * @return string |
|
86 | - */ |
|
87 | - public function unnormalize($normalized_value) |
|
88 | - { |
|
89 | - if ($normalized_value === null || $normalized_value === '') { |
|
90 | - return ''; |
|
91 | - } |
|
92 | - if (empty($normalized_value)) { |
|
93 | - return '0'; |
|
94 | - } |
|
95 | - return "$normalized_value"; |
|
96 | - } |
|
81 | + /** |
|
82 | + * Converts the int into a string for use in teh html form |
|
83 | + * |
|
84 | + * @param int $normalized_value |
|
85 | + * @return string |
|
86 | + */ |
|
87 | + public function unnormalize($normalized_value) |
|
88 | + { |
|
89 | + if ($normalized_value === null || $normalized_value === '') { |
|
90 | + return ''; |
|
91 | + } |
|
92 | + if (empty($normalized_value)) { |
|
93 | + return '0'; |
|
94 | + } |
|
95 | + return "$normalized_value"; |
|
96 | + } |
|
97 | 97 | } |
@@ -14,17 +14,17 @@ |
||
14 | 14 | */ |
15 | 15 | class EE_Phone_Input extends EE_Text_Input |
16 | 16 | { |
17 | - /** |
|
18 | - * @param array $options |
|
19 | - */ |
|
20 | - public function __construct($options = array()) |
|
21 | - { |
|
22 | - $this->_add_validation_strategy( |
|
23 | - new EE_Text_Validation_Strategy( |
|
24 | - esc_html__('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), |
|
25 | - '~^(([\d]{10})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' |
|
26 | - ) |
|
27 | - ); |
|
28 | - parent::__construct($options); |
|
29 | - } |
|
17 | + /** |
|
18 | + * @param array $options |
|
19 | + */ |
|
20 | + public function __construct($options = array()) |
|
21 | + { |
|
22 | + $this->_add_validation_strategy( |
|
23 | + new EE_Text_Validation_Strategy( |
|
24 | + esc_html__('Please enter a valid phone number. Eg 123-456-7890 or 1234567890', 'event_espresso'), |
|
25 | + '~^(([\d]{10})|(^[\d]{3}-[\d]{3}-[\d]{4}))$~' |
|
26 | + ) |
|
27 | + ); |
|
28 | + parent::__construct($options); |
|
29 | + } |
|
30 | 30 | } |
@@ -74,7 +74,7 @@ discard block |
||
74 | 74 | ); |
75 | 75 | // make sure limit and caps are always set |
76 | 76 | $query_params = array_merge( |
77 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | + array('limit' => 10, 'caps' => EEM_Base::caps_read_admin), |
|
78 | 78 | $query_params |
79 | 79 | ); |
80 | 80 | $this->_value_field_name = EEH_Array::is_set( |
@@ -155,12 +155,12 @@ discard block |
||
155 | 155 | $values_for_options = (array) $value; |
156 | 156 | $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
157 | 157 | $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
158 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
159 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
158 | + $this->_extra_select_columns[] = $value_field->get_qualified_column().' AS '.$this->_value_field_name; |
|
159 | + $this->_extra_select_columns[] = $display_field->get_qualified_column().' AS '.$this->_display_field_name; |
|
160 | 160 | $display_values = $this->_get_model()->get_all_wpdb_results( |
161 | 161 | array( |
162 | 162 | array( |
163 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | + $this->_value_field_name => array('IN', $values_for_options) |
|
164 | 164 | ) |
165 | 165 | ), |
166 | 166 | ARRAY_A, |
@@ -170,9 +170,9 @@ discard block |
||
170 | 170 | if (is_array($select_options)) { |
171 | 171 | foreach ($display_values as $db_rows) { |
172 | 172 | $db_rows = (array) $db_rows; |
173 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | + $select_options[$db_rows[$this->_value_field_name]] = apply_filters( |
|
174 | 174 | 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
175 | - $db_rows[ $this->_display_field_name ], |
|
175 | + $db_rows[$this->_display_field_name], |
|
176 | 176 | $db_rows |
177 | 177 | ); |
178 | 178 | } |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | */ |
189 | 189 | protected function _get_model() |
190 | 190 | { |
191 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | + if ( ! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
192 | 192 | throw new EE_Error( |
193 | 193 | sprintf( |
194 | 194 | esc_html__( |
@@ -16,189 +16,189 @@ |
||
16 | 16 | */ |
17 | 17 | class EE_Select_Ajax_Model_Rest_Input extends EE_Form_Input_With_Options_Base |
18 | 18 | { |
19 | - /** |
|
20 | - * @var string $_model_name |
|
21 | - */ |
|
22 | - protected $_model_name; |
|
19 | + /** |
|
20 | + * @var string $_model_name |
|
21 | + */ |
|
22 | + protected $_model_name; |
|
23 | 23 | |
24 | - /** |
|
25 | - * @var string $_display_field_name |
|
26 | - */ |
|
27 | - protected $_display_field_name; |
|
24 | + /** |
|
25 | + * @var string $_display_field_name |
|
26 | + */ |
|
27 | + protected $_display_field_name; |
|
28 | 28 | |
29 | - /** |
|
30 | - * @var string $_value_field_name |
|
31 | - */ |
|
32 | - protected $_value_field_name; |
|
29 | + /** |
|
30 | + * @var string $_value_field_name |
|
31 | + */ |
|
32 | + protected $_value_field_name; |
|
33 | 33 | |
34 | - /** |
|
35 | - * @var array $_extra_select_columns |
|
36 | - */ |
|
37 | - protected $_extra_select_columns = array(); |
|
34 | + /** |
|
35 | + * @var array $_extra_select_columns |
|
36 | + */ |
|
37 | + protected $_extra_select_columns = array(); |
|
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * @param array $input_settings { |
|
42 | - * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
43 | - * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
44 | - * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
45 | - * the string "where") |
|
46 | - * @type string $value_field_name the name of the model field on this model to |
|
47 | - * be used for the HTML select's option's values |
|
48 | - * @type string $display_field_name the name of the model field on this model |
|
49 | - * to be used for the HTML select's option's display text |
|
50 | - * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
51 | - * } |
|
52 | - * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
53 | - * } |
|
54 | - * @throws EE_Error |
|
55 | - * @throws InvalidArgumentException |
|
56 | - * @throws InvalidDataTypeException |
|
57 | - * @throws InvalidInterfaceException |
|
58 | - */ |
|
59 | - public function __construct($input_settings = array()) |
|
60 | - { |
|
61 | - // needed input settings: |
|
62 | - // select2_args |
|
63 | - $this->_model_name = EEH_Array::is_set( |
|
64 | - $input_settings, |
|
65 | - 'model_name', |
|
66 | - null |
|
67 | - ); |
|
68 | - $model = $this->_get_model(); |
|
69 | - $query_params = EEH_Array::is_set( |
|
70 | - $input_settings, |
|
71 | - 'query_params', |
|
72 | - array() |
|
73 | - ); |
|
74 | - // make sure limit and caps are always set |
|
75 | - $query_params = array_merge( |
|
76 | - array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | - $query_params |
|
78 | - ); |
|
79 | - $this->_value_field_name = EEH_Array::is_set( |
|
80 | - $input_settings, |
|
81 | - 'value_field_name', |
|
82 | - $model->primary_key_name() |
|
83 | - ); |
|
84 | - $this->_display_field_name = EEH_Array::is_set( |
|
85 | - $input_settings, |
|
86 | - 'display_field_name', |
|
87 | - $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
88 | - ); |
|
89 | - $this->_extra_select_columns = EEH_Array::is_set( |
|
90 | - $input_settings, |
|
91 | - 'extra_select_columns', |
|
92 | - array() |
|
93 | - ); |
|
94 | - $this->_add_validation_strategy( |
|
95 | - new EE_Model_Matching_Query_Validation_Strategy( |
|
96 | - '', |
|
97 | - $this->_model_name, |
|
98 | - $query_params, |
|
99 | - $this->_value_field_name |
|
100 | - ) |
|
101 | - ); |
|
102 | - // get resource endpoint |
|
103 | - $rest_controller = LoaderFactory::getLoader()->getNew( |
|
104 | - 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
105 | - ); |
|
106 | - $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
107 | - $default_select2_args = array( |
|
108 | - 'ajax' => array( |
|
109 | - 'url' => $rest_controller->getVersionedLinkTo( |
|
110 | - EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
111 | - ), |
|
112 | - 'dataType' => 'json', |
|
113 | - 'delay' => '250', |
|
114 | - 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
115 | - 'data_interface_args' => array( |
|
116 | - 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
117 | - $query_params, |
|
118 | - $model |
|
119 | - ), |
|
120 | - 'display_field' => $this->_display_field_name, |
|
121 | - 'value_field' => $this->_value_field_name, |
|
122 | - 'nonce' => wp_create_nonce('wp_rest'), |
|
123 | - 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
124 | - ), |
|
125 | - ), |
|
126 | - 'cache' => true, |
|
127 | - 'width' => 'resolve' |
|
128 | - ); |
|
129 | - $select2_args = array_replace_recursive( |
|
130 | - $default_select2_args, |
|
131 | - (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
132 | - ); |
|
133 | - $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
134 | - parent::__construct(array(), $input_settings); |
|
135 | - } |
|
40 | + /** |
|
41 | + * @param array $input_settings { |
|
42 | + * @type string $model_name the name of model to be used for searching, both via the REST API and server-side model queries |
|
43 | + * @type array $query_params default query parameters which will apply to both REST API queries and server-side queries. This should be |
|
44 | + * in the exact format that will be used for server-side model usage (eg use index 0 for where conditions, not |
|
45 | + * the string "where") |
|
46 | + * @type string $value_field_name the name of the model field on this model to |
|
47 | + * be used for the HTML select's option's values |
|
48 | + * @type string $display_field_name the name of the model field on this model |
|
49 | + * to be used for the HTML select's option's display text |
|
50 | + * @type array $select2_args arguments to be passed directly into the select2's JS constructor |
|
51 | + * } |
|
52 | + * And the arguments accepted by EE_Form_Input_With_Options_Base |
|
53 | + * } |
|
54 | + * @throws EE_Error |
|
55 | + * @throws InvalidArgumentException |
|
56 | + * @throws InvalidDataTypeException |
|
57 | + * @throws InvalidInterfaceException |
|
58 | + */ |
|
59 | + public function __construct($input_settings = array()) |
|
60 | + { |
|
61 | + // needed input settings: |
|
62 | + // select2_args |
|
63 | + $this->_model_name = EEH_Array::is_set( |
|
64 | + $input_settings, |
|
65 | + 'model_name', |
|
66 | + null |
|
67 | + ); |
|
68 | + $model = $this->_get_model(); |
|
69 | + $query_params = EEH_Array::is_set( |
|
70 | + $input_settings, |
|
71 | + 'query_params', |
|
72 | + array() |
|
73 | + ); |
|
74 | + // make sure limit and caps are always set |
|
75 | + $query_params = array_merge( |
|
76 | + array( 'limit' => 10, 'caps' => EEM_Base::caps_read_admin ), |
|
77 | + $query_params |
|
78 | + ); |
|
79 | + $this->_value_field_name = EEH_Array::is_set( |
|
80 | + $input_settings, |
|
81 | + 'value_field_name', |
|
82 | + $model->primary_key_name() |
|
83 | + ); |
|
84 | + $this->_display_field_name = EEH_Array::is_set( |
|
85 | + $input_settings, |
|
86 | + 'display_field_name', |
|
87 | + $model->get_a_field_of_type('EE_Text_Field_Base')->get_name() |
|
88 | + ); |
|
89 | + $this->_extra_select_columns = EEH_Array::is_set( |
|
90 | + $input_settings, |
|
91 | + 'extra_select_columns', |
|
92 | + array() |
|
93 | + ); |
|
94 | + $this->_add_validation_strategy( |
|
95 | + new EE_Model_Matching_Query_Validation_Strategy( |
|
96 | + '', |
|
97 | + $this->_model_name, |
|
98 | + $query_params, |
|
99 | + $this->_value_field_name |
|
100 | + ) |
|
101 | + ); |
|
102 | + // get resource endpoint |
|
103 | + $rest_controller = LoaderFactory::getLoader()->getNew( |
|
104 | + 'EventEspresso\core\libraries\rest_api\controllers\model\Read' |
|
105 | + ); |
|
106 | + $rest_controller->setRequestedVersion(EED_Core_Rest_Api::latest_rest_api_version()); |
|
107 | + $default_select2_args = array( |
|
108 | + 'ajax' => array( |
|
109 | + 'url' => $rest_controller->getVersionedLinkTo( |
|
110 | + EEH_Inflector::pluralize_and_lower($this->_model_name) |
|
111 | + ), |
|
112 | + 'dataType' => 'json', |
|
113 | + 'delay' => '250', |
|
114 | + 'data_interface' => 'EE_Select2_REST_API_Interface', |
|
115 | + 'data_interface_args' => array( |
|
116 | + 'default_query_params' => (object) ModelDataTranslator::prepareQueryParamsForRestApi( |
|
117 | + $query_params, |
|
118 | + $model |
|
119 | + ), |
|
120 | + 'display_field' => $this->_display_field_name, |
|
121 | + 'value_field' => $this->_value_field_name, |
|
122 | + 'nonce' => wp_create_nonce('wp_rest'), |
|
123 | + 'locale' => str_replace('_', '-', strtolower(get_locale())) |
|
124 | + ), |
|
125 | + ), |
|
126 | + 'cache' => true, |
|
127 | + 'width' => 'resolve' |
|
128 | + ); |
|
129 | + $select2_args = array_replace_recursive( |
|
130 | + $default_select2_args, |
|
131 | + (array) EEH_Array::is_set($input_settings, 'select2_args', array()) |
|
132 | + ); |
|
133 | + $this->set_display_strategy(new EE_Select2_Display_Strategy($select2_args)); |
|
134 | + parent::__construct(array(), $input_settings); |
|
135 | + } |
|
136 | 136 | |
137 | 137 | |
138 | 138 | |
139 | - /** |
|
140 | - * Before setting the raw value (usually because we're setting the default, |
|
141 | - * or we've received a form submission and this might be re-displayed to the user), |
|
142 | - * sets the options so that the current selections appear on initial display. |
|
143 | - * |
|
144 | - * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
145 | - * for validation, this input's options only affect DISPLAY and NOT validation, |
|
146 | - * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
147 | - * |
|
148 | - * @param mixed $value |
|
149 | - * @return void |
|
150 | - * @throws \EE_Error |
|
151 | - */ |
|
152 | - public function _set_raw_value($value) |
|
153 | - { |
|
154 | - $values_for_options = (array) $value; |
|
155 | - $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
156 | - $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
157 | - $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
158 | - $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
159 | - $display_values = $this->_get_model()->get_all_wpdb_results( |
|
160 | - array( |
|
161 | - array( |
|
162 | - $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | - ) |
|
164 | - ), |
|
165 | - ARRAY_A, |
|
166 | - implode(',', $this->_extra_select_columns) |
|
167 | - ); |
|
168 | - $select_options = array(); |
|
169 | - if (is_array($select_options)) { |
|
170 | - foreach ($display_values as $db_rows) { |
|
171 | - $db_rows = (array) $db_rows; |
|
172 | - $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | - 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
174 | - $db_rows[ $this->_display_field_name ], |
|
175 | - $db_rows |
|
176 | - ); |
|
177 | - } |
|
178 | - } |
|
179 | - $this->set_select_options($select_options); |
|
180 | - parent::_set_raw_value($value); |
|
181 | - } |
|
139 | + /** |
|
140 | + * Before setting the raw value (usually because we're setting the default, |
|
141 | + * or we've received a form submission and this might be re-displayed to the user), |
|
142 | + * sets the options so that the current selections appear on initial display. |
|
143 | + * |
|
144 | + * Note: because this input uses EE_Model_Matching_Query_Validation_Strategy |
|
145 | + * for validation, this input's options only affect DISPLAY and NOT validation, |
|
146 | + * which is why its ok to just assume the provided $value to be in the list of acceptable values |
|
147 | + * |
|
148 | + * @param mixed $value |
|
149 | + * @return void |
|
150 | + * @throws \EE_Error |
|
151 | + */ |
|
152 | + public function _set_raw_value($value) |
|
153 | + { |
|
154 | + $values_for_options = (array) $value; |
|
155 | + $value_field = $this->_get_model()->field_settings_for($this->_value_field_name); |
|
156 | + $display_field = $this->_get_model()->field_settings_for($this->_display_field_name); |
|
157 | + $this->_extra_select_columns[] = $value_field->get_qualified_column() . ' AS ' . $this->_value_field_name; |
|
158 | + $this->_extra_select_columns[] = $display_field->get_qualified_column() . ' AS ' . $this->_display_field_name; |
|
159 | + $display_values = $this->_get_model()->get_all_wpdb_results( |
|
160 | + array( |
|
161 | + array( |
|
162 | + $this->_value_field_name => array( 'IN', $values_for_options ) |
|
163 | + ) |
|
164 | + ), |
|
165 | + ARRAY_A, |
|
166 | + implode(',', $this->_extra_select_columns) |
|
167 | + ); |
|
168 | + $select_options = array(); |
|
169 | + if (is_array($select_options)) { |
|
170 | + foreach ($display_values as $db_rows) { |
|
171 | + $db_rows = (array) $db_rows; |
|
172 | + $select_options[ $db_rows[ $this->_value_field_name ] ] = apply_filters( |
|
173 | + 'FHEE__EE_Select_Ajax_Model_Rest_Input___set_raw_value__select_option_value', |
|
174 | + $db_rows[ $this->_display_field_name ], |
|
175 | + $db_rows |
|
176 | + ); |
|
177 | + } |
|
178 | + } |
|
179 | + $this->set_select_options($select_options); |
|
180 | + parent::_set_raw_value($value); |
|
181 | + } |
|
182 | 182 | |
183 | - /** |
|
184 | - * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
185 | - * @return EEM_Base |
|
186 | - * @throws EE_Error |
|
187 | - */ |
|
188 | - protected function _get_model() |
|
189 | - { |
|
190 | - if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | - throw new EE_Error( |
|
192 | - sprintf( |
|
193 | - esc_html__( |
|
194 | - '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $this->_model_name |
|
198 | - ) |
|
199 | - ); |
|
200 | - } else { |
|
201 | - return EE_Registry::instance()->load_model($this->_model_name); |
|
202 | - } |
|
203 | - } |
|
183 | + /** |
|
184 | + * Returns the model, or throws an exception if the model name provided in constructor doesn't exist |
|
185 | + * @return EEM_Base |
|
186 | + * @throws EE_Error |
|
187 | + */ |
|
188 | + protected function _get_model() |
|
189 | + { |
|
190 | + if (! EE_Registry::instance()->is_model_name($this->_model_name)) { |
|
191 | + throw new EE_Error( |
|
192 | + sprintf( |
|
193 | + esc_html__( |
|
194 | + '%1$s is not a proper model name. Please provide a model name in the "model_name" form input argument', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $this->_model_name |
|
198 | + ) |
|
199 | + ); |
|
200 | + } else { |
|
201 | + return EE_Registry::instance()->load_model($this->_model_name); |
|
202 | + } |
|
203 | + } |
|
204 | 204 | } |
@@ -120,7 +120,7 @@ |
||
120 | 120 | public function _update_config(EE_Config_Base $config_obj = null) |
121 | 121 | { |
122 | 122 | $config_class = $this->config_class(); |
123 | - if (! $config_obj instanceof $config_class) { |
|
123 | + if ( ! $config_obj instanceof $config_class) { |
|
124 | 124 | throw new EE_Error( |
125 | 125 | sprintf( |
126 | 126 | esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
@@ -9,143 +9,143 @@ |
||
9 | 9 | */ |
10 | 10 | abstract class EE_Configurable extends EE_Base |
11 | 11 | { |
12 | - /** |
|
13 | - * @var $_config |
|
14 | - * @type EE_Config_Base |
|
15 | - */ |
|
16 | - protected $_config; |
|
17 | - |
|
18 | - /** |
|
19 | - * @var $_config_section |
|
20 | - * @type string |
|
21 | - */ |
|
22 | - protected $_config_section = ''; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var $_config_class |
|
26 | - * @type string |
|
27 | - */ |
|
28 | - protected $_config_class = ''; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var $_config_name |
|
32 | - * @type string |
|
33 | - */ |
|
34 | - protected $_config_name = ''; |
|
35 | - |
|
36 | - |
|
37 | - /** |
|
38 | - * @param string $config_section |
|
39 | - */ |
|
40 | - public function set_config_section($config_section = '') |
|
41 | - { |
|
42 | - $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @return mixed |
|
48 | - */ |
|
49 | - public function config_section() |
|
50 | - { |
|
51 | - return $this->_config_section; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $config_class |
|
57 | - */ |
|
58 | - public function set_config_class($config_class = '') |
|
59 | - { |
|
60 | - $this->_config_class = $config_class; |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return mixed |
|
66 | - */ |
|
67 | - public function config_class() |
|
68 | - { |
|
69 | - return $this->_config_class; |
|
70 | - } |
|
71 | - |
|
72 | - |
|
73 | - /** |
|
74 | - * @param mixed $config_name |
|
75 | - */ |
|
76 | - public function set_config_name($config_name) |
|
77 | - { |
|
78 | - $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
79 | - } |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * @return mixed |
|
84 | - */ |
|
85 | - public function config_name() |
|
86 | - { |
|
87 | - return $this->_config_name; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - /** |
|
92 | - * set_config |
|
93 | - * this method integrates directly with EE_Config to set up the config object for this class |
|
94 | - * |
|
95 | - * @access protected |
|
96 | - * @param EE_Config_Base $config_obj |
|
97 | - * @return mixed EE_Config_Base | NULL |
|
98 | - */ |
|
99 | - protected function _set_config(EE_Config_Base $config_obj = null) |
|
100 | - { |
|
101 | - return EE_Config::instance()->set_config( |
|
102 | - $this->config_section(), |
|
103 | - $this->config_name(), |
|
104 | - $this->config_class(), |
|
105 | - $config_obj |
|
106 | - ); |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * _update_config |
|
112 | - * this method integrates directly with EE_Config to update an existing config object for this class |
|
113 | - * |
|
114 | - * @access protected |
|
115 | - * @param EE_Config_Base $config_obj |
|
116 | - * @throws \EE_Error |
|
117 | - * @return mixed EE_Config_Base | NULL |
|
118 | - */ |
|
119 | - public function _update_config(EE_Config_Base $config_obj = null) |
|
120 | - { |
|
121 | - $config_class = $this->config_class(); |
|
122 | - if (! $config_obj instanceof $config_class) { |
|
123 | - throw new EE_Error( |
|
124 | - sprintf( |
|
125 | - esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
126 | - print_r($config_obj, true), |
|
127 | - $config_class |
|
128 | - ) |
|
129 | - ); |
|
130 | - } |
|
131 | - return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
132 | - } |
|
133 | - |
|
134 | - |
|
135 | - /** |
|
136 | - * gets the class's config object |
|
137 | - * |
|
138 | - * @return EE_Config_Base |
|
139 | - */ |
|
140 | - public function config() |
|
141 | - { |
|
142 | - if (empty($this->_config)) { |
|
143 | - $this->_config = EE_Config::instance()->get_config( |
|
144 | - $this->config_section(), |
|
145 | - $this->config_name(), |
|
146 | - $this->config_class() |
|
147 | - ); |
|
148 | - } |
|
149 | - return $this->_config; |
|
150 | - } |
|
12 | + /** |
|
13 | + * @var $_config |
|
14 | + * @type EE_Config_Base |
|
15 | + */ |
|
16 | + protected $_config; |
|
17 | + |
|
18 | + /** |
|
19 | + * @var $_config_section |
|
20 | + * @type string |
|
21 | + */ |
|
22 | + protected $_config_section = ''; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var $_config_class |
|
26 | + * @type string |
|
27 | + */ |
|
28 | + protected $_config_class = ''; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var $_config_name |
|
32 | + * @type string |
|
33 | + */ |
|
34 | + protected $_config_name = ''; |
|
35 | + |
|
36 | + |
|
37 | + /** |
|
38 | + * @param string $config_section |
|
39 | + */ |
|
40 | + public function set_config_section($config_section = '') |
|
41 | + { |
|
42 | + $this->_config_section = ! empty($config_section) ? $config_section : 'modules'; |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @return mixed |
|
48 | + */ |
|
49 | + public function config_section() |
|
50 | + { |
|
51 | + return $this->_config_section; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $config_class |
|
57 | + */ |
|
58 | + public function set_config_class($config_class = '') |
|
59 | + { |
|
60 | + $this->_config_class = $config_class; |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return mixed |
|
66 | + */ |
|
67 | + public function config_class() |
|
68 | + { |
|
69 | + return $this->_config_class; |
|
70 | + } |
|
71 | + |
|
72 | + |
|
73 | + /** |
|
74 | + * @param mixed $config_name |
|
75 | + */ |
|
76 | + public function set_config_name($config_name) |
|
77 | + { |
|
78 | + $this->_config_name = ! empty($config_name) ? $config_name : get_called_class(); |
|
79 | + } |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * @return mixed |
|
84 | + */ |
|
85 | + public function config_name() |
|
86 | + { |
|
87 | + return $this->_config_name; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + /** |
|
92 | + * set_config |
|
93 | + * this method integrates directly with EE_Config to set up the config object for this class |
|
94 | + * |
|
95 | + * @access protected |
|
96 | + * @param EE_Config_Base $config_obj |
|
97 | + * @return mixed EE_Config_Base | NULL |
|
98 | + */ |
|
99 | + protected function _set_config(EE_Config_Base $config_obj = null) |
|
100 | + { |
|
101 | + return EE_Config::instance()->set_config( |
|
102 | + $this->config_section(), |
|
103 | + $this->config_name(), |
|
104 | + $this->config_class(), |
|
105 | + $config_obj |
|
106 | + ); |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * _update_config |
|
112 | + * this method integrates directly with EE_Config to update an existing config object for this class |
|
113 | + * |
|
114 | + * @access protected |
|
115 | + * @param EE_Config_Base $config_obj |
|
116 | + * @throws \EE_Error |
|
117 | + * @return mixed EE_Config_Base | NULL |
|
118 | + */ |
|
119 | + public function _update_config(EE_Config_Base $config_obj = null) |
|
120 | + { |
|
121 | + $config_class = $this->config_class(); |
|
122 | + if (! $config_obj instanceof $config_class) { |
|
123 | + throw new EE_Error( |
|
124 | + sprintf( |
|
125 | + esc_html__('The "%1$s" class is not an instance of %2$s.', 'event_espresso'), |
|
126 | + print_r($config_obj, true), |
|
127 | + $config_class |
|
128 | + ) |
|
129 | + ); |
|
130 | + } |
|
131 | + return EE_Config::instance()->update_config($this->config_section(), $this->config_name(), $config_obj); |
|
132 | + } |
|
133 | + |
|
134 | + |
|
135 | + /** |
|
136 | + * gets the class's config object |
|
137 | + * |
|
138 | + * @return EE_Config_Base |
|
139 | + */ |
|
140 | + public function config() |
|
141 | + { |
|
142 | + if (empty($this->_config)) { |
|
143 | + $this->_config = EE_Config::instance()->get_config( |
|
144 | + $this->config_section(), |
|
145 | + $this->config_name(), |
|
146 | + $this->config_class() |
|
147 | + ); |
|
148 | + } |
|
149 | + return $this->_config; |
|
150 | + } |
|
151 | 151 | } |