@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
2 | - exit('No direct script access allowed'); |
|
2 | + exit('No direct script access allowed'); |
|
3 | 3 | } |
4 | 4 | |
5 | 5 | |
@@ -16,237 +16,237 @@ discard block |
||
16 | 16 | { |
17 | 17 | |
18 | 18 | |
19 | - /** |
|
20 | - * @var string $_tag |
|
21 | - */ |
|
22 | - protected $_tag = ''; |
|
19 | + /** |
|
20 | + * @var string $_tag |
|
21 | + */ |
|
22 | + protected $_tag = ''; |
|
23 | 23 | |
24 | 24 | |
25 | 25 | |
26 | 26 | |
27 | 27 | |
28 | - /** |
|
29 | - * returns HTML and javascript related to the displaying of this input |
|
30 | - * |
|
31 | - * @return string |
|
32 | - */ |
|
33 | - abstract public function display(); |
|
28 | + /** |
|
29 | + * returns HTML and javascript related to the displaying of this input |
|
30 | + * |
|
31 | + * @return string |
|
32 | + */ |
|
33 | + abstract public function display(); |
|
34 | 34 | |
35 | 35 | |
36 | 36 | |
37 | - /** |
|
38 | - * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars |
|
39 | - * is already there |
|
40 | - * |
|
41 | - * @param string $string - the string being processed |
|
42 | - * @param string $chars - exact string of characters to remove |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - protected function _remove_chars($string = '', $chars = '-') |
|
46 | - { |
|
47 | - $char_length = strlen($chars) * -1; |
|
48 | - // if last three characters of string is " - ", then remove it |
|
49 | - return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string; |
|
50 | - } |
|
37 | + /** |
|
38 | + * _remove_chars - takes an incoming string, and removes the string $chars from the end of it, but only if $chars |
|
39 | + * is already there |
|
40 | + * |
|
41 | + * @param string $string - the string being processed |
|
42 | + * @param string $chars - exact string of characters to remove |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + protected function _remove_chars($string = '', $chars = '-') |
|
46 | + { |
|
47 | + $char_length = strlen($chars) * -1; |
|
48 | + // if last three characters of string is " - ", then remove it |
|
49 | + return substr($string, $char_length) === $chars ? substr($string, 0, $char_length) : $string; |
|
50 | + } |
|
51 | 51 | |
52 | 52 | |
53 | 53 | |
54 | - /** |
|
55 | - * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not |
|
56 | - * already there |
|
57 | - * |
|
58 | - * @param string $string - the string being processed |
|
59 | - * @param string $chars - exact string of characters to be added to end of string |
|
60 | - * @return string |
|
61 | - */ |
|
62 | - protected function _append_chars($string = '', $chars = '-') |
|
63 | - { |
|
64 | - return $this->_remove_chars($string, $chars) . $chars; |
|
65 | - } |
|
54 | + /** |
|
55 | + * _append_chars - takes an incoming string, and adds the string $chars to the end of it, but only if $chars is not |
|
56 | + * already there |
|
57 | + * |
|
58 | + * @param string $string - the string being processed |
|
59 | + * @param string $chars - exact string of characters to be added to end of string |
|
60 | + * @return string |
|
61 | + */ |
|
62 | + protected function _append_chars($string = '', $chars = '-') |
|
63 | + { |
|
64 | + return $this->_remove_chars($string, $chars) . $chars; |
|
65 | + } |
|
66 | 66 | |
67 | 67 | |
68 | - |
|
69 | - /** |
|
70 | - * Gets the HTML IDs of all the inputs |
|
71 | - * |
|
72 | - * @param bool $add_pound_sign |
|
73 | - * @return array |
|
74 | - */ |
|
75 | - public function get_html_input_ids($add_pound_sign = false) |
|
76 | - { |
|
77 | - return array($this->get_input()->html_id($add_pound_sign)); |
|
78 | - } |
|
79 | - |
|
80 | - |
|
81 | - |
|
82 | - /** |
|
83 | - * Adds js variables for localization to the $other_js_data. These should be put |
|
84 | - * in each form's "other_data" javascript object. |
|
85 | - * |
|
86 | - * @param array $other_js_data |
|
87 | - * @return array |
|
88 | - */ |
|
89 | - public function get_other_js_data($other_js_data = array()) |
|
90 | - { |
|
91 | - return $other_js_data; |
|
92 | - } |
|
93 | - |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style. |
|
98 | - * This should be called during wp_enqueue_scripts |
|
99 | - */ |
|
100 | - public function enqueue_js() |
|
101 | - { |
|
102 | - } |
|
103 | - |
|
104 | - |
|
105 | - |
|
106 | - /** |
|
107 | - * returns string like: '<tag' |
|
108 | - * |
|
109 | - * @param string $tag |
|
110 | - * @return string |
|
111 | - */ |
|
112 | - protected function _opening_tag($tag) |
|
113 | - { |
|
114 | - $this->_tag = $tag; |
|
115 | - return "<{$this->_tag}"; |
|
116 | - } |
|
117 | - |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * returns string like: '</tag> |
|
122 | - * |
|
123 | - * @return string |
|
124 | - */ |
|
125 | - protected function _closing_tag() |
|
126 | - { |
|
127 | - return "</{$this->_tag}>"; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * returns string like: '/>' |
|
134 | - * |
|
135 | - * @return string |
|
136 | - */ |
|
137 | - protected function _close_tag() |
|
138 | - { |
|
139 | - return '/>'; |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * returns an array of standard HTML attributes that get added to nearly all inputs, |
|
146 | - * where string keys represent named attributes like id, class, etc |
|
147 | - * and numeric keys represent single attributes like 'required'. |
|
148 | - * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use |
|
149 | - * it. |
|
150 | - * |
|
151 | - * @return array |
|
152 | - */ |
|
153 | - protected function _standard_attributes_array() |
|
154 | - { |
|
155 | - return array( |
|
156 | - 'name' => $this->_input->html_name(), |
|
157 | - 'id' => $this->_input->html_id(), |
|
158 | - 'class' => $this->_input->html_class(true), |
|
159 | - 0 => array('required', $this->_input->required()), |
|
160 | - 1 => $this->_input->other_html_attributes(), |
|
161 | - 'style' => $this->_input->html_style(), |
|
162 | - ); |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - |
|
167 | - /** |
|
168 | - * sets the attributes using the incoming array |
|
169 | - * and returns a string of all attributes rendered as valid HTML |
|
170 | - * |
|
171 | - * @param array $attributes |
|
172 | - * @return string |
|
173 | - */ |
|
174 | - protected function _attributes_string($attributes = array()) |
|
175 | - { |
|
176 | - $attributes = apply_filters( |
|
177 | - 'FHEE__EE_Display_Strategy_Base__attributes_string__attributes', |
|
178 | - $attributes, |
|
179 | - $this, |
|
180 | - $this->_input |
|
181 | - ); |
|
182 | - $attributes_string = ''; |
|
183 | - foreach ($attributes as $attribute => $value) { |
|
184 | - if (is_numeric($attribute)) { |
|
185 | - $add = true; |
|
186 | - if (is_array($value)) { |
|
187 | - $attribute = isset($value[0]) ? $value[0] : ''; |
|
188 | - $add = isset($value[1]) ? $value[1] : false; |
|
189 | - } else { |
|
190 | - $attribute = $value; |
|
191 | - } |
|
192 | - $attributes_string .= $this->_single_attribute($attribute, $add); |
|
193 | - } else { |
|
194 | - $attributes_string .= $this->_attribute($attribute, $value); |
|
195 | - } |
|
196 | - } |
|
197 | - return $attributes_string; |
|
198 | - } |
|
199 | - |
|
200 | - |
|
201 | - |
|
202 | - /** |
|
203 | - * returns string like: ' attribute="value"' |
|
204 | - * returns an empty string if $value is null |
|
205 | - * |
|
206 | - * @param string $attribute |
|
207 | - * @param string $value |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - protected function _attribute($attribute, $value = '') |
|
211 | - { |
|
212 | - if( $value === null) { |
|
213 | - return ''; |
|
214 | - } |
|
215 | - $value = esc_attr($value); |
|
216 | - return " {$attribute}=\"{$value}\""; |
|
217 | - } |
|
218 | - |
|
219 | - |
|
220 | - |
|
221 | - /** |
|
222 | - * returns string like: ' data-attribute="value"' |
|
223 | - * returns an empty string if $value is null |
|
224 | - * |
|
225 | - * @param string $attribute |
|
226 | - * @param string $value |
|
227 | - * @return string |
|
228 | - */ |
|
229 | - protected function _data_attribute($attribute, $value = '') |
|
230 | - { |
|
231 | - if( $value === null) { |
|
232 | - return ''; |
|
233 | - } |
|
234 | - $value = esc_attr($value); |
|
235 | - return " data-{$attribute}=\"{$value}\""; |
|
236 | - } |
|
237 | - |
|
238 | - |
|
239 | - |
|
240 | - /** |
|
241 | - * returns string like: ' attribute' if $add is true |
|
242 | - * |
|
243 | - * @param string $attribute |
|
244 | - * @param boolean $add |
|
245 | - * @return string |
|
246 | - */ |
|
247 | - protected function _single_attribute($attribute, $add = true) |
|
248 | - { |
|
249 | - return $add ? " {$attribute}" : ''; |
|
250 | - } |
|
68 | + |
|
69 | + /** |
|
70 | + * Gets the HTML IDs of all the inputs |
|
71 | + * |
|
72 | + * @param bool $add_pound_sign |
|
73 | + * @return array |
|
74 | + */ |
|
75 | + public function get_html_input_ids($add_pound_sign = false) |
|
76 | + { |
|
77 | + return array($this->get_input()->html_id($add_pound_sign)); |
|
78 | + } |
|
79 | + |
|
80 | + |
|
81 | + |
|
82 | + /** |
|
83 | + * Adds js variables for localization to the $other_js_data. These should be put |
|
84 | + * in each form's "other_data" javascript object. |
|
85 | + * |
|
86 | + * @param array $other_js_data |
|
87 | + * @return array |
|
88 | + */ |
|
89 | + public function get_other_js_data($other_js_data = array()) |
|
90 | + { |
|
91 | + return $other_js_data; |
|
92 | + } |
|
93 | + |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * Opportunity for this display strategy to call wp_enqueue_script and wp_enqueue_style. |
|
98 | + * This should be called during wp_enqueue_scripts |
|
99 | + */ |
|
100 | + public function enqueue_js() |
|
101 | + { |
|
102 | + } |
|
103 | + |
|
104 | + |
|
105 | + |
|
106 | + /** |
|
107 | + * returns string like: '<tag' |
|
108 | + * |
|
109 | + * @param string $tag |
|
110 | + * @return string |
|
111 | + */ |
|
112 | + protected function _opening_tag($tag) |
|
113 | + { |
|
114 | + $this->_tag = $tag; |
|
115 | + return "<{$this->_tag}"; |
|
116 | + } |
|
117 | + |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * returns string like: '</tag> |
|
122 | + * |
|
123 | + * @return string |
|
124 | + */ |
|
125 | + protected function _closing_tag() |
|
126 | + { |
|
127 | + return "</{$this->_tag}>"; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * returns string like: '/>' |
|
134 | + * |
|
135 | + * @return string |
|
136 | + */ |
|
137 | + protected function _close_tag() |
|
138 | + { |
|
139 | + return '/>'; |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * returns an array of standard HTML attributes that get added to nearly all inputs, |
|
146 | + * where string keys represent named attributes like id, class, etc |
|
147 | + * and numeric keys represent single attributes like 'required'. |
|
148 | + * Note: this does not include "value" because many inputs (like dropdowns, textareas, and checkboxes) don't use |
|
149 | + * it. |
|
150 | + * |
|
151 | + * @return array |
|
152 | + */ |
|
153 | + protected function _standard_attributes_array() |
|
154 | + { |
|
155 | + return array( |
|
156 | + 'name' => $this->_input->html_name(), |
|
157 | + 'id' => $this->_input->html_id(), |
|
158 | + 'class' => $this->_input->html_class(true), |
|
159 | + 0 => array('required', $this->_input->required()), |
|
160 | + 1 => $this->_input->other_html_attributes(), |
|
161 | + 'style' => $this->_input->html_style(), |
|
162 | + ); |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + |
|
167 | + /** |
|
168 | + * sets the attributes using the incoming array |
|
169 | + * and returns a string of all attributes rendered as valid HTML |
|
170 | + * |
|
171 | + * @param array $attributes |
|
172 | + * @return string |
|
173 | + */ |
|
174 | + protected function _attributes_string($attributes = array()) |
|
175 | + { |
|
176 | + $attributes = apply_filters( |
|
177 | + 'FHEE__EE_Display_Strategy_Base__attributes_string__attributes', |
|
178 | + $attributes, |
|
179 | + $this, |
|
180 | + $this->_input |
|
181 | + ); |
|
182 | + $attributes_string = ''; |
|
183 | + foreach ($attributes as $attribute => $value) { |
|
184 | + if (is_numeric($attribute)) { |
|
185 | + $add = true; |
|
186 | + if (is_array($value)) { |
|
187 | + $attribute = isset($value[0]) ? $value[0] : ''; |
|
188 | + $add = isset($value[1]) ? $value[1] : false; |
|
189 | + } else { |
|
190 | + $attribute = $value; |
|
191 | + } |
|
192 | + $attributes_string .= $this->_single_attribute($attribute, $add); |
|
193 | + } else { |
|
194 | + $attributes_string .= $this->_attribute($attribute, $value); |
|
195 | + } |
|
196 | + } |
|
197 | + return $attributes_string; |
|
198 | + } |
|
199 | + |
|
200 | + |
|
201 | + |
|
202 | + /** |
|
203 | + * returns string like: ' attribute="value"' |
|
204 | + * returns an empty string if $value is null |
|
205 | + * |
|
206 | + * @param string $attribute |
|
207 | + * @param string $value |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + protected function _attribute($attribute, $value = '') |
|
211 | + { |
|
212 | + if( $value === null) { |
|
213 | + return ''; |
|
214 | + } |
|
215 | + $value = esc_attr($value); |
|
216 | + return " {$attribute}=\"{$value}\""; |
|
217 | + } |
|
218 | + |
|
219 | + |
|
220 | + |
|
221 | + /** |
|
222 | + * returns string like: ' data-attribute="value"' |
|
223 | + * returns an empty string if $value is null |
|
224 | + * |
|
225 | + * @param string $attribute |
|
226 | + * @param string $value |
|
227 | + * @return string |
|
228 | + */ |
|
229 | + protected function _data_attribute($attribute, $value = '') |
|
230 | + { |
|
231 | + if( $value === null) { |
|
232 | + return ''; |
|
233 | + } |
|
234 | + $value = esc_attr($value); |
|
235 | + return " data-{$attribute}=\"{$value}\""; |
|
236 | + } |
|
237 | + |
|
238 | + |
|
239 | + |
|
240 | + /** |
|
241 | + * returns string like: ' attribute' if $add is true |
|
242 | + * |
|
243 | + * @param string $attribute |
|
244 | + * @param boolean $add |
|
245 | + * @return string |
|
246 | + */ |
|
247 | + protected function _single_attribute($attribute, $add = true) |
|
248 | + { |
|
249 | + return $add ? " {$attribute}" : ''; |
|
250 | + } |
|
251 | 251 | |
252 | 252 | } |
253 | 253 | \ No newline at end of file |
@@ -1,4 +1,4 @@ discard block |
||
1 | -<?php if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
1 | +<?php if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
2 | 2 | exit('No direct script access allowed'); |
3 | 3 | } |
4 | 4 | |
@@ -61,7 +61,7 @@ discard block |
||
61 | 61 | */ |
62 | 62 | protected function _append_chars($string = '', $chars = '-') |
63 | 63 | { |
64 | - return $this->_remove_chars($string, $chars) . $chars; |
|
64 | + return $this->_remove_chars($string, $chars).$chars; |
|
65 | 65 | } |
66 | 66 | |
67 | 67 | |
@@ -209,7 +209,7 @@ discard block |
||
209 | 209 | */ |
210 | 210 | protected function _attribute($attribute, $value = '') |
211 | 211 | { |
212 | - if( $value === null) { |
|
212 | + if ($value === null) { |
|
213 | 213 | return ''; |
214 | 214 | } |
215 | 215 | $value = esc_attr($value); |
@@ -228,7 +228,7 @@ discard block |
||
228 | 228 | */ |
229 | 229 | protected function _data_attribute($attribute, $value = '') |
230 | 230 | { |
231 | - if( $value === null) { |
|
231 | + if ($value === null) { |
|
232 | 232 | return ''; |
233 | 233 | } |
234 | 234 | $value = esc_attr($value); |
@@ -12,32 +12,32 @@ |
||
12 | 12 | class EE_Button_Display_Strategy extends EE_Display_Strategy_Base |
13 | 13 | { |
14 | 14 | |
15 | - /** |
|
16 | - * @return string of html to display the input |
|
17 | - */ |
|
18 | - public function display() |
|
19 | - { |
|
20 | - $default_value = $this->_input->get_default(); |
|
21 | - if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
22 | - $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
23 | - } |
|
24 | - $html = $this->_opening_tag('button'); |
|
25 | - $html .= $this->_attributes_string( |
|
26 | - array_merge( |
|
27 | - $this->_standard_attributes_array(), |
|
28 | - array( |
|
29 | - 'value' => $default_value, |
|
30 | - ) |
|
31 | - ) |
|
32 | - ); |
|
33 | - if ($this->_input instanceof EE_Button_Input) { |
|
34 | - $button_content = $this->_input->button_content(); |
|
35 | - } else { |
|
36 | - $button_content = $this->_input->get_default(); |
|
37 | - } |
|
38 | - $html .= '>'; |
|
39 | - $html .= $button_content; |
|
40 | - $html .= $this->_closing_tag(); |
|
41 | - return $html; |
|
42 | - } |
|
15 | + /** |
|
16 | + * @return string of html to display the input |
|
17 | + */ |
|
18 | + public function display() |
|
19 | + { |
|
20 | + $default_value = $this->_input->get_default(); |
|
21 | + if ($this->_input->get_normalization_strategy() instanceof EE_Normalization_Strategy_Base) { |
|
22 | + $default_value = $this->_input->get_normalization_strategy()->unnormalize($default_value); |
|
23 | + } |
|
24 | + $html = $this->_opening_tag('button'); |
|
25 | + $html .= $this->_attributes_string( |
|
26 | + array_merge( |
|
27 | + $this->_standard_attributes_array(), |
|
28 | + array( |
|
29 | + 'value' => $default_value, |
|
30 | + ) |
|
31 | + ) |
|
32 | + ); |
|
33 | + if ($this->_input instanceof EE_Button_Input) { |
|
34 | + $button_content = $this->_input->button_content(); |
|
35 | + } else { |
|
36 | + $button_content = $this->_input->get_default(); |
|
37 | + } |
|
38 | + $html .= '>'; |
|
39 | + $html .= $button_content; |
|
40 | + $html .= $this->_closing_tag(); |
|
41 | + return $html; |
|
42 | + } |
|
43 | 43 | } |
@@ -10,17 +10,17 @@ discard block |
||
10 | 10 | */ |
11 | 11 | class EE_Button_Input extends EE_Form_Input_Base{ |
12 | 12 | |
13 | - /** |
|
14 | - * @var string of HTML to put between the button tags |
|
15 | - */ |
|
16 | - protected $_button_content; |
|
13 | + /** |
|
14 | + * @var string of HTML to put between the button tags |
|
15 | + */ |
|
16 | + protected $_button_content; |
|
17 | 17 | /** |
18 | 18 | * @param array $options |
19 | 19 | */ |
20 | 20 | public function __construct($options = array()){ |
21 | - if( empty($options['button_content'])) { |
|
22 | - $options['button_content'] = esc_html__('Button', 'event_espresso'); |
|
23 | - } |
|
21 | + if( empty($options['button_content'])) { |
|
22 | + $options['button_content'] = esc_html__('Button', 'event_espresso'); |
|
23 | + } |
|
24 | 24 | $this->_set_display_strategy(new EE_Button_Display_Strategy()); |
25 | 25 | $this->_set_normalization_strategy(new EE_Text_Normalization()); |
26 | 26 | $this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy() ); |
@@ -29,22 +29,22 @@ discard block |
||
29 | 29 | |
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * Sets the button content |
|
34 | - * @see EE_Button_Input::$_button_content |
|
35 | - * @param string $new_content |
|
36 | - */ |
|
32 | + /** |
|
33 | + * Sets the button content |
|
34 | + * @see EE_Button_Input::$_button_content |
|
35 | + * @param string $new_content |
|
36 | + */ |
|
37 | 37 | public function set_button_content($new_content) |
38 | - { |
|
39 | - $this->_button_content = $new_content; |
|
40 | - } |
|
38 | + { |
|
39 | + $this->_button_content = $new_content; |
|
40 | + } |
|
41 | 41 | |
42 | - /** |
|
43 | - * Gets the button content |
|
44 | - * @return string |
|
45 | - */ |
|
42 | + /** |
|
43 | + * Gets the button content |
|
44 | + * @return string |
|
45 | + */ |
|
46 | 46 | public function button_content() |
47 | - { |
|
48 | - return $this->_button_content; |
|
49 | - } |
|
47 | + { |
|
48 | + return $this->_button_content; |
|
49 | + } |
|
50 | 50 | } |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @author Mike Nelson |
9 | 9 | * |
10 | 10 | */ |
11 | -class EE_Button_Input extends EE_Form_Input_Base{ |
|
11 | +class EE_Button_Input extends EE_Form_Input_Base { |
|
12 | 12 | |
13 | 13 | /** |
14 | 14 | * @var string of HTML to put between the button tags |
@@ -17,13 +17,13 @@ discard block |
||
17 | 17 | /** |
18 | 18 | * @param array $options |
19 | 19 | */ |
20 | - public function __construct($options = array()){ |
|
21 | - if( empty($options['button_content'])) { |
|
20 | + public function __construct($options = array()) { |
|
21 | + if (empty($options['button_content'])) { |
|
22 | 22 | $options['button_content'] = esc_html__('Button', 'event_espresso'); |
23 | 23 | } |
24 | 24 | $this->_set_display_strategy(new EE_Button_Display_Strategy()); |
25 | 25 | $this->_set_normalization_strategy(new EE_Text_Normalization()); |
26 | - $this->_add_validation_strategy( new EE_Plaintext_Validation_Strategy() ); |
|
26 | + $this->_add_validation_strategy(new EE_Plaintext_Validation_Strategy()); |
|
27 | 27 | parent::__construct($options); |
28 | 28 | } |
29 | 29 |
@@ -19,10 +19,10 @@ |
||
19 | 19 | interface RequiresRegistryInterface |
20 | 20 | { |
21 | 21 | |
22 | - /** |
|
23 | - * @param EE_Registry $registry |
|
24 | - */ |
|
25 | - public function setRegistry($registry); |
|
22 | + /** |
|
23 | + * @param EE_Registry $registry |
|
24 | + */ |
|
25 | + public function setRegistry($registry); |
|
26 | 26 | |
27 | 27 | } |
28 | 28 | // Location: requiresRegistry.php |
@@ -15,36 +15,36 @@ |
||
15 | 15 | interface DomainInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @return string |
|
20 | - * @throws DomainException |
|
21 | - */ |
|
22 | - public function pluginFile(); |
|
18 | + /** |
|
19 | + * @return string |
|
20 | + * @throws DomainException |
|
21 | + */ |
|
22 | + public function pluginFile(); |
|
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * @return string |
|
27 | - * @throws DomainException |
|
28 | - */ |
|
29 | - public function pluginBasename(); |
|
25 | + /** |
|
26 | + * @return string |
|
27 | + * @throws DomainException |
|
28 | + */ |
|
29 | + public function pluginBasename(); |
|
30 | 30 | |
31 | 31 | |
32 | - /** |
|
33 | - * @return string |
|
34 | - */ |
|
35 | - public function pluginPath(); |
|
32 | + /** |
|
33 | + * @return string |
|
34 | + */ |
|
35 | + public function pluginPath(); |
|
36 | 36 | |
37 | 37 | |
38 | - /** |
|
39 | - * @return string |
|
40 | - * @throws DomainException |
|
41 | - */ |
|
42 | - public function pluginUrl(); |
|
38 | + /** |
|
39 | + * @return string |
|
40 | + * @throws DomainException |
|
41 | + */ |
|
42 | + public function pluginUrl(); |
|
43 | 43 | |
44 | 44 | |
45 | - /** |
|
46 | - * @return string |
|
47 | - * @throws DomainException |
|
48 | - */ |
|
49 | - public function version(); |
|
45 | + /** |
|
46 | + * @return string |
|
47 | + * @throws DomainException |
|
48 | + */ |
|
49 | + public function version(); |
|
50 | 50 | } |
@@ -21,146 +21,146 @@ |
||
21 | 21 | class CachingLoader extends LoaderDecorator |
22 | 22 | { |
23 | 23 | |
24 | - /** |
|
25 | - * @var CollectionInterface $cache |
|
26 | - */ |
|
27 | - protected $cache; |
|
28 | - |
|
29 | - /** |
|
30 | - * @var string $identifier |
|
31 | - */ |
|
32 | - protected $identifier; |
|
33 | - |
|
34 | - |
|
35 | - |
|
36 | - /** |
|
37 | - * CachingLoader constructor. |
|
38 | - * |
|
39 | - * @param LoaderDecoratorInterface $loader |
|
40 | - * @param CollectionInterface $cache |
|
41 | - * @param string $identifier |
|
42 | - * @throws InvalidDataTypeException |
|
43 | - */ |
|
44 | - public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '') |
|
45 | - { |
|
46 | - parent::__construct($loader); |
|
47 | - $this->cache = $cache; |
|
48 | - $this->setIdentifier($identifier); |
|
49 | - if ($this->identifier !== '') { |
|
50 | - // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
51 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
52 | - // where "IDENTIFIER" = the string that was set during construction |
|
53 | - add_action( |
|
54 | - "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
55 | - array($this, 'reset') |
|
56 | - ); |
|
57 | - } |
|
58 | - // to clear ALL caches, simply do the following: |
|
59 | - // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
60 | - add_action( |
|
61 | - 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
62 | - array($this, 'reset') |
|
63 | - ); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * @return string |
|
70 | - */ |
|
71 | - public function identifier() |
|
72 | - { |
|
73 | - return $this->identifier; |
|
74 | - } |
|
75 | - |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * @param string $identifier |
|
80 | - * @throws InvalidDataTypeException |
|
81 | - */ |
|
82 | - private function setIdentifier($identifier) |
|
83 | - { |
|
84 | - if ( ! is_string($identifier)) { |
|
85 | - throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
86 | - } |
|
87 | - $this->identifier = $identifier; |
|
88 | - } |
|
89 | - |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * @param string $fqcn |
|
94 | - * @param array $arguments |
|
95 | - * @param bool $shared |
|
96 | - * @return mixed |
|
97 | - */ |
|
98 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
99 | - { |
|
100 | - $fqcn = ltrim($fqcn, '\\'); |
|
101 | - // caching can be turned off via the following code: |
|
102 | - // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
103 | - if( |
|
104 | - apply_filters( |
|
105 | - 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
106 | - false, |
|
107 | - $this |
|
108 | - ) |
|
109 | - ){ |
|
110 | - // even though $shared might be true, caching could be bypassed for whatever reason, |
|
111 | - // so we don't want the core loader to cache anything, therefore caching is turned off |
|
112 | - return $this->loader->load($fqcn, $arguments, false); |
|
113 | - } |
|
114 | - $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
115 | - if($this->cache->has($identifier)){ |
|
116 | - return $this->cache->get($identifier); |
|
117 | - } |
|
118 | - $object = $this->loader->load($fqcn, $arguments, $shared); |
|
119 | - if($object instanceof $fqcn){ |
|
120 | - $this->cache->add($object, $identifier); |
|
121 | - } |
|
122 | - return $object; |
|
123 | - } |
|
124 | - |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * empties cache and calls reset() on loader if method exists |
|
129 | - */ |
|
130 | - public function reset() |
|
131 | - { |
|
132 | - $this->cache->trashAndDetachAll(); |
|
133 | - $this->loader->reset(); |
|
134 | - } |
|
135 | - |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * build a string representation of a class' arguments |
|
140 | - * (mostly because Closures can't be serialized) |
|
141 | - * |
|
142 | - * @param array $arguments |
|
143 | - * @return string |
|
144 | - */ |
|
145 | - private function getIdentifierForArgument(array $arguments) |
|
146 | - { |
|
147 | - $identifier = ''; |
|
148 | - foreach ($arguments as $argument) { |
|
149 | - switch (true) { |
|
150 | - case is_object($argument) : |
|
151 | - case $argument instanceof Closure : |
|
152 | - $identifier .= spl_object_hash($argument); |
|
153 | - break; |
|
154 | - case is_array($argument) : |
|
155 | - $identifier .= $this->getIdentifierForArgument($argument); |
|
156 | - break; |
|
157 | - default : |
|
158 | - $identifier .= $argument; |
|
159 | - break; |
|
160 | - } |
|
161 | - } |
|
162 | - return $identifier; |
|
163 | - } |
|
24 | + /** |
|
25 | + * @var CollectionInterface $cache |
|
26 | + */ |
|
27 | + protected $cache; |
|
28 | + |
|
29 | + /** |
|
30 | + * @var string $identifier |
|
31 | + */ |
|
32 | + protected $identifier; |
|
33 | + |
|
34 | + |
|
35 | + |
|
36 | + /** |
|
37 | + * CachingLoader constructor. |
|
38 | + * |
|
39 | + * @param LoaderDecoratorInterface $loader |
|
40 | + * @param CollectionInterface $cache |
|
41 | + * @param string $identifier |
|
42 | + * @throws InvalidDataTypeException |
|
43 | + */ |
|
44 | + public function __construct(LoaderDecoratorInterface $loader, CollectionInterface $cache, $identifier = '') |
|
45 | + { |
|
46 | + parent::__construct($loader); |
|
47 | + $this->cache = $cache; |
|
48 | + $this->setIdentifier($identifier); |
|
49 | + if ($this->identifier !== '') { |
|
50 | + // to only clear this cache, and assuming an identifier has been set, simply do the following: |
|
51 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__IDENTIFIER'); |
|
52 | + // where "IDENTIFIER" = the string that was set during construction |
|
53 | + add_action( |
|
54 | + "AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache__{$identifier}", |
|
55 | + array($this, 'reset') |
|
56 | + ); |
|
57 | + } |
|
58 | + // to clear ALL caches, simply do the following: |
|
59 | + // do_action('AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache'); |
|
60 | + add_action( |
|
61 | + 'AHEE__EventEspresso_core_services_loaders_CachingLoader__resetCache', |
|
62 | + array($this, 'reset') |
|
63 | + ); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * @return string |
|
70 | + */ |
|
71 | + public function identifier() |
|
72 | + { |
|
73 | + return $this->identifier; |
|
74 | + } |
|
75 | + |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * @param string $identifier |
|
80 | + * @throws InvalidDataTypeException |
|
81 | + */ |
|
82 | + private function setIdentifier($identifier) |
|
83 | + { |
|
84 | + if ( ! is_string($identifier)) { |
|
85 | + throw new InvalidDataTypeException('$identifier', $identifier, 'string'); |
|
86 | + } |
|
87 | + $this->identifier = $identifier; |
|
88 | + } |
|
89 | + |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * @param string $fqcn |
|
94 | + * @param array $arguments |
|
95 | + * @param bool $shared |
|
96 | + * @return mixed |
|
97 | + */ |
|
98 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
99 | + { |
|
100 | + $fqcn = ltrim($fqcn, '\\'); |
|
101 | + // caching can be turned off via the following code: |
|
102 | + // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
|
103 | + if( |
|
104 | + apply_filters( |
|
105 | + 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
|
106 | + false, |
|
107 | + $this |
|
108 | + ) |
|
109 | + ){ |
|
110 | + // even though $shared might be true, caching could be bypassed for whatever reason, |
|
111 | + // so we don't want the core loader to cache anything, therefore caching is turned off |
|
112 | + return $this->loader->load($fqcn, $arguments, false); |
|
113 | + } |
|
114 | + $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
115 | + if($this->cache->has($identifier)){ |
|
116 | + return $this->cache->get($identifier); |
|
117 | + } |
|
118 | + $object = $this->loader->load($fqcn, $arguments, $shared); |
|
119 | + if($object instanceof $fqcn){ |
|
120 | + $this->cache->add($object, $identifier); |
|
121 | + } |
|
122 | + return $object; |
|
123 | + } |
|
124 | + |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * empties cache and calls reset() on loader if method exists |
|
129 | + */ |
|
130 | + public function reset() |
|
131 | + { |
|
132 | + $this->cache->trashAndDetachAll(); |
|
133 | + $this->loader->reset(); |
|
134 | + } |
|
135 | + |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * build a string representation of a class' arguments |
|
140 | + * (mostly because Closures can't be serialized) |
|
141 | + * |
|
142 | + * @param array $arguments |
|
143 | + * @return string |
|
144 | + */ |
|
145 | + private function getIdentifierForArgument(array $arguments) |
|
146 | + { |
|
147 | + $identifier = ''; |
|
148 | + foreach ($arguments as $argument) { |
|
149 | + switch (true) { |
|
150 | + case is_object($argument) : |
|
151 | + case $argument instanceof Closure : |
|
152 | + $identifier .= spl_object_hash($argument); |
|
153 | + break; |
|
154 | + case is_array($argument) : |
|
155 | + $identifier .= $this->getIdentifierForArgument($argument); |
|
156 | + break; |
|
157 | + default : |
|
158 | + $identifier .= $argument; |
|
159 | + break; |
|
160 | + } |
|
161 | + } |
|
162 | + return $identifier; |
|
163 | + } |
|
164 | 164 | |
165 | 165 | |
166 | 166 | } |
@@ -100,23 +100,23 @@ |
||
100 | 100 | $fqcn = ltrim($fqcn, '\\'); |
101 | 101 | // caching can be turned off via the following code: |
102 | 102 | // add_filter('FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', '__return_true'); |
103 | - if( |
|
103 | + if ( |
|
104 | 104 | apply_filters( |
105 | 105 | 'FHEE__EventEspresso_core_services_loaders_CachingLoader__load__bypass_cache', |
106 | 106 | false, |
107 | 107 | $this |
108 | 108 | ) |
109 | - ){ |
|
109 | + ) { |
|
110 | 110 | // even though $shared might be true, caching could be bypassed for whatever reason, |
111 | 111 | // so we don't want the core loader to cache anything, therefore caching is turned off |
112 | 112 | return $this->loader->load($fqcn, $arguments, false); |
113 | 113 | } |
114 | - $identifier = md5($fqcn . $this->getIdentifierForArgument($arguments)); |
|
115 | - if($this->cache->has($identifier)){ |
|
114 | + $identifier = md5($fqcn.$this->getIdentifierForArgument($arguments)); |
|
115 | + if ($this->cache->has($identifier)) { |
|
116 | 116 | return $this->cache->get($identifier); |
117 | 117 | } |
118 | 118 | $object = $this->loader->load($fqcn, $arguments, $shared); |
119 | - if($object instanceof $fqcn){ |
|
119 | + if ($object instanceof $fqcn) { |
|
120 | 120 | $this->cache->add($object, $identifier); |
121 | 121 | } |
122 | 122 | return $object; |
@@ -20,15 +20,15 @@ |
||
20 | 20 | interface RequiresDependencyMapInterface |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * @param EE_Dependency_Map $dependency_map |
|
25 | - */ |
|
26 | - public function setDependencyMap($dependency_map); |
|
27 | - |
|
28 | - /** |
|
29 | - * @return EE_Dependency_Map |
|
30 | - */ |
|
31 | - public function dependencyMap(); |
|
23 | + /** |
|
24 | + * @param EE_Dependency_Map $dependency_map |
|
25 | + */ |
|
26 | + public function setDependencyMap($dependency_map); |
|
27 | + |
|
28 | + /** |
|
29 | + * @return EE_Dependency_Map |
|
30 | + */ |
|
31 | + public function dependencyMap(); |
|
32 | 32 | |
33 | 33 | } |
34 | 34 | // Location: RequiresDependencyMap.php |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | use EventEspresso\core\exceptions\InvalidDataTypeException; |
5 | 5 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
6 | 6 | |
7 | -if (! defined('EVENT_ESPRESSO_VERSION')) { |
|
7 | +if ( ! defined('EVENT_ESPRESSO_VERSION')) { |
|
8 | 8 | exit('No direct script access allowed'); |
9 | 9 | } |
10 | 10 | |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | { |
33 | 33 | |
34 | 34 | //validate that the first element in the array is an EE_Registration object. |
35 | - if (! reset($data) instanceof EE_Registration) { |
|
35 | + if ( ! reset($data) instanceof EE_Registration) { |
|
36 | 36 | throw new EE_Error( |
37 | 37 | esc_html__( |
38 | 38 | 'The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
@@ -101,7 +101,7 @@ discard block |
||
101 | 101 | */ |
102 | 102 | public static function convert_data_for_persistent_storage($registrations) |
103 | 103 | { |
104 | - if (! self::validateRegistrationsForConversion($registrations)) { |
|
104 | + if ( ! self::validateRegistrationsForConversion($registrations)) { |
|
105 | 105 | return array(); |
106 | 106 | } |
107 | 107 | |
@@ -114,7 +114,7 @@ discard block |
||
114 | 114 | //k nope so let's pull from the registrations |
115 | 115 | $registration_ids = array_filter( |
116 | 116 | array_map( |
117 | - function ($registration) { |
|
117 | + function($registration) { |
|
118 | 118 | if ($registration instanceof EE_Registration) { |
119 | 119 | return $registration->ID(); |
120 | 120 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | use EventEspresso\core\exceptions\InvalidInterfaceException; |
6 | 6 | |
7 | 7 | if (! defined('EVENT_ESPRESSO_VERSION')) { |
8 | - exit('No direct script access allowed'); |
|
8 | + exit('No direct script access allowed'); |
|
9 | 9 | } |
10 | 10 | |
11 | 11 | /** |
@@ -21,172 +21,172 @@ discard block |
||
21 | 21 | { |
22 | 22 | |
23 | 23 | |
24 | - /** |
|
25 | - * Constructor. |
|
26 | - * |
|
27 | - * @param EE_Registration[] $data expecting an array of EE_Registration objects. |
|
28 | - * @throws EE_Error |
|
29 | - * @access protected |
|
30 | - */ |
|
31 | - public function __construct($data = array()) |
|
32 | - { |
|
33 | - |
|
34 | - //validate that the first element in the array is an EE_Registration object. |
|
35 | - if (! reset($data) instanceof EE_Registration) { |
|
36 | - throw new EE_Error( |
|
37 | - esc_html__( |
|
38 | - 'The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
|
39 | - 'event_espresso' |
|
40 | - ) |
|
41 | - ); |
|
42 | - } |
|
43 | - parent::__construct($data); |
|
44 | - } |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * setup the data. |
|
49 | - * Sets up the expected data object for the messages prep using incoming registration objects. |
|
50 | - * |
|
51 | - * @return void |
|
52 | - * @throws EE_Error |
|
53 | - * @throws EntityNotFoundException |
|
54 | - * @access protected |
|
55 | - */ |
|
56 | - protected function _setup_data() |
|
57 | - { |
|
58 | - //we'll loop through each contact and setup the data needed. Note that many properties will just be set as |
|
59 | - // empty because this data handler is for a very specific set of data (i.e. just what's related to the |
|
60 | - // registration). |
|
61 | - |
|
62 | - $this->reg_objs = $this->data(); |
|
63 | - $this->txn = $this->_maybe_get_transaction(); |
|
64 | - $this->_assemble_data(); |
|
65 | - } |
|
66 | - |
|
67 | - |
|
68 | - /** |
|
69 | - * If the incoming registrations all share the same transaction then this will return the transaction object shared |
|
70 | - * among the registrations. Otherwise the transaction object is set to null because its intended to only represent |
|
71 | - * one transaction. |
|
72 | - * |
|
73 | - * @return EE_Transaction|null |
|
74 | - * @throws EE_Error |
|
75 | - * @throws EntityNotFoundException |
|
76 | - */ |
|
77 | - protected function _maybe_get_transaction() |
|
78 | - { |
|
79 | - $transactions = array(); |
|
80 | - foreach ($this->reg_objs as $registration) { |
|
81 | - if ($registration instanceof EE_Registration) { |
|
82 | - $transaction = $registration->transaction(); |
|
83 | - if ($transaction instanceof EE_Transaction) { |
|
84 | - $transactions[$transaction->ID()] = $transaction; |
|
85 | - } |
|
86 | - } |
|
87 | - } |
|
88 | - return count($transactions) === 1 ? reset($transactions) : null; |
|
89 | - } |
|
90 | - |
|
91 | - |
|
92 | - /** |
|
93 | - * Returns database safe representation of the data later used to when instantiating this object. |
|
94 | - * |
|
95 | - * @param array $registrations The incoming data to be prepped. |
|
96 | - * @return EE_Registration[] The data being prepared for the db |
|
97 | - * @throws EE_Error |
|
98 | - * @throws InvalidArgumentException |
|
99 | - * @throws InvalidDataTypeException |
|
100 | - * @throws InvalidInterfaceException |
|
101 | - */ |
|
102 | - public static function convert_data_for_persistent_storage($registrations) |
|
103 | - { |
|
104 | - if (! self::validateRegistrationsForConversion($registrations)) { |
|
105 | - return array(); |
|
106 | - } |
|
107 | - |
|
108 | - //is this an array of ints? |
|
109 | - $first_item = reset($registrations); |
|
110 | - if (is_int($first_item)) { |
|
111 | - return $registrations; |
|
112 | - } |
|
113 | - |
|
114 | - //k nope so let's pull from the registrations |
|
115 | - $registration_ids = array_filter( |
|
116 | - array_map( |
|
117 | - function ($registration) { |
|
118 | - if ($registration instanceof EE_Registration) { |
|
119 | - return $registration->ID(); |
|
120 | - } |
|
121 | - return false; |
|
122 | - }, |
|
123 | - $registrations |
|
124 | - ) |
|
125 | - ); |
|
126 | - |
|
127 | - return $registration_ids; |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - /** |
|
132 | - * This validates incoming registrations (considers whether they are ids or EE_Registration objects. |
|
133 | - * |
|
134 | - * @param array $registrations Could be EE_Registration[] or int[] |
|
135 | - * @return bool |
|
136 | - * @throws EE_Error |
|
137 | - * @throws InvalidArgumentException |
|
138 | - * @throws InvalidDataTypeException |
|
139 | - * @throws InvalidInterfaceException |
|
140 | - */ |
|
141 | - protected static function validateRegistrationsForConversion($registrations) |
|
142 | - { |
|
143 | - if (is_array($registrations)) { |
|
144 | - $first_item = reset($registrations); |
|
145 | - if ($first_item instanceof EE_Registration) { |
|
146 | - return true; |
|
147 | - } |
|
148 | - if (is_int($first_item)) { |
|
149 | - //k let's some basic validation here. This isn't foolproof but better than nothing. |
|
150 | - //the purpose of this validation is to verify that the ids sent in match valid registrations existing |
|
151 | - //in the db. If the count is different, then we know they aren't valid. |
|
152 | - $count_for_ids = EEM_Registration::instance()->count( |
|
153 | - array( |
|
154 | - array( |
|
155 | - 'REG_ID' => array('IN', $registrations) |
|
156 | - ) |
|
157 | - ) |
|
158 | - ); |
|
159 | - return $count_for_ids === count($registrations); |
|
160 | - } |
|
161 | - } |
|
162 | - return false; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
168 | - * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
169 | - * |
|
170 | - * @param array $data |
|
171 | - * @return EE_Registration[] |
|
172 | - * @throws EE_Error |
|
173 | - * @throws InvalidArgumentException |
|
174 | - * @throws InvalidDataTypeException |
|
175 | - * @throws InvalidInterfaceException |
|
176 | - */ |
|
177 | - public static function convert_data_from_persistent_storage($data) |
|
178 | - { |
|
179 | - //since this was added later, we need to account of possible back compat issues where data already queued for |
|
180 | - // generation is in the old format, which is an array of EE_Registration objects. So if that's the case, then |
|
181 | - // let's just return them |
|
182 | - //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
|
183 | - if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
184 | - return $data; |
|
185 | - } |
|
186 | - |
|
187 | - $registrations = is_array($data) |
|
188 | - ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
189 | - : array(); |
|
190 | - return $registrations; |
|
191 | - } |
|
24 | + /** |
|
25 | + * Constructor. |
|
26 | + * |
|
27 | + * @param EE_Registration[] $data expecting an array of EE_Registration objects. |
|
28 | + * @throws EE_Error |
|
29 | + * @access protected |
|
30 | + */ |
|
31 | + public function __construct($data = array()) |
|
32 | + { |
|
33 | + |
|
34 | + //validate that the first element in the array is an EE_Registration object. |
|
35 | + if (! reset($data) instanceof EE_Registration) { |
|
36 | + throw new EE_Error( |
|
37 | + esc_html__( |
|
38 | + 'The EE_Message_Registrations_incoming_data class expects an array of EE_Registration objects.', |
|
39 | + 'event_espresso' |
|
40 | + ) |
|
41 | + ); |
|
42 | + } |
|
43 | + parent::__construct($data); |
|
44 | + } |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * setup the data. |
|
49 | + * Sets up the expected data object for the messages prep using incoming registration objects. |
|
50 | + * |
|
51 | + * @return void |
|
52 | + * @throws EE_Error |
|
53 | + * @throws EntityNotFoundException |
|
54 | + * @access protected |
|
55 | + */ |
|
56 | + protected function _setup_data() |
|
57 | + { |
|
58 | + //we'll loop through each contact and setup the data needed. Note that many properties will just be set as |
|
59 | + // empty because this data handler is for a very specific set of data (i.e. just what's related to the |
|
60 | + // registration). |
|
61 | + |
|
62 | + $this->reg_objs = $this->data(); |
|
63 | + $this->txn = $this->_maybe_get_transaction(); |
|
64 | + $this->_assemble_data(); |
|
65 | + } |
|
66 | + |
|
67 | + |
|
68 | + /** |
|
69 | + * If the incoming registrations all share the same transaction then this will return the transaction object shared |
|
70 | + * among the registrations. Otherwise the transaction object is set to null because its intended to only represent |
|
71 | + * one transaction. |
|
72 | + * |
|
73 | + * @return EE_Transaction|null |
|
74 | + * @throws EE_Error |
|
75 | + * @throws EntityNotFoundException |
|
76 | + */ |
|
77 | + protected function _maybe_get_transaction() |
|
78 | + { |
|
79 | + $transactions = array(); |
|
80 | + foreach ($this->reg_objs as $registration) { |
|
81 | + if ($registration instanceof EE_Registration) { |
|
82 | + $transaction = $registration->transaction(); |
|
83 | + if ($transaction instanceof EE_Transaction) { |
|
84 | + $transactions[$transaction->ID()] = $transaction; |
|
85 | + } |
|
86 | + } |
|
87 | + } |
|
88 | + return count($transactions) === 1 ? reset($transactions) : null; |
|
89 | + } |
|
90 | + |
|
91 | + |
|
92 | + /** |
|
93 | + * Returns database safe representation of the data later used to when instantiating this object. |
|
94 | + * |
|
95 | + * @param array $registrations The incoming data to be prepped. |
|
96 | + * @return EE_Registration[] The data being prepared for the db |
|
97 | + * @throws EE_Error |
|
98 | + * @throws InvalidArgumentException |
|
99 | + * @throws InvalidDataTypeException |
|
100 | + * @throws InvalidInterfaceException |
|
101 | + */ |
|
102 | + public static function convert_data_for_persistent_storage($registrations) |
|
103 | + { |
|
104 | + if (! self::validateRegistrationsForConversion($registrations)) { |
|
105 | + return array(); |
|
106 | + } |
|
107 | + |
|
108 | + //is this an array of ints? |
|
109 | + $first_item = reset($registrations); |
|
110 | + if (is_int($first_item)) { |
|
111 | + return $registrations; |
|
112 | + } |
|
113 | + |
|
114 | + //k nope so let's pull from the registrations |
|
115 | + $registration_ids = array_filter( |
|
116 | + array_map( |
|
117 | + function ($registration) { |
|
118 | + if ($registration instanceof EE_Registration) { |
|
119 | + return $registration->ID(); |
|
120 | + } |
|
121 | + return false; |
|
122 | + }, |
|
123 | + $registrations |
|
124 | + ) |
|
125 | + ); |
|
126 | + |
|
127 | + return $registration_ids; |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + /** |
|
132 | + * This validates incoming registrations (considers whether they are ids or EE_Registration objects. |
|
133 | + * |
|
134 | + * @param array $registrations Could be EE_Registration[] or int[] |
|
135 | + * @return bool |
|
136 | + * @throws EE_Error |
|
137 | + * @throws InvalidArgumentException |
|
138 | + * @throws InvalidDataTypeException |
|
139 | + * @throws InvalidInterfaceException |
|
140 | + */ |
|
141 | + protected static function validateRegistrationsForConversion($registrations) |
|
142 | + { |
|
143 | + if (is_array($registrations)) { |
|
144 | + $first_item = reset($registrations); |
|
145 | + if ($first_item instanceof EE_Registration) { |
|
146 | + return true; |
|
147 | + } |
|
148 | + if (is_int($first_item)) { |
|
149 | + //k let's some basic validation here. This isn't foolproof but better than nothing. |
|
150 | + //the purpose of this validation is to verify that the ids sent in match valid registrations existing |
|
151 | + //in the db. If the count is different, then we know they aren't valid. |
|
152 | + $count_for_ids = EEM_Registration::instance()->count( |
|
153 | + array( |
|
154 | + array( |
|
155 | + 'REG_ID' => array('IN', $registrations) |
|
156 | + ) |
|
157 | + ) |
|
158 | + ); |
|
159 | + return $count_for_ids === count($registrations); |
|
160 | + } |
|
161 | + } |
|
162 | + return false; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * Data that has been stored in persistent storage that was prepped by _convert_data_for_persistent_storage |
|
168 | + * can be sent into this method and converted back into the format used for instantiating with this data handler. |
|
169 | + * |
|
170 | + * @param array $data |
|
171 | + * @return EE_Registration[] |
|
172 | + * @throws EE_Error |
|
173 | + * @throws InvalidArgumentException |
|
174 | + * @throws InvalidDataTypeException |
|
175 | + * @throws InvalidInterfaceException |
|
176 | + */ |
|
177 | + public static function convert_data_from_persistent_storage($data) |
|
178 | + { |
|
179 | + //since this was added later, we need to account of possible back compat issues where data already queued for |
|
180 | + // generation is in the old format, which is an array of EE_Registration objects. So if that's the case, then |
|
181 | + // let's just return them |
|
182 | + //@see https://events.codebasehq.com/projects/event-espresso/tickets/10127 |
|
183 | + if (is_array($data) && reset($data) instanceof EE_Registration) { |
|
184 | + return $data; |
|
185 | + } |
|
186 | + |
|
187 | + $registrations = is_array($data) |
|
188 | + ? EEM_Registration::instance()->get_all(array(array('REG_ID' => array('IN', $data)))) |
|
189 | + : array(); |
|
190 | + return $registrations; |
|
191 | + } |
|
192 | 192 | } |
@@ -32,115 +32,115 @@ |
||
32 | 32 | class CoreLoader implements LoaderDecoratorInterface |
33 | 33 | { |
34 | 34 | |
35 | - /** |
|
36 | - * @var EE_Registry|CoffeeShop $generator |
|
37 | - */ |
|
38 | - private $generator; |
|
39 | - |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * CoreLoader constructor. |
|
44 | - * |
|
45 | - * @param EE_Registry|CoffeeShop $generator |
|
46 | - * @throws InvalidArgumentException |
|
47 | - */ |
|
48 | - public function __construct($generator) |
|
49 | - { |
|
50 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
51 | - throw new InvalidArgumentException( |
|
52 | - esc_html__( |
|
53 | - 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
54 | - 'event_espresso' |
|
55 | - ) |
|
56 | - ); |
|
57 | - } |
|
58 | - $this->generator = $generator; |
|
59 | - } |
|
60 | - |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Calls the appropriate loading method from the installed generator; |
|
65 | - * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
|
66 | - * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
|
67 | - * but NOT to the class being instantiated. |
|
68 | - * This is done by adding the parameters to the $arguments array as follows: |
|
69 | - * array( |
|
70 | - * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
|
71 | - * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
|
72 | - * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
|
73 | - * ) |
|
74 | - * |
|
75 | - * @param string $fqcn |
|
76 | - * @param array $arguments |
|
77 | - * @param bool $shared |
|
78 | - * @return mixed |
|
79 | - * @throws OutOfBoundsException |
|
80 | - * @throws ServiceExistsException |
|
81 | - * @throws InstantiationException |
|
82 | - * @throws InvalidIdentifierException |
|
83 | - * @throws InvalidDataTypeException |
|
84 | - * @throws InvalidClassException |
|
85 | - * @throws EE_Error |
|
86 | - * @throws ServiceNotFoundException |
|
87 | - * @throws ReflectionException |
|
88 | - */ |
|
89 | - public function load($fqcn, $arguments = array(), $shared = true) |
|
90 | - { |
|
91 | - $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN); |
|
92 | - if($this->generator instanceof EE_Registry) { |
|
93 | - // check if additional EE_Registry::create() arguments have been passed |
|
94 | - // from_db |
|
95 | - $from_db = isset($arguments['EE_Registry::create(from_db)']) |
|
96 | - ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN) |
|
97 | - : false; |
|
98 | - // load_only |
|
99 | - $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
100 | - ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN) |
|
101 | - : false; |
|
102 | - // addon |
|
103 | - $addon = isset($arguments['EE_Registry::create(addon)']) |
|
104 | - ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN) |
|
105 | - : false; |
|
106 | - unset( |
|
107 | - $arguments['EE_Registry::create(from_db)'], |
|
108 | - $arguments['EE_Registry::create(load_only)'], |
|
109 | - $arguments['EE_Registry::create(addon)'] |
|
110 | - ); |
|
111 | - // addons need to be cached on EE_Registry |
|
112 | - $shared = $addon ? true : $shared; |
|
113 | - return $this->generator->create( |
|
114 | - $fqcn, |
|
115 | - $arguments, |
|
116 | - $shared, |
|
117 | - $from_db, |
|
118 | - $load_only, |
|
119 | - $addon |
|
120 | - ); |
|
121 | - } |
|
122 | - return $this->generator->brew( |
|
123 | - $fqcn, |
|
124 | - $arguments, |
|
125 | - $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
126 | - ); |
|
127 | - |
|
128 | - } |
|
129 | - |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * calls reset() on generator if method exists |
|
134 | - * |
|
135 | - * @throws EE_Error |
|
136 | - * @throws ReflectionException |
|
137 | - */ |
|
138 | - public function reset() |
|
139 | - { |
|
140 | - if (method_exists($this->generator, 'reset')) { |
|
141 | - $this->generator->reset(); |
|
142 | - } |
|
143 | - } |
|
35 | + /** |
|
36 | + * @var EE_Registry|CoffeeShop $generator |
|
37 | + */ |
|
38 | + private $generator; |
|
39 | + |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * CoreLoader constructor. |
|
44 | + * |
|
45 | + * @param EE_Registry|CoffeeShop $generator |
|
46 | + * @throws InvalidArgumentException |
|
47 | + */ |
|
48 | + public function __construct($generator) |
|
49 | + { |
|
50 | + if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
51 | + throw new InvalidArgumentException( |
|
52 | + esc_html__( |
|
53 | + 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
|
54 | + 'event_espresso' |
|
55 | + ) |
|
56 | + ); |
|
57 | + } |
|
58 | + $this->generator = $generator; |
|
59 | + } |
|
60 | + |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Calls the appropriate loading method from the installed generator; |
|
65 | + * If EE_Registry is being used, then the additional parameters for the EE_Registry::create() method |
|
66 | + * can be added to the $arguments array and they will be extracted and passed to EE_Registry::create(), |
|
67 | + * but NOT to the class being instantiated. |
|
68 | + * This is done by adding the parameters to the $arguments array as follows: |
|
69 | + * array( |
|
70 | + * 'EE_Registry::create(from_db)' => true, // boolean value, default = false |
|
71 | + * 'EE_Registry::create(load_only)' => true, // boolean value, default = false |
|
72 | + * 'EE_Registry::create(addon)' => true, // boolean value, default = false |
|
73 | + * ) |
|
74 | + * |
|
75 | + * @param string $fqcn |
|
76 | + * @param array $arguments |
|
77 | + * @param bool $shared |
|
78 | + * @return mixed |
|
79 | + * @throws OutOfBoundsException |
|
80 | + * @throws ServiceExistsException |
|
81 | + * @throws InstantiationException |
|
82 | + * @throws InvalidIdentifierException |
|
83 | + * @throws InvalidDataTypeException |
|
84 | + * @throws InvalidClassException |
|
85 | + * @throws EE_Error |
|
86 | + * @throws ServiceNotFoundException |
|
87 | + * @throws ReflectionException |
|
88 | + */ |
|
89 | + public function load($fqcn, $arguments = array(), $shared = true) |
|
90 | + { |
|
91 | + $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN); |
|
92 | + if($this->generator instanceof EE_Registry) { |
|
93 | + // check if additional EE_Registry::create() arguments have been passed |
|
94 | + // from_db |
|
95 | + $from_db = isset($arguments['EE_Registry::create(from_db)']) |
|
96 | + ? filter_var($arguments['EE_Registry::create(from_db)'], FILTER_VALIDATE_BOOLEAN) |
|
97 | + : false; |
|
98 | + // load_only |
|
99 | + $load_only = isset($arguments['EE_Registry::create(load_only)']) |
|
100 | + ? filter_var($arguments['EE_Registry::create(load_only)'], FILTER_VALIDATE_BOOLEAN) |
|
101 | + : false; |
|
102 | + // addon |
|
103 | + $addon = isset($arguments['EE_Registry::create(addon)']) |
|
104 | + ? filter_var($arguments['EE_Registry::create(addon)'], FILTER_VALIDATE_BOOLEAN) |
|
105 | + : false; |
|
106 | + unset( |
|
107 | + $arguments['EE_Registry::create(from_db)'], |
|
108 | + $arguments['EE_Registry::create(load_only)'], |
|
109 | + $arguments['EE_Registry::create(addon)'] |
|
110 | + ); |
|
111 | + // addons need to be cached on EE_Registry |
|
112 | + $shared = $addon ? true : $shared; |
|
113 | + return $this->generator->create( |
|
114 | + $fqcn, |
|
115 | + $arguments, |
|
116 | + $shared, |
|
117 | + $from_db, |
|
118 | + $load_only, |
|
119 | + $addon |
|
120 | + ); |
|
121 | + } |
|
122 | + return $this->generator->brew( |
|
123 | + $fqcn, |
|
124 | + $arguments, |
|
125 | + $shared ? CoffeeMaker::BREW_SHARED : CoffeeMaker::BREW_NEW |
|
126 | + ); |
|
127 | + |
|
128 | + } |
|
129 | + |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * calls reset() on generator if method exists |
|
134 | + * |
|
135 | + * @throws EE_Error |
|
136 | + * @throws ReflectionException |
|
137 | + */ |
|
138 | + public function reset() |
|
139 | + { |
|
140 | + if (method_exists($this->generator, 'reset')) { |
|
141 | + $this->generator->reset(); |
|
142 | + } |
|
143 | + } |
|
144 | 144 | |
145 | 145 | } |
146 | 146 | // End of file CoreLoader.php |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | */ |
48 | 48 | public function __construct($generator) |
49 | 49 | { |
50 | - if(!($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
50 | + if ( ! ($generator instanceof EE_Registry || $generator instanceof CoffeeShop)) { |
|
51 | 51 | throw new InvalidArgumentException( |
52 | 52 | esc_html__( |
53 | 53 | 'The CoreLoader class must receive an instance of EE_Registry or the CoffeeShop DI container.', |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | public function load($fqcn, $arguments = array(), $shared = true) |
90 | 90 | { |
91 | 91 | $shared = filter_var($shared, FILTER_VALIDATE_BOOLEAN); |
92 | - if($this->generator instanceof EE_Registry) { |
|
92 | + if ($this->generator instanceof EE_Registry) { |
|
93 | 93 | // check if additional EE_Registry::create() arguments have been passed |
94 | 94 | // from_db |
95 | 95 | $from_db = isset($arguments['EE_Registry::create(from_db)']) |