@@ -17,327 +17,327 @@ |
||
17 | 17 | */ |
18 | 18 | class CustomSelects |
19 | 19 | { |
20 | - const TYPE_SIMPLE = 'simple'; |
|
21 | - const TYPE_COMPLEX = 'complex'; |
|
22 | - const TYPE_STRUCTURED = 'structured'; |
|
23 | - |
|
24 | - private $valid_operators = array('COUNT', 'SUM'); |
|
25 | - |
|
26 | - |
|
27 | - /** |
|
28 | - * Original incoming select array |
|
29 | - * @var array |
|
30 | - */ |
|
31 | - private $original_selects; |
|
32 | - |
|
33 | - /** |
|
34 | - * Select string that can be added to the query |
|
35 | - * @var string |
|
36 | - */ |
|
37 | - private $columns_to_select_expression; |
|
38 | - |
|
39 | - |
|
40 | - /** |
|
41 | - * An array of aliases for the columns included in the incoming select array. |
|
42 | - * @var array |
|
43 | - */ |
|
44 | - private $column_aliases_in_select; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Enum representation of the "type" of array coming into this value object. |
|
49 | - * @var string |
|
50 | - * |
|
51 | - */ |
|
52 | - private $type = ''; |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * CustomSelects constructor. |
|
57 | - * Incoming selects can be in one of the following formats: |
|
58 | - * ---- self::TYPE_SIMPLE array ---- |
|
59 | - * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
60 | - * multiple columns to select as the values. |
|
61 | - * eg. array( 'ATT_ID', 'REG_ID' ) |
|
62 | - * eg. array( '*' ) |
|
63 | - * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
64 | - * "structured" method. |
|
65 | - * ---- self::TYPE_COMPLEX array ---- |
|
66 | - * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
67 | - * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
68 | - * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
69 | - * EEM_Base::$_valid_wpdb_data_types. |
|
70 | - * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
71 | - * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
72 | - * ---- self::TYPE_STRUCTURED array --- |
|
73 | - * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
74 | - * to the column alias contains three values. The first value is the qualified column name (which can include |
|
75 | - * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
76 | - * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
77 | - * the second value. |
|
78 | - * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
79 | - * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
80 | - * |
|
81 | - * NOTE: mixing array types in the incoming $select will cause errors. |
|
82 | - * |
|
83 | - * @param array $selects |
|
84 | - * @throws InvalidArgumentException |
|
85 | - */ |
|
86 | - public function __construct(array $selects) |
|
87 | - { |
|
88 | - $this->original_selects = $selects; |
|
89 | - $this->deriveType($selects); |
|
90 | - $this->deriveParts($selects); |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * Derives what type of custom select has been sent in. |
|
96 | - * @param array $selects |
|
97 | - * @throws InvalidArgumentException |
|
98 | - */ |
|
99 | - private function deriveType(array $selects) |
|
100 | - { |
|
101 | - // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
102 | - // ensure all elements of the array are simple. |
|
103 | - if (is_int(key($selects))) { |
|
104 | - // let's ensure all keys are ints |
|
105 | - $invalid_keys = array_filter( |
|
106 | - array_keys($selects), |
|
107 | - function ($value) { |
|
108 | - return ! is_int($value); |
|
109 | - } |
|
110 | - ); |
|
111 | - if (! empty($invalid_keys)) { |
|
112 | - throw new InvalidArgumentException( |
|
113 | - sprintf( |
|
114 | - esc_html__( |
|
115 | - 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
116 | - 'event_espresso' |
|
117 | - ), |
|
118 | - self::TYPE_SIMPLE |
|
119 | - ) |
|
120 | - ); |
|
121 | - } |
|
122 | - $this->type = self::TYPE_SIMPLE; |
|
123 | - return; |
|
124 | - } |
|
125 | - // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
126 | - // the first array element off. |
|
127 | - $first_element = reset($selects); |
|
128 | - |
|
129 | - if (! is_array($first_element)) { |
|
130 | - throw new InvalidArgumentException( |
|
131 | - sprintf( |
|
132 | - esc_html__( |
|
133 | - 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
134 | - 'event_espresso' |
|
135 | - ), |
|
136 | - self::TYPE_COMPLEX, |
|
137 | - self::TYPE_STRUCTURED |
|
138 | - ) |
|
139 | - ); |
|
140 | - } |
|
141 | - $this->type = count($first_element) === 2 |
|
142 | - ? self::TYPE_COMPLEX |
|
143 | - : self::TYPE_STRUCTURED; |
|
144 | - } |
|
145 | - |
|
146 | - |
|
147 | - /** |
|
148 | - * Sets up the various properties for the vo depending on type. |
|
149 | - * @param array $selects |
|
150 | - * @throws InvalidArgumentException |
|
151 | - */ |
|
152 | - private function deriveParts(array $selects) |
|
153 | - { |
|
154 | - $column_parts = array(); |
|
155 | - switch ($this->type) { |
|
156 | - case self::TYPE_SIMPLE: |
|
157 | - $column_parts = $selects; |
|
158 | - $this->column_aliases_in_select = $selects; |
|
159 | - break; |
|
160 | - case self::TYPE_COMPLEX: |
|
161 | - foreach ($selects as $alias => $parts) { |
|
162 | - $this->validateSelectValueForType($parts, $alias); |
|
163 | - $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
164 | - $this->column_aliases_in_select[] = $alias; |
|
165 | - } |
|
166 | - break; |
|
167 | - case self::TYPE_STRUCTURED: |
|
168 | - foreach ($selects as $alias => $parts) { |
|
169 | - $this->validateSelectValueForType($parts, $alias); |
|
170 | - $column_parts[] = $parts[1] !== '' |
|
171 | - ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
172 | - : "{$parts[0]} AS {$alias}"; |
|
173 | - $this->column_aliases_in_select[] = $alias; |
|
174 | - } |
|
175 | - break; |
|
176 | - } |
|
177 | - $this->columns_to_select_expression = implode(', ', $column_parts); |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
183 | - * @param array $select_parts |
|
184 | - * @param string $alias |
|
185 | - * @throws InvalidArgumentException |
|
186 | - */ |
|
187 | - private function validateSelectValueForType(array $select_parts, $alias) |
|
188 | - { |
|
189 | - $valid_data_types = array('%d', '%s', '%f'); |
|
190 | - if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
191 | - throw new InvalidArgumentException( |
|
192 | - sprintf( |
|
193 | - esc_html__( |
|
194 | - 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
195 | - 'event_espresso' |
|
196 | - ), |
|
197 | - $alias, |
|
198 | - $this->expectedSelectPartCountForType(), |
|
199 | - $this->type, |
|
200 | - count($select_parts) |
|
201 | - ) |
|
202 | - ); |
|
203 | - } |
|
204 | - // validate data type. |
|
205 | - $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
206 | - $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
207 | - |
|
208 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
209 | - throw new InvalidArgumentException( |
|
210 | - sprintf( |
|
211 | - esc_html__( |
|
212 | - 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
213 | - 'event_espresso' |
|
214 | - ), |
|
215 | - $data_type, |
|
216 | - $select_parts[0], |
|
217 | - $alias, |
|
218 | - implode(', ', $valid_data_types) |
|
219 | - ) |
|
220 | - ); |
|
221 | - } |
|
222 | - } |
|
223 | - |
|
224 | - |
|
225 | - /** |
|
226 | - * Each type will have an expected count of array elements, this returns what that expected count is. |
|
227 | - * @param string $type |
|
228 | - * @return int |
|
229 | - */ |
|
230 | - private function expectedSelectPartCountForType($type = '') |
|
231 | - { |
|
232 | - $type = $type === '' ? $this->type : $type; |
|
233 | - $types_count_map = array( |
|
234 | - self::TYPE_COMPLEX => 2, |
|
235 | - self::TYPE_STRUCTURED => 3 |
|
236 | - ); |
|
237 | - return isset($types_count_map[$type]) ? $types_count_map[$type] : 0; |
|
238 | - } |
|
239 | - |
|
240 | - |
|
241 | - /** |
|
242 | - * Prepares the select statement part for for structured type selects. |
|
243 | - * @param array $select_parts |
|
244 | - * @param string $alias |
|
245 | - * @return string |
|
246 | - * @throws InvalidArgumentException |
|
247 | - */ |
|
248 | - private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
249 | - { |
|
250 | - $operator = strtoupper($select_parts[1]); |
|
251 | - // validate operator |
|
252 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
253 | - throw new InvalidArgumentException( |
|
254 | - sprintf( |
|
255 | - esc_html__( |
|
256 | - 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
257 | - 'event_espresso' |
|
258 | - ), |
|
259 | - $operator, |
|
260 | - $alias, |
|
261 | - implode(', ', $this->valid_operators) |
|
262 | - ) |
|
263 | - ); |
|
264 | - } |
|
265 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * Return the datatype from the given select part. |
|
271 | - * Remember the select_part has already been validated on object instantiation. |
|
272 | - * @param array $select_part |
|
273 | - * @return string |
|
274 | - */ |
|
275 | - private function getDataTypeForSelectType(array $select_part) |
|
276 | - { |
|
277 | - switch ($this->type) { |
|
278 | - case self::TYPE_COMPLEX: |
|
279 | - return $select_part[1]; |
|
280 | - case self::TYPE_STRUCTURED: |
|
281 | - return $select_part[2]; |
|
282 | - default: |
|
283 | - return ''; |
|
284 | - } |
|
285 | - } |
|
286 | - |
|
287 | - |
|
288 | - /** |
|
289 | - * Returns the original select array sent into the VO. |
|
290 | - * @return array |
|
291 | - */ |
|
292 | - public function originalSelects() |
|
293 | - { |
|
294 | - return $this->original_selects; |
|
295 | - } |
|
296 | - |
|
297 | - |
|
298 | - /** |
|
299 | - * Returns the final assembled select expression derived from the incoming select array. |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function columnsToSelectExpression() |
|
303 | - { |
|
304 | - return $this->columns_to_select_expression; |
|
305 | - } |
|
306 | - |
|
307 | - |
|
308 | - /** |
|
309 | - * Returns all the column aliases derived from the incoming select array. |
|
310 | - * @return array |
|
311 | - */ |
|
312 | - public function columnAliases() |
|
313 | - { |
|
314 | - return $this->column_aliases_in_select; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * Returns the enum type for the incoming select array. |
|
320 | - * @return string |
|
321 | - */ |
|
322 | - public function type() |
|
323 | - { |
|
324 | - return $this->type; |
|
325 | - } |
|
326 | - |
|
327 | - |
|
328 | - |
|
329 | - /** |
|
330 | - * Return the datatype for the given column_alias |
|
331 | - * @param string $column_alias |
|
332 | - * @return string (if there's no data type we return string as the default). |
|
333 | - */ |
|
334 | - public function getDataTypeForAlias($column_alias) |
|
335 | - { |
|
336 | - if (isset($this->original_selects[$column_alias]) |
|
337 | - && in_array($column_alias, $this->columnAliases(), true) |
|
338 | - ) { |
|
339 | - return $this->getDataTypeForSelectType($this->original_selects[$column_alias]); |
|
340 | - } |
|
341 | - return '%s'; |
|
342 | - } |
|
20 | + const TYPE_SIMPLE = 'simple'; |
|
21 | + const TYPE_COMPLEX = 'complex'; |
|
22 | + const TYPE_STRUCTURED = 'structured'; |
|
23 | + |
|
24 | + private $valid_operators = array('COUNT', 'SUM'); |
|
25 | + |
|
26 | + |
|
27 | + /** |
|
28 | + * Original incoming select array |
|
29 | + * @var array |
|
30 | + */ |
|
31 | + private $original_selects; |
|
32 | + |
|
33 | + /** |
|
34 | + * Select string that can be added to the query |
|
35 | + * @var string |
|
36 | + */ |
|
37 | + private $columns_to_select_expression; |
|
38 | + |
|
39 | + |
|
40 | + /** |
|
41 | + * An array of aliases for the columns included in the incoming select array. |
|
42 | + * @var array |
|
43 | + */ |
|
44 | + private $column_aliases_in_select; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Enum representation of the "type" of array coming into this value object. |
|
49 | + * @var string |
|
50 | + * |
|
51 | + */ |
|
52 | + private $type = ''; |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * CustomSelects constructor. |
|
57 | + * Incoming selects can be in one of the following formats: |
|
58 | + * ---- self::TYPE_SIMPLE array ---- |
|
59 | + * This is considered the "simple" type. In this case the array is an numerically indexed array with single or |
|
60 | + * multiple columns to select as the values. |
|
61 | + * eg. array( 'ATT_ID', 'REG_ID' ) |
|
62 | + * eg. array( '*' ) |
|
63 | + * If you want to use the columns in any WHERE, GROUP BY, or HAVING clauses, you must instead use the "complex" or |
|
64 | + * "structured" method. |
|
65 | + * ---- self::TYPE_COMPLEX array ---- |
|
66 | + * This is considered the "complex" type. In this case the array is indexed by arbitrary strings that serve as |
|
67 | + * column alias, and the value is an numerically indexed array where there are two values. The first value (0) is |
|
68 | + * the selection and the second value (1) is the data type. Data types must be one of the types defined in |
|
69 | + * EEM_Base::$_valid_wpdb_data_types. |
|
70 | + * eg. array( 'count' => array('count(REG_ID)', '%d') ) |
|
71 | + * Complex array configuration allows for using the column alias in any WHERE, GROUP BY, or HAVING clauses. |
|
72 | + * ---- self::TYPE_STRUCTURED array --- |
|
73 | + * This is considered the "structured" type. This type is similar to the complex type except that the array attached |
|
74 | + * to the column alias contains three values. The first value is the qualified column name (which can include |
|
75 | + * join syntax for models). The second value is the operator performed on the column (i.e. 'COUNT', 'SUM' etc)., |
|
76 | + * the third value is the data type. Note, if the select does not have an operator, you can use an empty string for |
|
77 | + * the second value. |
|
78 | + * Note: for now SUM is only for simple single column expressions (i.e. SUM(Transaction.TXN_total)) |
|
79 | + * eg. array( 'registration_count' => array('Registration.REG_ID', 'count', '%d') ); |
|
80 | + * |
|
81 | + * NOTE: mixing array types in the incoming $select will cause errors. |
|
82 | + * |
|
83 | + * @param array $selects |
|
84 | + * @throws InvalidArgumentException |
|
85 | + */ |
|
86 | + public function __construct(array $selects) |
|
87 | + { |
|
88 | + $this->original_selects = $selects; |
|
89 | + $this->deriveType($selects); |
|
90 | + $this->deriveParts($selects); |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * Derives what type of custom select has been sent in. |
|
96 | + * @param array $selects |
|
97 | + * @throws InvalidArgumentException |
|
98 | + */ |
|
99 | + private function deriveType(array $selects) |
|
100 | + { |
|
101 | + // first if the first key for this array is an integer then its coming in as a simple format, so we'll also |
|
102 | + // ensure all elements of the array are simple. |
|
103 | + if (is_int(key($selects))) { |
|
104 | + // let's ensure all keys are ints |
|
105 | + $invalid_keys = array_filter( |
|
106 | + array_keys($selects), |
|
107 | + function ($value) { |
|
108 | + return ! is_int($value); |
|
109 | + } |
|
110 | + ); |
|
111 | + if (! empty($invalid_keys)) { |
|
112 | + throw new InvalidArgumentException( |
|
113 | + sprintf( |
|
114 | + esc_html__( |
|
115 | + 'Incoming array looks like its formatted for "%1$s" type selects, however it has elements that are not indexed numerically', |
|
116 | + 'event_espresso' |
|
117 | + ), |
|
118 | + self::TYPE_SIMPLE |
|
119 | + ) |
|
120 | + ); |
|
121 | + } |
|
122 | + $this->type = self::TYPE_SIMPLE; |
|
123 | + return; |
|
124 | + } |
|
125 | + // made it here so that means we've got either complex or structured selects. Let's find out which by popping |
|
126 | + // the first array element off. |
|
127 | + $first_element = reset($selects); |
|
128 | + |
|
129 | + if (! is_array($first_element)) { |
|
130 | + throw new InvalidArgumentException( |
|
131 | + sprintf( |
|
132 | + esc_html__( |
|
133 | + 'Incoming array looks like its formatted as a "%1$s" or "%2$s" type. However, the values in the array must be arrays themselves and they are not.', |
|
134 | + 'event_espresso' |
|
135 | + ), |
|
136 | + self::TYPE_COMPLEX, |
|
137 | + self::TYPE_STRUCTURED |
|
138 | + ) |
|
139 | + ); |
|
140 | + } |
|
141 | + $this->type = count($first_element) === 2 |
|
142 | + ? self::TYPE_COMPLEX |
|
143 | + : self::TYPE_STRUCTURED; |
|
144 | + } |
|
145 | + |
|
146 | + |
|
147 | + /** |
|
148 | + * Sets up the various properties for the vo depending on type. |
|
149 | + * @param array $selects |
|
150 | + * @throws InvalidArgumentException |
|
151 | + */ |
|
152 | + private function deriveParts(array $selects) |
|
153 | + { |
|
154 | + $column_parts = array(); |
|
155 | + switch ($this->type) { |
|
156 | + case self::TYPE_SIMPLE: |
|
157 | + $column_parts = $selects; |
|
158 | + $this->column_aliases_in_select = $selects; |
|
159 | + break; |
|
160 | + case self::TYPE_COMPLEX: |
|
161 | + foreach ($selects as $alias => $parts) { |
|
162 | + $this->validateSelectValueForType($parts, $alias); |
|
163 | + $column_parts[] = "{$parts[0]} AS {$alias}"; |
|
164 | + $this->column_aliases_in_select[] = $alias; |
|
165 | + } |
|
166 | + break; |
|
167 | + case self::TYPE_STRUCTURED: |
|
168 | + foreach ($selects as $alias => $parts) { |
|
169 | + $this->validateSelectValueForType($parts, $alias); |
|
170 | + $column_parts[] = $parts[1] !== '' |
|
171 | + ? $this->assembleSelectStringWithOperator($parts, $alias) |
|
172 | + : "{$parts[0]} AS {$alias}"; |
|
173 | + $this->column_aliases_in_select[] = $alias; |
|
174 | + } |
|
175 | + break; |
|
176 | + } |
|
177 | + $this->columns_to_select_expression = implode(', ', $column_parts); |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * Validates self::TYPE_COMPLEX and self::TYPE_STRUCTURED select statement parts. |
|
183 | + * @param array $select_parts |
|
184 | + * @param string $alias |
|
185 | + * @throws InvalidArgumentException |
|
186 | + */ |
|
187 | + private function validateSelectValueForType(array $select_parts, $alias) |
|
188 | + { |
|
189 | + $valid_data_types = array('%d', '%s', '%f'); |
|
190 | + if (count($select_parts) !== $this->expectedSelectPartCountForType()) { |
|
191 | + throw new InvalidArgumentException( |
|
192 | + sprintf( |
|
193 | + esc_html__( |
|
194 | + 'The provided select part array for the %1$s column is expected to have a count of %2$d because the incoming select array is of type %3$s. However the count was %4$d.', |
|
195 | + 'event_espresso' |
|
196 | + ), |
|
197 | + $alias, |
|
198 | + $this->expectedSelectPartCountForType(), |
|
199 | + $this->type, |
|
200 | + count($select_parts) |
|
201 | + ) |
|
202 | + ); |
|
203 | + } |
|
204 | + // validate data type. |
|
205 | + $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
|
206 | + $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
|
207 | + |
|
208 | + if (! in_array($data_type, $valid_data_types, true)) { |
|
209 | + throw new InvalidArgumentException( |
|
210 | + sprintf( |
|
211 | + esc_html__( |
|
212 | + 'Datatype %1$s (for selection "%2$s" and alias "%3$s") is not a valid wpdb datatype (eg %%s)', |
|
213 | + 'event_espresso' |
|
214 | + ), |
|
215 | + $data_type, |
|
216 | + $select_parts[0], |
|
217 | + $alias, |
|
218 | + implode(', ', $valid_data_types) |
|
219 | + ) |
|
220 | + ); |
|
221 | + } |
|
222 | + } |
|
223 | + |
|
224 | + |
|
225 | + /** |
|
226 | + * Each type will have an expected count of array elements, this returns what that expected count is. |
|
227 | + * @param string $type |
|
228 | + * @return int |
|
229 | + */ |
|
230 | + private function expectedSelectPartCountForType($type = '') |
|
231 | + { |
|
232 | + $type = $type === '' ? $this->type : $type; |
|
233 | + $types_count_map = array( |
|
234 | + self::TYPE_COMPLEX => 2, |
|
235 | + self::TYPE_STRUCTURED => 3 |
|
236 | + ); |
|
237 | + return isset($types_count_map[$type]) ? $types_count_map[$type] : 0; |
|
238 | + } |
|
239 | + |
|
240 | + |
|
241 | + /** |
|
242 | + * Prepares the select statement part for for structured type selects. |
|
243 | + * @param array $select_parts |
|
244 | + * @param string $alias |
|
245 | + * @return string |
|
246 | + * @throws InvalidArgumentException |
|
247 | + */ |
|
248 | + private function assembleSelectStringWithOperator(array $select_parts, $alias) |
|
249 | + { |
|
250 | + $operator = strtoupper($select_parts[1]); |
|
251 | + // validate operator |
|
252 | + if (! in_array($operator, $this->valid_operators, true)) { |
|
253 | + throw new InvalidArgumentException( |
|
254 | + sprintf( |
|
255 | + esc_html__( |
|
256 | + 'An invalid operator has been provided (%1$s) for the column %2$s. Valid operators must be one of the following: %3$s.', |
|
257 | + 'event_espresso' |
|
258 | + ), |
|
259 | + $operator, |
|
260 | + $alias, |
|
261 | + implode(', ', $this->valid_operators) |
|
262 | + ) |
|
263 | + ); |
|
264 | + } |
|
265 | + return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * Return the datatype from the given select part. |
|
271 | + * Remember the select_part has already been validated on object instantiation. |
|
272 | + * @param array $select_part |
|
273 | + * @return string |
|
274 | + */ |
|
275 | + private function getDataTypeForSelectType(array $select_part) |
|
276 | + { |
|
277 | + switch ($this->type) { |
|
278 | + case self::TYPE_COMPLEX: |
|
279 | + return $select_part[1]; |
|
280 | + case self::TYPE_STRUCTURED: |
|
281 | + return $select_part[2]; |
|
282 | + default: |
|
283 | + return ''; |
|
284 | + } |
|
285 | + } |
|
286 | + |
|
287 | + |
|
288 | + /** |
|
289 | + * Returns the original select array sent into the VO. |
|
290 | + * @return array |
|
291 | + */ |
|
292 | + public function originalSelects() |
|
293 | + { |
|
294 | + return $this->original_selects; |
|
295 | + } |
|
296 | + |
|
297 | + |
|
298 | + /** |
|
299 | + * Returns the final assembled select expression derived from the incoming select array. |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function columnsToSelectExpression() |
|
303 | + { |
|
304 | + return $this->columns_to_select_expression; |
|
305 | + } |
|
306 | + |
|
307 | + |
|
308 | + /** |
|
309 | + * Returns all the column aliases derived from the incoming select array. |
|
310 | + * @return array |
|
311 | + */ |
|
312 | + public function columnAliases() |
|
313 | + { |
|
314 | + return $this->column_aliases_in_select; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * Returns the enum type for the incoming select array. |
|
320 | + * @return string |
|
321 | + */ |
|
322 | + public function type() |
|
323 | + { |
|
324 | + return $this->type; |
|
325 | + } |
|
326 | + |
|
327 | + |
|
328 | + |
|
329 | + /** |
|
330 | + * Return the datatype for the given column_alias |
|
331 | + * @param string $column_alias |
|
332 | + * @return string (if there's no data type we return string as the default). |
|
333 | + */ |
|
334 | + public function getDataTypeForAlias($column_alias) |
|
335 | + { |
|
336 | + if (isset($this->original_selects[$column_alias]) |
|
337 | + && in_array($column_alias, $this->columnAliases(), true) |
|
338 | + ) { |
|
339 | + return $this->getDataTypeForSelectType($this->original_selects[$column_alias]); |
|
340 | + } |
|
341 | + return '%s'; |
|
342 | + } |
|
343 | 343 | } |
@@ -104,11 +104,11 @@ discard block |
||
104 | 104 | // let's ensure all keys are ints |
105 | 105 | $invalid_keys = array_filter( |
106 | 106 | array_keys($selects), |
107 | - function ($value) { |
|
107 | + function($value) { |
|
108 | 108 | return ! is_int($value); |
109 | 109 | } |
110 | 110 | ); |
111 | - if (! empty($invalid_keys)) { |
|
111 | + if ( ! empty($invalid_keys)) { |
|
112 | 112 | throw new InvalidArgumentException( |
113 | 113 | sprintf( |
114 | 114 | esc_html__( |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | // the first array element off. |
127 | 127 | $first_element = reset($selects); |
128 | 128 | |
129 | - if (! is_array($first_element)) { |
|
129 | + if ( ! is_array($first_element)) { |
|
130 | 130 | throw new InvalidArgumentException( |
131 | 131 | sprintf( |
132 | 132 | esc_html__( |
@@ -205,7 +205,7 @@ discard block |
||
205 | 205 | $data_type = $this->type === self::TYPE_COMPLEX ? $select_parts[1] : ''; |
206 | 206 | $data_type = $this->type === self::TYPE_STRUCTURED ? $select_parts[2] : $data_type; |
207 | 207 | |
208 | - if (! in_array($data_type, $valid_data_types, true)) { |
|
208 | + if ( ! in_array($data_type, $valid_data_types, true)) { |
|
209 | 209 | throw new InvalidArgumentException( |
210 | 210 | sprintf( |
211 | 211 | esc_html__( |
@@ -249,7 +249,7 @@ discard block |
||
249 | 249 | { |
250 | 250 | $operator = strtoupper($select_parts[1]); |
251 | 251 | // validate operator |
252 | - if (! in_array($operator, $this->valid_operators, true)) { |
|
252 | + if ( ! in_array($operator, $this->valid_operators, true)) { |
|
253 | 253 | throw new InvalidArgumentException( |
254 | 254 | sprintf( |
255 | 255 | esc_html__( |
@@ -262,7 +262,7 @@ discard block |
||
262 | 262 | ) |
263 | 263 | ); |
264 | 264 | } |
265 | - return $operator . '(' . $select_parts[0] . ') AS ' . $alias; |
|
265 | + return $operator.'('.$select_parts[0].') AS '.$alias; |
|
266 | 266 | } |
267 | 267 | |
268 | 268 |
@@ -17,198 +17,198 @@ |
||
17 | 17 | class Url |
18 | 18 | { |
19 | 19 | |
20 | - /** |
|
21 | - * @var string $scheme |
|
22 | - */ |
|
23 | - private $scheme; |
|
24 | - |
|
25 | - /** |
|
26 | - * @var string $host |
|
27 | - */ |
|
28 | - private $host; |
|
29 | - |
|
30 | - /** |
|
31 | - * @var string $path |
|
32 | - */ |
|
33 | - private $path; |
|
34 | - |
|
35 | - /** |
|
36 | - * @var string $query |
|
37 | - */ |
|
38 | - private $query; |
|
39 | - |
|
40 | - /** |
|
41 | - * @var string $fragment |
|
42 | - */ |
|
43 | - private $fragment; |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * Url constructor. |
|
48 | - * |
|
49 | - * @param $url |
|
50 | - * @throws InvalidArgumentException |
|
51 | - */ |
|
52 | - public function __construct($url) |
|
53 | - { |
|
54 | - if (! filter_var( |
|
55 | - $url, |
|
56 | - FILTER_VALIDATE_URL, |
|
57 | - array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED) |
|
58 | - )) { |
|
59 | - throw new InvalidArgumentException( |
|
60 | - esc_html__( |
|
61 | - 'Invalid URL. Both the "Scheme" and "Host" are required.', |
|
62 | - 'event_espresso' |
|
63 | - ) |
|
64 | - ); |
|
65 | - } |
|
66 | - $url = parse_url($url); |
|
67 | - $this->setScheme($url); |
|
68 | - $this->setHost($url); |
|
69 | - $this->setPath($url); |
|
70 | - $this->setQuery($url); |
|
71 | - $this->setFragment($url); |
|
72 | - } |
|
73 | - |
|
74 | - |
|
75 | - /** |
|
76 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
77 | - * will return a string like: 'abc://' |
|
78 | - * |
|
79 | - * @return string |
|
80 | - */ |
|
81 | - public function scheme() |
|
82 | - { |
|
83 | - return $this->scheme; |
|
84 | - } |
|
85 | - |
|
86 | - |
|
87 | - /** |
|
88 | - * @param array $url |
|
89 | - */ |
|
90 | - private function setScheme($url) |
|
91 | - { |
|
92 | - $this->scheme = $url['scheme'] . '://'; |
|
93 | - } |
|
94 | - |
|
95 | - |
|
96 | - /** |
|
97 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
98 | - * will return a string like: 'example.com' |
|
99 | - * |
|
100 | - * @return string |
|
101 | - */ |
|
102 | - public function host() |
|
103 | - { |
|
104 | - return $this->host; |
|
105 | - } |
|
106 | - |
|
107 | - |
|
108 | - /** |
|
109 | - * @param array $url |
|
110 | - */ |
|
111 | - private function setHost($url) |
|
112 | - { |
|
113 | - $this->host = $url['host']; |
|
114 | - } |
|
115 | - |
|
116 | - |
|
117 | - /** |
|
118 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
119 | - * will return a string like: '/path/data' |
|
120 | - * |
|
121 | - * @return string |
|
122 | - */ |
|
123 | - public function path() |
|
124 | - { |
|
125 | - return $this->path; |
|
126 | - } |
|
127 | - |
|
128 | - |
|
129 | - /** |
|
130 | - * @param array $url |
|
131 | - */ |
|
132 | - private function setPath($url) |
|
133 | - { |
|
134 | - $this->path = isset($url['path']) ? $url['path'] : ''; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
140 | - * will return a string like: '?key=value' |
|
141 | - * |
|
142 | - * @return string |
|
143 | - */ |
|
144 | - public function queryString() |
|
145 | - { |
|
146 | - return $this->query !== '' ? '?' . $this->query : ''; |
|
147 | - } |
|
148 | - |
|
149 | - |
|
150 | - /** |
|
151 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
152 | - * will return an array like: array('key' => 'value') |
|
153 | - * |
|
154 | - * @return array |
|
155 | - */ |
|
156 | - public function queryParams() |
|
157 | - { |
|
158 | - return wp_parse_args($this->query); |
|
159 | - } |
|
160 | - |
|
161 | - |
|
162 | - /** |
|
163 | - * @param array $url |
|
164 | - */ |
|
165 | - private function setQuery($url) |
|
166 | - { |
|
167 | - $this->query = isset($url['query']) ? $url['query'] : ''; |
|
168 | - } |
|
169 | - |
|
170 | - |
|
171 | - /** |
|
172 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
173 | - * will return a string like: '#id' |
|
174 | - * |
|
175 | - * @return string |
|
176 | - */ |
|
177 | - public function fragment() |
|
178 | - { |
|
179 | - return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
180 | - } |
|
181 | - |
|
182 | - |
|
183 | - /** |
|
184 | - * @param array $url |
|
185 | - */ |
|
186 | - private function setFragment($url) |
|
187 | - { |
|
188 | - $this->fragment = isset($url['fragment']) ? $url['fragment'] : ''; |
|
189 | - } |
|
190 | - |
|
191 | - |
|
192 | - /** |
|
193 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
194 | - * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
195 | - * |
|
196 | - * @return string |
|
197 | - */ |
|
198 | - public function getFullUrl() |
|
199 | - { |
|
200 | - return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
201 | - } |
|
202 | - |
|
203 | - |
|
204 | - /** |
|
205 | - * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
206 | - * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
207 | - * |
|
208 | - * @return string |
|
209 | - */ |
|
210 | - public function __toString() |
|
211 | - { |
|
212 | - return $this->getFullUrl(); |
|
213 | - } |
|
20 | + /** |
|
21 | + * @var string $scheme |
|
22 | + */ |
|
23 | + private $scheme; |
|
24 | + |
|
25 | + /** |
|
26 | + * @var string $host |
|
27 | + */ |
|
28 | + private $host; |
|
29 | + |
|
30 | + /** |
|
31 | + * @var string $path |
|
32 | + */ |
|
33 | + private $path; |
|
34 | + |
|
35 | + /** |
|
36 | + * @var string $query |
|
37 | + */ |
|
38 | + private $query; |
|
39 | + |
|
40 | + /** |
|
41 | + * @var string $fragment |
|
42 | + */ |
|
43 | + private $fragment; |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * Url constructor. |
|
48 | + * |
|
49 | + * @param $url |
|
50 | + * @throws InvalidArgumentException |
|
51 | + */ |
|
52 | + public function __construct($url) |
|
53 | + { |
|
54 | + if (! filter_var( |
|
55 | + $url, |
|
56 | + FILTER_VALIDATE_URL, |
|
57 | + array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED) |
|
58 | + )) { |
|
59 | + throw new InvalidArgumentException( |
|
60 | + esc_html__( |
|
61 | + 'Invalid URL. Both the "Scheme" and "Host" are required.', |
|
62 | + 'event_espresso' |
|
63 | + ) |
|
64 | + ); |
|
65 | + } |
|
66 | + $url = parse_url($url); |
|
67 | + $this->setScheme($url); |
|
68 | + $this->setHost($url); |
|
69 | + $this->setPath($url); |
|
70 | + $this->setQuery($url); |
|
71 | + $this->setFragment($url); |
|
72 | + } |
|
73 | + |
|
74 | + |
|
75 | + /** |
|
76 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
77 | + * will return a string like: 'abc://' |
|
78 | + * |
|
79 | + * @return string |
|
80 | + */ |
|
81 | + public function scheme() |
|
82 | + { |
|
83 | + return $this->scheme; |
|
84 | + } |
|
85 | + |
|
86 | + |
|
87 | + /** |
|
88 | + * @param array $url |
|
89 | + */ |
|
90 | + private function setScheme($url) |
|
91 | + { |
|
92 | + $this->scheme = $url['scheme'] . '://'; |
|
93 | + } |
|
94 | + |
|
95 | + |
|
96 | + /** |
|
97 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
98 | + * will return a string like: 'example.com' |
|
99 | + * |
|
100 | + * @return string |
|
101 | + */ |
|
102 | + public function host() |
|
103 | + { |
|
104 | + return $this->host; |
|
105 | + } |
|
106 | + |
|
107 | + |
|
108 | + /** |
|
109 | + * @param array $url |
|
110 | + */ |
|
111 | + private function setHost($url) |
|
112 | + { |
|
113 | + $this->host = $url['host']; |
|
114 | + } |
|
115 | + |
|
116 | + |
|
117 | + /** |
|
118 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
119 | + * will return a string like: '/path/data' |
|
120 | + * |
|
121 | + * @return string |
|
122 | + */ |
|
123 | + public function path() |
|
124 | + { |
|
125 | + return $this->path; |
|
126 | + } |
|
127 | + |
|
128 | + |
|
129 | + /** |
|
130 | + * @param array $url |
|
131 | + */ |
|
132 | + private function setPath($url) |
|
133 | + { |
|
134 | + $this->path = isset($url['path']) ? $url['path'] : ''; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
140 | + * will return a string like: '?key=value' |
|
141 | + * |
|
142 | + * @return string |
|
143 | + */ |
|
144 | + public function queryString() |
|
145 | + { |
|
146 | + return $this->query !== '' ? '?' . $this->query : ''; |
|
147 | + } |
|
148 | + |
|
149 | + |
|
150 | + /** |
|
151 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
152 | + * will return an array like: array('key' => 'value') |
|
153 | + * |
|
154 | + * @return array |
|
155 | + */ |
|
156 | + public function queryParams() |
|
157 | + { |
|
158 | + return wp_parse_args($this->query); |
|
159 | + } |
|
160 | + |
|
161 | + |
|
162 | + /** |
|
163 | + * @param array $url |
|
164 | + */ |
|
165 | + private function setQuery($url) |
|
166 | + { |
|
167 | + $this->query = isset($url['query']) ? $url['query'] : ''; |
|
168 | + } |
|
169 | + |
|
170 | + |
|
171 | + /** |
|
172 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
173 | + * will return a string like: '#id' |
|
174 | + * |
|
175 | + * @return string |
|
176 | + */ |
|
177 | + public function fragment() |
|
178 | + { |
|
179 | + return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
180 | + } |
|
181 | + |
|
182 | + |
|
183 | + /** |
|
184 | + * @param array $url |
|
185 | + */ |
|
186 | + private function setFragment($url) |
|
187 | + { |
|
188 | + $this->fragment = isset($url['fragment']) ? $url['fragment'] : ''; |
|
189 | + } |
|
190 | + |
|
191 | + |
|
192 | + /** |
|
193 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
194 | + * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
195 | + * |
|
196 | + * @return string |
|
197 | + */ |
|
198 | + public function getFullUrl() |
|
199 | + { |
|
200 | + return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
201 | + } |
|
202 | + |
|
203 | + |
|
204 | + /** |
|
205 | + * For a URL like: abc://username:[email protected]:123/path/data?key=value#id |
|
206 | + * will return a string like: 'abc://example.com/path/data?key=value#id' |
|
207 | + * |
|
208 | + * @return string |
|
209 | + */ |
|
210 | + public function __toString() |
|
211 | + { |
|
212 | + return $this->getFullUrl(); |
|
213 | + } |
|
214 | 214 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __construct($url) |
53 | 53 | { |
54 | - if (! filter_var( |
|
54 | + if ( ! filter_var( |
|
55 | 55 | $url, |
56 | 56 | FILTER_VALIDATE_URL, |
57 | 57 | array(FILTER_FLAG_SCHEME_REQUIRED, FILTER_FLAG_HOST_REQUIRED) |
@@ -89,7 +89,7 @@ discard block |
||
89 | 89 | */ |
90 | 90 | private function setScheme($url) |
91 | 91 | { |
92 | - $this->scheme = $url['scheme'] . '://'; |
|
92 | + $this->scheme = $url['scheme'].'://'; |
|
93 | 93 | } |
94 | 94 | |
95 | 95 | |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | */ |
144 | 144 | public function queryString() |
145 | 145 | { |
146 | - return $this->query !== '' ? '?' . $this->query : ''; |
|
146 | + return $this->query !== '' ? '?'.$this->query : ''; |
|
147 | 147 | } |
148 | 148 | |
149 | 149 | |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | */ |
177 | 177 | public function fragment() |
178 | 178 | { |
179 | - return $this->fragment !== '' ? '#' . $this->fragment : ''; |
|
179 | + return $this->fragment !== '' ? '#'.$this->fragment : ''; |
|
180 | 180 | } |
181 | 181 | |
182 | 182 | |
@@ -197,7 +197,7 @@ discard block |
||
197 | 197 | */ |
198 | 198 | public function getFullUrl() |
199 | 199 | { |
200 | - return $this->scheme() . $this->host() . $this->path() . $this->queryString() . $this->fragment(); |
|
200 | + return $this->scheme().$this->host().$this->path().$this->queryString().$this->fragment(); |
|
201 | 201 | } |
202 | 202 | |
203 | 203 |
@@ -20,98 +20,98 @@ |
||
20 | 20 | class SessionLifespan |
21 | 21 | { |
22 | 22 | |
23 | - /** |
|
24 | - * how long an EE session lasts in seconds |
|
25 | - * default session lifespan of 1 hour (for not so instant IPNs) |
|
26 | - * |
|
27 | - * @var int $lifespan |
|
28 | - */ |
|
29 | - private $lifespan; |
|
30 | - |
|
31 | - |
|
32 | - /** |
|
33 | - * SessionLifespan constructor. |
|
34 | - * |
|
35 | - * @param int $lifespan |
|
36 | - * @throws DomainException |
|
37 | - */ |
|
38 | - public function __construct($lifespan = 0) |
|
39 | - { |
|
40 | - $lifespan = absint($lifespan); |
|
41 | - $lifespan = $lifespan > 0 ? $lifespan : (int) HOUR_IN_SECONDS; |
|
42 | - $this->setLifespan($lifespan); |
|
43 | - } |
|
44 | - |
|
45 | - |
|
46 | - /** |
|
47 | - * @param int $lifespan |
|
48 | - * @throws DomainException |
|
49 | - */ |
|
50 | - protected function setLifespan($lifespan) |
|
51 | - { |
|
52 | - if ($lifespan < 60) { |
|
53 | - throw new DomainException( |
|
54 | - esc_html__( |
|
55 | - 'The session lifespan needs to be at least 60 seconds, and even that is extremely short', |
|
56 | - 'event_espresso' |
|
57 | - ) |
|
58 | - ); |
|
59 | - } |
|
60 | - $this->lifespan = apply_filters( |
|
61 | - 'FHEE__EventEspresso_core_domain_values_session_SessionLifespan__setLifespan___lifespan', |
|
62 | - // apply legacy filter for now but add doing it wrong notice in future |
|
63 | - apply_filters( |
|
64 | - 'FHEE__EE_Session__construct___lifespan', |
|
65 | - $lifespan |
|
66 | - ) |
|
67 | - ) + 1; |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return int |
|
73 | - */ |
|
74 | - public function inSeconds() |
|
75 | - { |
|
76 | - return $this->lifespan; |
|
77 | - } |
|
78 | - |
|
79 | - |
|
80 | - /** |
|
81 | - * @param string $separator |
|
82 | - * @return string |
|
83 | - */ |
|
84 | - public function inHoursMinutesSeconds($separator = ':') |
|
85 | - { |
|
86 | - return sprintf( |
|
87 | - '%02d%s%02d%s%02d', |
|
88 | - floor($this->lifespan / 3600), |
|
89 | - $separator, |
|
90 | - ($this->lifespan / 60) % 60, |
|
91 | - $separator, |
|
92 | - $this->lifespan % 60 |
|
93 | - ); |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * Returns a timestamp for when the session would expire based on this lifespan |
|
99 | - * |
|
100 | - * @param bool $utc If true, displays expiration in UTC |
|
101 | - * If false, displays expiration in local time |
|
102 | - * @return int |
|
103 | - */ |
|
104 | - public function expiration($utc = true) |
|
105 | - { |
|
106 | - return (int) current_time('timestamp', $utc) - $this->lifespan; |
|
107 | - } |
|
108 | - |
|
109 | - |
|
110 | - /** |
|
111 | - * @return string |
|
112 | - */ |
|
113 | - public function __toString() |
|
114 | - { |
|
115 | - return (string) $this->inSeconds(); |
|
116 | - } |
|
23 | + /** |
|
24 | + * how long an EE session lasts in seconds |
|
25 | + * default session lifespan of 1 hour (for not so instant IPNs) |
|
26 | + * |
|
27 | + * @var int $lifespan |
|
28 | + */ |
|
29 | + private $lifespan; |
|
30 | + |
|
31 | + |
|
32 | + /** |
|
33 | + * SessionLifespan constructor. |
|
34 | + * |
|
35 | + * @param int $lifespan |
|
36 | + * @throws DomainException |
|
37 | + */ |
|
38 | + public function __construct($lifespan = 0) |
|
39 | + { |
|
40 | + $lifespan = absint($lifespan); |
|
41 | + $lifespan = $lifespan > 0 ? $lifespan : (int) HOUR_IN_SECONDS; |
|
42 | + $this->setLifespan($lifespan); |
|
43 | + } |
|
44 | + |
|
45 | + |
|
46 | + /** |
|
47 | + * @param int $lifespan |
|
48 | + * @throws DomainException |
|
49 | + */ |
|
50 | + protected function setLifespan($lifespan) |
|
51 | + { |
|
52 | + if ($lifespan < 60) { |
|
53 | + throw new DomainException( |
|
54 | + esc_html__( |
|
55 | + 'The session lifespan needs to be at least 60 seconds, and even that is extremely short', |
|
56 | + 'event_espresso' |
|
57 | + ) |
|
58 | + ); |
|
59 | + } |
|
60 | + $this->lifespan = apply_filters( |
|
61 | + 'FHEE__EventEspresso_core_domain_values_session_SessionLifespan__setLifespan___lifespan', |
|
62 | + // apply legacy filter for now but add doing it wrong notice in future |
|
63 | + apply_filters( |
|
64 | + 'FHEE__EE_Session__construct___lifespan', |
|
65 | + $lifespan |
|
66 | + ) |
|
67 | + ) + 1; |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return int |
|
73 | + */ |
|
74 | + public function inSeconds() |
|
75 | + { |
|
76 | + return $this->lifespan; |
|
77 | + } |
|
78 | + |
|
79 | + |
|
80 | + /** |
|
81 | + * @param string $separator |
|
82 | + * @return string |
|
83 | + */ |
|
84 | + public function inHoursMinutesSeconds($separator = ':') |
|
85 | + { |
|
86 | + return sprintf( |
|
87 | + '%02d%s%02d%s%02d', |
|
88 | + floor($this->lifespan / 3600), |
|
89 | + $separator, |
|
90 | + ($this->lifespan / 60) % 60, |
|
91 | + $separator, |
|
92 | + $this->lifespan % 60 |
|
93 | + ); |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * Returns a timestamp for when the session would expire based on this lifespan |
|
99 | + * |
|
100 | + * @param bool $utc If true, displays expiration in UTC |
|
101 | + * If false, displays expiration in local time |
|
102 | + * @return int |
|
103 | + */ |
|
104 | + public function expiration($utc = true) |
|
105 | + { |
|
106 | + return (int) current_time('timestamp', $utc) - $this->lifespan; |
|
107 | + } |
|
108 | + |
|
109 | + |
|
110 | + /** |
|
111 | + * @return string |
|
112 | + */ |
|
113 | + public function __toString() |
|
114 | + { |
|
115 | + return (string) $this->inSeconds(); |
|
116 | + } |
|
117 | 117 | } |
@@ -16,295 +16,295 @@ |
||
16 | 16 | class Version |
17 | 17 | { |
18 | 18 | |
19 | - const RELEASE_TYPE_RC = 'rc'; |
|
20 | - |
|
21 | - const RELEASE_TYPE_BETA = 'beta'; |
|
22 | - |
|
23 | - const RELEASE_TYPE_DECAF = 'decaf'; |
|
24 | - |
|
25 | - const RELEASE_TYPE_PROD = 'p'; |
|
26 | - |
|
27 | - /** |
|
28 | - * @var int $major |
|
29 | - */ |
|
30 | - private $major; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var int $minor |
|
34 | - */ |
|
35 | - private $minor; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var int $patch |
|
39 | - */ |
|
40 | - private $patch; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string $release |
|
44 | - */ |
|
45 | - private $release; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var int $build |
|
49 | - */ |
|
50 | - private $build; |
|
51 | - |
|
52 | - |
|
53 | - /** |
|
54 | - * Version constructor. |
|
55 | - * |
|
56 | - * @param int $major |
|
57 | - * @param int $minor |
|
58 | - * @param int $patch |
|
59 | - * @param string $release |
|
60 | - * @param int $build |
|
61 | - * @throws InvalidDataTypeException |
|
62 | - * @throws InvalidArgumentException |
|
63 | - */ |
|
64 | - public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0) |
|
65 | - { |
|
66 | - $this->setMajor($major); |
|
67 | - $this->setMinor($minor); |
|
68 | - $this->setPatch($patch); |
|
69 | - $this->setRelease($release); |
|
70 | - $this->setBuild($build); |
|
71 | - } |
|
72 | - |
|
73 | - |
|
74 | - /** |
|
75 | - * @param string $version_string |
|
76 | - * @return Version |
|
77 | - * @throws InvalidArgumentException |
|
78 | - */ |
|
79 | - public static function fromString($version_string) |
|
80 | - { |
|
81 | - // compare incoming version string against the lowest possible valid version |
|
82 | - if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
83 | - throw new InvalidArgumentException( |
|
84 | - sprintf( |
|
85 | - esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
86 | - $version_string |
|
87 | - ) |
|
88 | - ); |
|
89 | - } |
|
90 | - // break apart incoming version string |
|
91 | - $version_parts = explode('.', $version_string); |
|
92 | - // verify that version string at least contains {major}.{minor}.{patch} |
|
93 | - if (count($version_parts) < 3) { |
|
94 | - throw new InvalidArgumentException( |
|
95 | - sprintf( |
|
96 | - esc_html__( |
|
97 | - 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
98 | - 'event_espresso' |
|
99 | - ), |
|
100 | - $version_string |
|
101 | - ) |
|
102 | - ); |
|
103 | - } |
|
104 | - // add defaults for missing pieces |
|
105 | - $version_parts += array(0,0,0,'p',0); |
|
106 | - // reassign to individual variables |
|
107 | - list($major, $minor, $patch, $release, $build) = $version_parts; |
|
108 | - return new Version( |
|
109 | - (int) $major, |
|
110 | - (int) $minor, |
|
111 | - (int) $patch, |
|
112 | - $release, |
|
113 | - (int) $build |
|
114 | - ); |
|
115 | - } |
|
116 | - |
|
117 | - |
|
118 | - /** |
|
119 | - * @return int |
|
120 | - */ |
|
121 | - public function major() |
|
122 | - { |
|
123 | - return $this->major; |
|
124 | - } |
|
125 | - |
|
126 | - |
|
127 | - /** |
|
128 | - * @param int|string $major |
|
129 | - * @throws InvalidDataTypeException |
|
130 | - */ |
|
131 | - private function setMajor($major) |
|
132 | - { |
|
133 | - if (! is_int($major)) { |
|
134 | - throw new InvalidDataTypeException( |
|
135 | - '$major', |
|
136 | - $major, |
|
137 | - 'integer' |
|
138 | - ); |
|
139 | - } |
|
140 | - $this->major = absint($major); |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @return int |
|
146 | - */ |
|
147 | - public function minor() |
|
148 | - { |
|
149 | - return $this->minor; |
|
150 | - } |
|
151 | - |
|
152 | - |
|
153 | - /** |
|
154 | - * @param int|string $minor |
|
155 | - * @throws InvalidDataTypeException |
|
156 | - */ |
|
157 | - private function setMinor($minor) |
|
158 | - { |
|
159 | - if (! is_int($minor)) { |
|
160 | - throw new InvalidDataTypeException( |
|
161 | - '$minor', |
|
162 | - $minor, |
|
163 | - 'integer' |
|
164 | - ); |
|
165 | - } |
|
166 | - $this->minor = absint($minor); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * @return int |
|
172 | - */ |
|
173 | - public function patch() |
|
174 | - { |
|
175 | - return $this->patch; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @param int|string $patch |
|
181 | - * @throws InvalidDataTypeException |
|
182 | - */ |
|
183 | - private function setPatch($patch) |
|
184 | - { |
|
185 | - if (! is_int($patch)) { |
|
186 | - throw new InvalidDataTypeException( |
|
187 | - '$patch', |
|
188 | - $patch, |
|
189 | - 'integer' |
|
190 | - ); |
|
191 | - } |
|
192 | - $this->patch = absint($patch); |
|
193 | - } |
|
194 | - |
|
195 | - |
|
196 | - /** |
|
197 | - * @return string |
|
198 | - */ |
|
199 | - public function release() |
|
200 | - { |
|
201 | - return $this->release; |
|
202 | - } |
|
203 | - |
|
204 | - |
|
205 | - /** |
|
206 | - * @param string $release |
|
207 | - * @throws InvalidArgumentException |
|
208 | - */ |
|
209 | - private function setRelease($release) |
|
210 | - { |
|
211 | - $valid_release_types = array( |
|
212 | - Version::RELEASE_TYPE_RC, |
|
213 | - Version::RELEASE_TYPE_BETA, |
|
214 | - Version::RELEASE_TYPE_DECAF, |
|
215 | - Version::RELEASE_TYPE_PROD, |
|
216 | - ); |
|
217 | - if (! in_array($release, $valid_release_types, true)) { |
|
218 | - throw new InvalidArgumentException( |
|
219 | - sprintf( |
|
220 | - esc_html__( |
|
221 | - '"%1$s" is not a valid release type. Please use one of the following values: %2$s', |
|
222 | - 'event_espresso' |
|
223 | - ), |
|
224 | - $release, |
|
225 | - implode(', ', $valid_release_types) |
|
226 | - ) |
|
227 | - ); |
|
228 | - } |
|
229 | - $this->release = $release; |
|
230 | - } |
|
231 | - |
|
232 | - |
|
233 | - /** |
|
234 | - * @return int |
|
235 | - */ |
|
236 | - public function build() |
|
237 | - { |
|
238 | - return $this->build; |
|
239 | - } |
|
240 | - |
|
241 | - |
|
242 | - /** |
|
243 | - * @param int|string $build |
|
244 | - * @throws InvalidDataTypeException |
|
245 | - */ |
|
246 | - private function setBuild($build) |
|
247 | - { |
|
248 | - if (! is_int($build)) { |
|
249 | - throw new InvalidDataTypeException( |
|
250 | - '$build', |
|
251 | - $build, |
|
252 | - 'integer' |
|
253 | - ); |
|
254 | - } |
|
255 | - $this->build = absint($build); |
|
256 | - } |
|
257 | - |
|
258 | - |
|
259 | - /** |
|
260 | - * @param Version $other_version |
|
261 | - * @return int |
|
262 | - */ |
|
263 | - public function compare(Version $other_version) |
|
264 | - { |
|
265 | - return version_compare((string) $this, (string) $other_version); |
|
266 | - } |
|
267 | - |
|
268 | - |
|
269 | - /** |
|
270 | - * @param Version $other_version |
|
271 | - * @return bool |
|
272 | - */ |
|
273 | - public function equals(Version $other_version) |
|
274 | - { |
|
275 | - return version_compare((string) $this, (string) $other_version, '=='); |
|
276 | - } |
|
277 | - |
|
278 | - |
|
279 | - /** |
|
280 | - * @param Version $other_version |
|
281 | - * @return bool |
|
282 | - */ |
|
283 | - public function newerThan(Version $other_version) |
|
284 | - { |
|
285 | - return version_compare((string) $this, (string) $other_version, '>'); |
|
286 | - } |
|
287 | - |
|
288 | - |
|
289 | - /** |
|
290 | - * @param Version $other_version |
|
291 | - * @return bool |
|
292 | - */ |
|
293 | - public function olderThan(Version $other_version) |
|
294 | - { |
|
295 | - return version_compare((string) $this, (string) $other_version, '<'); |
|
296 | - } |
|
297 | - |
|
298 | - |
|
299 | - /** |
|
300 | - * @return string |
|
301 | - */ |
|
302 | - public function __toString() |
|
303 | - { |
|
304 | - $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
|
305 | - if ($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
|
306 | - $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
307 | - } |
|
308 | - return $version_string; |
|
309 | - } |
|
19 | + const RELEASE_TYPE_RC = 'rc'; |
|
20 | + |
|
21 | + const RELEASE_TYPE_BETA = 'beta'; |
|
22 | + |
|
23 | + const RELEASE_TYPE_DECAF = 'decaf'; |
|
24 | + |
|
25 | + const RELEASE_TYPE_PROD = 'p'; |
|
26 | + |
|
27 | + /** |
|
28 | + * @var int $major |
|
29 | + */ |
|
30 | + private $major; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var int $minor |
|
34 | + */ |
|
35 | + private $minor; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var int $patch |
|
39 | + */ |
|
40 | + private $patch; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string $release |
|
44 | + */ |
|
45 | + private $release; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var int $build |
|
49 | + */ |
|
50 | + private $build; |
|
51 | + |
|
52 | + |
|
53 | + /** |
|
54 | + * Version constructor. |
|
55 | + * |
|
56 | + * @param int $major |
|
57 | + * @param int $minor |
|
58 | + * @param int $patch |
|
59 | + * @param string $release |
|
60 | + * @param int $build |
|
61 | + * @throws InvalidDataTypeException |
|
62 | + * @throws InvalidArgumentException |
|
63 | + */ |
|
64 | + public function __construct($major, $minor, $patch, $release = Version::RELEASE_TYPE_PROD, $build = 0) |
|
65 | + { |
|
66 | + $this->setMajor($major); |
|
67 | + $this->setMinor($minor); |
|
68 | + $this->setPatch($patch); |
|
69 | + $this->setRelease($release); |
|
70 | + $this->setBuild($build); |
|
71 | + } |
|
72 | + |
|
73 | + |
|
74 | + /** |
|
75 | + * @param string $version_string |
|
76 | + * @return Version |
|
77 | + * @throws InvalidArgumentException |
|
78 | + */ |
|
79 | + public static function fromString($version_string) |
|
80 | + { |
|
81 | + // compare incoming version string against the lowest possible valid version |
|
82 | + if (version_compare($version_string, '0.0.1.dev.001', '<')) { |
|
83 | + throw new InvalidArgumentException( |
|
84 | + sprintf( |
|
85 | + esc_html__('"%1$s" is not a valid version string', 'event_espresso'), |
|
86 | + $version_string |
|
87 | + ) |
|
88 | + ); |
|
89 | + } |
|
90 | + // break apart incoming version string |
|
91 | + $version_parts = explode('.', $version_string); |
|
92 | + // verify that version string at least contains {major}.{minor}.{patch} |
|
93 | + if (count($version_parts) < 3) { |
|
94 | + throw new InvalidArgumentException( |
|
95 | + sprintf( |
|
96 | + esc_html__( |
|
97 | + 'At minimum, a version string needs to be in a "{major}.{minor}.{patch}" format, therefore "%1$s" is not valid', |
|
98 | + 'event_espresso' |
|
99 | + ), |
|
100 | + $version_string |
|
101 | + ) |
|
102 | + ); |
|
103 | + } |
|
104 | + // add defaults for missing pieces |
|
105 | + $version_parts += array(0,0,0,'p',0); |
|
106 | + // reassign to individual variables |
|
107 | + list($major, $minor, $patch, $release, $build) = $version_parts; |
|
108 | + return new Version( |
|
109 | + (int) $major, |
|
110 | + (int) $minor, |
|
111 | + (int) $patch, |
|
112 | + $release, |
|
113 | + (int) $build |
|
114 | + ); |
|
115 | + } |
|
116 | + |
|
117 | + |
|
118 | + /** |
|
119 | + * @return int |
|
120 | + */ |
|
121 | + public function major() |
|
122 | + { |
|
123 | + return $this->major; |
|
124 | + } |
|
125 | + |
|
126 | + |
|
127 | + /** |
|
128 | + * @param int|string $major |
|
129 | + * @throws InvalidDataTypeException |
|
130 | + */ |
|
131 | + private function setMajor($major) |
|
132 | + { |
|
133 | + if (! is_int($major)) { |
|
134 | + throw new InvalidDataTypeException( |
|
135 | + '$major', |
|
136 | + $major, |
|
137 | + 'integer' |
|
138 | + ); |
|
139 | + } |
|
140 | + $this->major = absint($major); |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @return int |
|
146 | + */ |
|
147 | + public function minor() |
|
148 | + { |
|
149 | + return $this->minor; |
|
150 | + } |
|
151 | + |
|
152 | + |
|
153 | + /** |
|
154 | + * @param int|string $minor |
|
155 | + * @throws InvalidDataTypeException |
|
156 | + */ |
|
157 | + private function setMinor($minor) |
|
158 | + { |
|
159 | + if (! is_int($minor)) { |
|
160 | + throw new InvalidDataTypeException( |
|
161 | + '$minor', |
|
162 | + $minor, |
|
163 | + 'integer' |
|
164 | + ); |
|
165 | + } |
|
166 | + $this->minor = absint($minor); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * @return int |
|
172 | + */ |
|
173 | + public function patch() |
|
174 | + { |
|
175 | + return $this->patch; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @param int|string $patch |
|
181 | + * @throws InvalidDataTypeException |
|
182 | + */ |
|
183 | + private function setPatch($patch) |
|
184 | + { |
|
185 | + if (! is_int($patch)) { |
|
186 | + throw new InvalidDataTypeException( |
|
187 | + '$patch', |
|
188 | + $patch, |
|
189 | + 'integer' |
|
190 | + ); |
|
191 | + } |
|
192 | + $this->patch = absint($patch); |
|
193 | + } |
|
194 | + |
|
195 | + |
|
196 | + /** |
|
197 | + * @return string |
|
198 | + */ |
|
199 | + public function release() |
|
200 | + { |
|
201 | + return $this->release; |
|
202 | + } |
|
203 | + |
|
204 | + |
|
205 | + /** |
|
206 | + * @param string $release |
|
207 | + * @throws InvalidArgumentException |
|
208 | + */ |
|
209 | + private function setRelease($release) |
|
210 | + { |
|
211 | + $valid_release_types = array( |
|
212 | + Version::RELEASE_TYPE_RC, |
|
213 | + Version::RELEASE_TYPE_BETA, |
|
214 | + Version::RELEASE_TYPE_DECAF, |
|
215 | + Version::RELEASE_TYPE_PROD, |
|
216 | + ); |
|
217 | + if (! in_array($release, $valid_release_types, true)) { |
|
218 | + throw new InvalidArgumentException( |
|
219 | + sprintf( |
|
220 | + esc_html__( |
|
221 | + '"%1$s" is not a valid release type. Please use one of the following values: %2$s', |
|
222 | + 'event_espresso' |
|
223 | + ), |
|
224 | + $release, |
|
225 | + implode(', ', $valid_release_types) |
|
226 | + ) |
|
227 | + ); |
|
228 | + } |
|
229 | + $this->release = $release; |
|
230 | + } |
|
231 | + |
|
232 | + |
|
233 | + /** |
|
234 | + * @return int |
|
235 | + */ |
|
236 | + public function build() |
|
237 | + { |
|
238 | + return $this->build; |
|
239 | + } |
|
240 | + |
|
241 | + |
|
242 | + /** |
|
243 | + * @param int|string $build |
|
244 | + * @throws InvalidDataTypeException |
|
245 | + */ |
|
246 | + private function setBuild($build) |
|
247 | + { |
|
248 | + if (! is_int($build)) { |
|
249 | + throw new InvalidDataTypeException( |
|
250 | + '$build', |
|
251 | + $build, |
|
252 | + 'integer' |
|
253 | + ); |
|
254 | + } |
|
255 | + $this->build = absint($build); |
|
256 | + } |
|
257 | + |
|
258 | + |
|
259 | + /** |
|
260 | + * @param Version $other_version |
|
261 | + * @return int |
|
262 | + */ |
|
263 | + public function compare(Version $other_version) |
|
264 | + { |
|
265 | + return version_compare((string) $this, (string) $other_version); |
|
266 | + } |
|
267 | + |
|
268 | + |
|
269 | + /** |
|
270 | + * @param Version $other_version |
|
271 | + * @return bool |
|
272 | + */ |
|
273 | + public function equals(Version $other_version) |
|
274 | + { |
|
275 | + return version_compare((string) $this, (string) $other_version, '=='); |
|
276 | + } |
|
277 | + |
|
278 | + |
|
279 | + /** |
|
280 | + * @param Version $other_version |
|
281 | + * @return bool |
|
282 | + */ |
|
283 | + public function newerThan(Version $other_version) |
|
284 | + { |
|
285 | + return version_compare((string) $this, (string) $other_version, '>'); |
|
286 | + } |
|
287 | + |
|
288 | + |
|
289 | + /** |
|
290 | + * @param Version $other_version |
|
291 | + * @return bool |
|
292 | + */ |
|
293 | + public function olderThan(Version $other_version) |
|
294 | + { |
|
295 | + return version_compare((string) $this, (string) $other_version, '<'); |
|
296 | + } |
|
297 | + |
|
298 | + |
|
299 | + /** |
|
300 | + * @return string |
|
301 | + */ |
|
302 | + public function __toString() |
|
303 | + { |
|
304 | + $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
|
305 | + if ($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
|
306 | + $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
307 | + } |
|
308 | + return $version_string; |
|
309 | + } |
|
310 | 310 | } |
@@ -102,7 +102,7 @@ discard block |
||
102 | 102 | ); |
103 | 103 | } |
104 | 104 | // add defaults for missing pieces |
105 | - $version_parts += array(0,0,0,'p',0); |
|
105 | + $version_parts += array(0, 0, 0, 'p', 0); |
|
106 | 106 | // reassign to individual variables |
107 | 107 | list($major, $minor, $patch, $release, $build) = $version_parts; |
108 | 108 | return new Version( |
@@ -130,7 +130,7 @@ discard block |
||
130 | 130 | */ |
131 | 131 | private function setMajor($major) |
132 | 132 | { |
133 | - if (! is_int($major)) { |
|
133 | + if ( ! is_int($major)) { |
|
134 | 134 | throw new InvalidDataTypeException( |
135 | 135 | '$major', |
136 | 136 | $major, |
@@ -156,7 +156,7 @@ discard block |
||
156 | 156 | */ |
157 | 157 | private function setMinor($minor) |
158 | 158 | { |
159 | - if (! is_int($minor)) { |
|
159 | + if ( ! is_int($minor)) { |
|
160 | 160 | throw new InvalidDataTypeException( |
161 | 161 | '$minor', |
162 | 162 | $minor, |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | */ |
183 | 183 | private function setPatch($patch) |
184 | 184 | { |
185 | - if (! is_int($patch)) { |
|
185 | + if ( ! is_int($patch)) { |
|
186 | 186 | throw new InvalidDataTypeException( |
187 | 187 | '$patch', |
188 | 188 | $patch, |
@@ -214,7 +214,7 @@ discard block |
||
214 | 214 | Version::RELEASE_TYPE_DECAF, |
215 | 215 | Version::RELEASE_TYPE_PROD, |
216 | 216 | ); |
217 | - if (! in_array($release, $valid_release_types, true)) { |
|
217 | + if ( ! in_array($release, $valid_release_types, true)) { |
|
218 | 218 | throw new InvalidArgumentException( |
219 | 219 | sprintf( |
220 | 220 | esc_html__( |
@@ -245,7 +245,7 @@ discard block |
||
245 | 245 | */ |
246 | 246 | private function setBuild($build) |
247 | 247 | { |
248 | - if (! is_int($build)) { |
|
248 | + if ( ! is_int($build)) { |
|
249 | 249 | throw new InvalidDataTypeException( |
250 | 250 | '$build', |
251 | 251 | $build, |
@@ -303,7 +303,7 @@ discard block |
||
303 | 303 | { |
304 | 304 | $version_string = "{$this->major}.{$this->minor}.{$this->patch}.{$this->release}"; |
305 | 305 | if ($this->release !== Version::RELEASE_TYPE_PROD && $this->release !== Version::RELEASE_TYPE_DECAF) { |
306 | - $version_string .= '.' . str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
306 | + $version_string .= '.'.str_pad($this->build, 3, '0', STR_PAD_LEFT); |
|
307 | 307 | } |
308 | 308 | return $version_string; |
309 | 309 | } |
@@ -15,59 +15,59 @@ |
||
15 | 15 | class EmailAddress |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var string $email_address |
|
20 | - */ |
|
21 | - private $email_address; |
|
18 | + /** |
|
19 | + * @var string $email_address |
|
20 | + */ |
|
21 | + private $email_address; |
|
22 | 22 | |
23 | 23 | |
24 | 24 | |
25 | - /** |
|
26 | - * EmailAddress constructor. |
|
27 | - * |
|
28 | - * @param string $email_address |
|
29 | - * @param EmailValidatorInterface $validator |
|
30 | - * @throws EmailValidationException |
|
31 | - */ |
|
32 | - public function __construct($email_address, EmailValidatorInterface $validator) |
|
33 | - { |
|
34 | - $validator->validate($email_address); |
|
35 | - $this->email_address = $email_address; |
|
36 | - } |
|
25 | + /** |
|
26 | + * EmailAddress constructor. |
|
27 | + * |
|
28 | + * @param string $email_address |
|
29 | + * @param EmailValidatorInterface $validator |
|
30 | + * @throws EmailValidationException |
|
31 | + */ |
|
32 | + public function __construct($email_address, EmailValidatorInterface $validator) |
|
33 | + { |
|
34 | + $validator->validate($email_address); |
|
35 | + $this->email_address = $email_address; |
|
36 | + } |
|
37 | 37 | |
38 | 38 | |
39 | 39 | |
40 | - /** |
|
41 | - * returns the string value for this EmailAddress |
|
42 | - * |
|
43 | - * @return string |
|
44 | - */ |
|
45 | - public function get() |
|
46 | - { |
|
47 | - return $this->email_address; |
|
48 | - } |
|
40 | + /** |
|
41 | + * returns the string value for this EmailAddress |
|
42 | + * |
|
43 | + * @return string |
|
44 | + */ |
|
45 | + public function get() |
|
46 | + { |
|
47 | + return $this->email_address; |
|
48 | + } |
|
49 | 49 | |
50 | 50 | |
51 | 51 | |
52 | - /** |
|
53 | - * compare another EmailAddress to this one to determine if they are the same |
|
54 | - * |
|
55 | - * @param EmailAddress $address |
|
56 | - * @return bool |
|
57 | - */ |
|
58 | - public function equals(EmailAddress $address) |
|
59 | - { |
|
60 | - return strtolower((string)$this) === strtolower((string)$address); |
|
61 | - } |
|
52 | + /** |
|
53 | + * compare another EmailAddress to this one to determine if they are the same |
|
54 | + * |
|
55 | + * @param EmailAddress $address |
|
56 | + * @return bool |
|
57 | + */ |
|
58 | + public function equals(EmailAddress $address) |
|
59 | + { |
|
60 | + return strtolower((string)$this) === strtolower((string)$address); |
|
61 | + } |
|
62 | 62 | |
63 | 63 | |
64 | - /** |
|
65 | - * allows an EmailAddress object to be used as a string |
|
66 | - * |
|
67 | - * @return string |
|
68 | - */ |
|
69 | - public function __toString() |
|
70 | - { |
|
71 | - return $this->email_address; |
|
72 | - } |
|
64 | + /** |
|
65 | + * allows an EmailAddress object to be used as a string |
|
66 | + * |
|
67 | + * @return string |
|
68 | + */ |
|
69 | + public function __toString() |
|
70 | + { |
|
71 | + return $this->email_address; |
|
72 | + } |
|
73 | 73 | } |
@@ -15,8 +15,8 @@ |
||
15 | 15 | interface RequiresRegistryInterface |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @param EE_Registry $registry |
|
20 | - */ |
|
21 | - public function setRegistry($registry); |
|
18 | + /** |
|
19 | + * @param EE_Registry $registry |
|
20 | + */ |
|
21 | + public function setRegistry($registry); |
|
22 | 22 | } |
@@ -18,154 +18,154 @@ |
||
18 | 18 | class DbSafeDateTime extends DateTime |
19 | 19 | { |
20 | 20 | |
21 | - // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
22 | - /** |
|
23 | - * @type string db_safe_timestamp_format |
|
24 | - */ |
|
25 | - const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
|
26 | - // phpcs:enable |
|
27 | - |
|
28 | - /** |
|
29 | - * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
|
30 | - * |
|
31 | - * @type string $_datetime_string |
|
32 | - */ |
|
33 | - protected $_datetime_string = ''; |
|
34 | - |
|
35 | - /** |
|
36 | - * where to write the error log to |
|
37 | - * |
|
38 | - * @type string $_error_log_dir |
|
39 | - */ |
|
40 | - protected $_error_log_dir = ''; |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $error_log_dir |
|
45 | - */ |
|
46 | - public function setErrorLogDir($error_log_dir) |
|
47 | - { |
|
48 | - // if the folder path is writable, then except the path + filename, else keep empty |
|
49 | - $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
50 | - ? $error_log_dir |
|
51 | - : ''; |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @return string |
|
57 | - */ |
|
58 | - public function __toString() |
|
59 | - { |
|
60 | - return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
61 | - } |
|
62 | - |
|
63 | - |
|
64 | - /** |
|
65 | - * @return array |
|
66 | - */ |
|
67 | - public function __sleep() |
|
68 | - { |
|
69 | - $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
70 | - $date = DateTime::createFromFormat( |
|
71 | - DbSafeDateTime::db_safe_timestamp_format, |
|
72 | - $this->_datetime_string |
|
73 | - ); |
|
74 | - if (! $date instanceof DateTime) { |
|
75 | - try { |
|
76 | - // we want a stack trace to determine where the malformed date came from, so... |
|
77 | - throw new DomainException(''); |
|
78 | - } catch (DomainException $e) { |
|
79 | - $stack_trace = $e->getTraceAsString(); |
|
80 | - } |
|
81 | - $this->writeToErrorLog( |
|
82 | - sprintf( |
|
83 | - __( |
|
84 | - 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
85 | - 'event_espresso' |
|
86 | - ), |
|
87 | - $this->_datetime_string, |
|
88 | - '<br />', |
|
89 | - print_r(DateTime::getLastErrors(), true), |
|
90 | - PHP_VERSION, |
|
91 | - $stack_trace |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - return array('_datetime_string'); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * if an empty or null value got saved to the db for a datetime, |
|
101 | - * then some servers and/or PHP itself will incorrectly convert that date string |
|
102 | - * resulting in "-0001-11-30" for the year-month-day. |
|
103 | - * see the Notes section |
|
104 | - * |
|
105 | - * @link http://php.net/manual/en/datetime.formats.date.php |
|
106 | - * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
107 | - * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
108 | - * so we're no better off, but at least things won't go fatal on us. |
|
109 | - */ |
|
110 | - public function __wakeup() |
|
111 | - { |
|
112 | - $this->_datetime_string = str_replace( |
|
113 | - array('-0001-11-29', '-0001-11-30'), |
|
114 | - '0000-00-00', |
|
115 | - $this->_datetime_string |
|
116 | - ); |
|
117 | - $date = DateTime::createFromFormat( |
|
118 | - DbSafeDateTime::db_safe_timestamp_format, |
|
119 | - $this->_datetime_string |
|
120 | - ); |
|
121 | - if (! $date instanceof DateTime) { |
|
122 | - $this->writeToErrorLog( |
|
123 | - sprintf( |
|
124 | - __( |
|
125 | - 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
126 | - 'event_espresso' |
|
127 | - ), |
|
128 | - $this->_datetime_string, |
|
129 | - '<br />', |
|
130 | - print_r(DateTime::getLastErrors(), true), |
|
131 | - PHP_VERSION |
|
132 | - ) |
|
133 | - ); |
|
134 | - } else { |
|
135 | - $this->__construct( |
|
136 | - $date->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
137 | - new DateTimeZone($date->format('e')) |
|
138 | - ); |
|
139 | - } |
|
140 | - } |
|
141 | - |
|
142 | - |
|
143 | - /** |
|
144 | - * Creates a DbSafeDateTime from ye old DateTime |
|
145 | - * |
|
146 | - * @param DateTime $datetime |
|
147 | - * @return \EventEspresso\core\domain\entities\DbSafeDateTime |
|
148 | - */ |
|
149 | - public static function createFromDateTime(DateTime $datetime) |
|
150 | - { |
|
151 | - return new DbSafeDateTime( |
|
152 | - $datetime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
153 | - new DateTimeZone($datetime->format('e')) |
|
154 | - ); |
|
155 | - } |
|
156 | - |
|
157 | - |
|
158 | - /** |
|
159 | - * @param string $message |
|
160 | - */ |
|
161 | - private function writeToErrorLog($message) |
|
162 | - { |
|
163 | - if (! empty($this->_error_log_dir)) { |
|
164 | - /** @noinspection ForgottenDebugOutputInspection */ |
|
165 | - error_log($message, 3, $this->_error_log_dir); |
|
166 | - } else { |
|
167 | - /** @noinspection ForgottenDebugOutputInspection */ |
|
168 | - error_log($message); |
|
169 | - } |
|
170 | - } |
|
21 | + // phpcs:disable Generic.NamingConventions.UpperCaseConstantName.ClassConstantNotUpperCase |
|
22 | + /** |
|
23 | + * @type string db_safe_timestamp_format |
|
24 | + */ |
|
25 | + const db_safe_timestamp_format = 'Y-m-d H:i:s O e'; |
|
26 | + // phpcs:enable |
|
27 | + |
|
28 | + /** |
|
29 | + * DateTime object converted to a string that includes the date, time, UTC offset, and timezone identifier |
|
30 | + * |
|
31 | + * @type string $_datetime_string |
|
32 | + */ |
|
33 | + protected $_datetime_string = ''; |
|
34 | + |
|
35 | + /** |
|
36 | + * where to write the error log to |
|
37 | + * |
|
38 | + * @type string $_error_log_dir |
|
39 | + */ |
|
40 | + protected $_error_log_dir = ''; |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $error_log_dir |
|
45 | + */ |
|
46 | + public function setErrorLogDir($error_log_dir) |
|
47 | + { |
|
48 | + // if the folder path is writable, then except the path + filename, else keep empty |
|
49 | + $this->_error_log_dir = is_writable(str_replace(basename($error_log_dir), '', $error_log_dir)) |
|
50 | + ? $error_log_dir |
|
51 | + : ''; |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @return string |
|
57 | + */ |
|
58 | + public function __toString() |
|
59 | + { |
|
60 | + return $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
61 | + } |
|
62 | + |
|
63 | + |
|
64 | + /** |
|
65 | + * @return array |
|
66 | + */ |
|
67 | + public function __sleep() |
|
68 | + { |
|
69 | + $this->_datetime_string = $this->format(DbSafeDateTime::db_safe_timestamp_format); |
|
70 | + $date = DateTime::createFromFormat( |
|
71 | + DbSafeDateTime::db_safe_timestamp_format, |
|
72 | + $this->_datetime_string |
|
73 | + ); |
|
74 | + if (! $date instanceof DateTime) { |
|
75 | + try { |
|
76 | + // we want a stack trace to determine where the malformed date came from, so... |
|
77 | + throw new DomainException(''); |
|
78 | + } catch (DomainException $e) { |
|
79 | + $stack_trace = $e->getTraceAsString(); |
|
80 | + } |
|
81 | + $this->writeToErrorLog( |
|
82 | + sprintf( |
|
83 | + __( |
|
84 | + 'A valid DateTime could not be generated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s %2$s Stack Trace: %5$s', |
|
85 | + 'event_espresso' |
|
86 | + ), |
|
87 | + $this->_datetime_string, |
|
88 | + '<br />', |
|
89 | + print_r(DateTime::getLastErrors(), true), |
|
90 | + PHP_VERSION, |
|
91 | + $stack_trace |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + return array('_datetime_string'); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * if an empty or null value got saved to the db for a datetime, |
|
101 | + * then some servers and/or PHP itself will incorrectly convert that date string |
|
102 | + * resulting in "-0001-11-30" for the year-month-day. |
|
103 | + * see the Notes section |
|
104 | + * |
|
105 | + * @link http://php.net/manual/en/datetime.formats.date.php |
|
106 | + * We'll replace those with "0000-00-00" which will allow a valid DateTime object to be created, |
|
107 | + * but still result in the internal date for that object being set to "-0001-11-30 10:00:00.000000". |
|
108 | + * so we're no better off, but at least things won't go fatal on us. |
|
109 | + */ |
|
110 | + public function __wakeup() |
|
111 | + { |
|
112 | + $this->_datetime_string = str_replace( |
|
113 | + array('-0001-11-29', '-0001-11-30'), |
|
114 | + '0000-00-00', |
|
115 | + $this->_datetime_string |
|
116 | + ); |
|
117 | + $date = DateTime::createFromFormat( |
|
118 | + DbSafeDateTime::db_safe_timestamp_format, |
|
119 | + $this->_datetime_string |
|
120 | + ); |
|
121 | + if (! $date instanceof DateTime) { |
|
122 | + $this->writeToErrorLog( |
|
123 | + sprintf( |
|
124 | + __( |
|
125 | + 'A valid DateTime could not be recreated from "%1$s" because the following errors occurred: %2$s %3$s %2$s PHP version: %4$s', |
|
126 | + 'event_espresso' |
|
127 | + ), |
|
128 | + $this->_datetime_string, |
|
129 | + '<br />', |
|
130 | + print_r(DateTime::getLastErrors(), true), |
|
131 | + PHP_VERSION |
|
132 | + ) |
|
133 | + ); |
|
134 | + } else { |
|
135 | + $this->__construct( |
|
136 | + $date->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
137 | + new DateTimeZone($date->format('e')) |
|
138 | + ); |
|
139 | + } |
|
140 | + } |
|
141 | + |
|
142 | + |
|
143 | + /** |
|
144 | + * Creates a DbSafeDateTime from ye old DateTime |
|
145 | + * |
|
146 | + * @param DateTime $datetime |
|
147 | + * @return \EventEspresso\core\domain\entities\DbSafeDateTime |
|
148 | + */ |
|
149 | + public static function createFromDateTime(DateTime $datetime) |
|
150 | + { |
|
151 | + return new DbSafeDateTime( |
|
152 | + $datetime->format(\EE_Datetime_Field::mysql_timestamp_format), |
|
153 | + new DateTimeZone($datetime->format('e')) |
|
154 | + ); |
|
155 | + } |
|
156 | + |
|
157 | + |
|
158 | + /** |
|
159 | + * @param string $message |
|
160 | + */ |
|
161 | + private function writeToErrorLog($message) |
|
162 | + { |
|
163 | + if (! empty($this->_error_log_dir)) { |
|
164 | + /** @noinspection ForgottenDebugOutputInspection */ |
|
165 | + error_log($message, 3, $this->_error_log_dir); |
|
166 | + } else { |
|
167 | + /** @noinspection ForgottenDebugOutputInspection */ |
|
168 | + error_log($message); |
|
169 | + } |
|
170 | + } |
|
171 | 171 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | DbSafeDateTime::db_safe_timestamp_format, |
72 | 72 | $this->_datetime_string |
73 | 73 | ); |
74 | - if (! $date instanceof DateTime) { |
|
74 | + if ( ! $date instanceof DateTime) { |
|
75 | 75 | try { |
76 | 76 | // we want a stack trace to determine where the malformed date came from, so... |
77 | 77 | throw new DomainException(''); |
@@ -118,7 +118,7 @@ discard block |
||
118 | 118 | DbSafeDateTime::db_safe_timestamp_format, |
119 | 119 | $this->_datetime_string |
120 | 120 | ); |
121 | - if (! $date instanceof DateTime) { |
|
121 | + if ( ! $date instanceof DateTime) { |
|
122 | 122 | $this->writeToErrorLog( |
123 | 123 | sprintf( |
124 | 124 | __( |
@@ -160,7 +160,7 @@ discard block |
||
160 | 160 | */ |
161 | 161 | private function writeToErrorLog($message) |
162 | 162 | { |
163 | - if (! empty($this->_error_log_dir)) { |
|
163 | + if ( ! empty($this->_error_log_dir)) { |
|
164 | 164 | /** @noinspection ForgottenDebugOutputInspection */ |
165 | 165 | error_log($message, 3, $this->_error_log_dir); |
166 | 166 | } else { |
@@ -18,97 +18,97 @@ |
||
18 | 18 | class RegUrlLink |
19 | 19 | { |
20 | 20 | |
21 | - /* |
|
21 | + /* |
|
22 | 22 | * @var string $reg_url_link |
23 | 23 | */ |
24 | - private $reg_url_link; |
|
24 | + private $reg_url_link; |
|
25 | 25 | |
26 | 26 | |
27 | - /** |
|
28 | - * @param string $reg_url_link |
|
29 | - * @return RegUrlLink |
|
30 | - * @throws InvalidArgumentException |
|
31 | - */ |
|
32 | - public static function fromRegUrlLinkString($reg_url_link) |
|
33 | - { |
|
34 | - if (empty($reg_url_link) || ! is_string($reg_url_link)) { |
|
35 | - throw new InvalidArgumentException( |
|
36 | - __( |
|
37 | - 'You must supply a valid non-empty string to generate a reg_url_link.', |
|
38 | - 'event_espresso' |
|
39 | - ) |
|
40 | - ); |
|
41 | - } |
|
42 | - return new RegUrlLink(1, '', $reg_url_link); |
|
43 | - } |
|
27 | + /** |
|
28 | + * @param string $reg_url_link |
|
29 | + * @return RegUrlLink |
|
30 | + * @throws InvalidArgumentException |
|
31 | + */ |
|
32 | + public static function fromRegUrlLinkString($reg_url_link) |
|
33 | + { |
|
34 | + if (empty($reg_url_link) || ! is_string($reg_url_link)) { |
|
35 | + throw new InvalidArgumentException( |
|
36 | + __( |
|
37 | + 'You must supply a valid non-empty string to generate a reg_url_link.', |
|
38 | + 'event_espresso' |
|
39 | + ) |
|
40 | + ); |
|
41 | + } |
|
42 | + return new RegUrlLink(1, '', $reg_url_link); |
|
43 | + } |
|
44 | 44 | |
45 | 45 | |
46 | - /** |
|
47 | - * @param EE_Registration $registration |
|
48 | - * @return RegUrlLink |
|
49 | - * @throws EntityNotFoundException |
|
50 | - * @throws EE_Error |
|
51 | - * @throws InvalidArgumentException |
|
52 | - */ |
|
53 | - public static function fromRegistration(EE_Registration $registration) |
|
54 | - { |
|
55 | - return new RegUrlLink( |
|
56 | - $registration->count(), |
|
57 | - $registration->ticket_line_item() |
|
58 | - ); |
|
59 | - } |
|
46 | + /** |
|
47 | + * @param EE_Registration $registration |
|
48 | + * @return RegUrlLink |
|
49 | + * @throws EntityNotFoundException |
|
50 | + * @throws EE_Error |
|
51 | + * @throws InvalidArgumentException |
|
52 | + */ |
|
53 | + public static function fromRegistration(EE_Registration $registration) |
|
54 | + { |
|
55 | + return new RegUrlLink( |
|
56 | + $registration->count(), |
|
57 | + $registration->ticket_line_item() |
|
58 | + ); |
|
59 | + } |
|
60 | 60 | |
61 | 61 | |
62 | - /** |
|
63 | - * CreateRegUrlLinkCommand constructor. |
|
64 | - * |
|
65 | - * @param int $reg_count |
|
66 | - * @param mixed $base_code |
|
67 | - * @param string $reg_url_link |
|
68 | - * @throws InvalidArgumentException |
|
69 | - */ |
|
70 | - public function __construct( |
|
71 | - $reg_count = 1, |
|
72 | - $base_code = '', |
|
73 | - $reg_url_link = '' |
|
74 | - ) { |
|
75 | - if (! empty($reg_url_link) && is_string($reg_url_link)) { |
|
76 | - $this->reg_url_link = apply_filters( |
|
77 | - 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
|
78 | - $reg_url_link, |
|
79 | - $reg_count, |
|
80 | - $base_code, |
|
81 | - $reg_url_link |
|
82 | - ); |
|
83 | - return; |
|
84 | - } |
|
85 | - $reg_count = max(1, absint($reg_count)); |
|
86 | - $base_code = $base_code instanceof \EE_Line_Item ? $base_code->code() : $base_code; |
|
87 | - if (empty($base_code) || ! is_string($base_code)) { |
|
88 | - throw new InvalidArgumentException( |
|
89 | - __( |
|
90 | - 'You must supply a valid EE_Line_Item or a non-empty string to generate a reg_url_link.', |
|
91 | - 'event_espresso' |
|
92 | - ) |
|
93 | - ); |
|
94 | - } |
|
95 | - $this->reg_url_link = (string)apply_filters( |
|
96 | - 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
|
97 | - $reg_count . '-' . md5($base_code . microtime()), |
|
98 | - $reg_count, |
|
99 | - $base_code, |
|
100 | - $reg_url_link |
|
101 | - ); |
|
102 | - } |
|
62 | + /** |
|
63 | + * CreateRegUrlLinkCommand constructor. |
|
64 | + * |
|
65 | + * @param int $reg_count |
|
66 | + * @param mixed $base_code |
|
67 | + * @param string $reg_url_link |
|
68 | + * @throws InvalidArgumentException |
|
69 | + */ |
|
70 | + public function __construct( |
|
71 | + $reg_count = 1, |
|
72 | + $base_code = '', |
|
73 | + $reg_url_link = '' |
|
74 | + ) { |
|
75 | + if (! empty($reg_url_link) && is_string($reg_url_link)) { |
|
76 | + $this->reg_url_link = apply_filters( |
|
77 | + 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
|
78 | + $reg_url_link, |
|
79 | + $reg_count, |
|
80 | + $base_code, |
|
81 | + $reg_url_link |
|
82 | + ); |
|
83 | + return; |
|
84 | + } |
|
85 | + $reg_count = max(1, absint($reg_count)); |
|
86 | + $base_code = $base_code instanceof \EE_Line_Item ? $base_code->code() : $base_code; |
|
87 | + if (empty($base_code) || ! is_string($base_code)) { |
|
88 | + throw new InvalidArgumentException( |
|
89 | + __( |
|
90 | + 'You must supply a valid EE_Line_Item or a non-empty string to generate a reg_url_link.', |
|
91 | + 'event_espresso' |
|
92 | + ) |
|
93 | + ); |
|
94 | + } |
|
95 | + $this->reg_url_link = (string)apply_filters( |
|
96 | + 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
|
97 | + $reg_count . '-' . md5($base_code . microtime()), |
|
98 | + $reg_count, |
|
99 | + $base_code, |
|
100 | + $reg_url_link |
|
101 | + ); |
|
102 | + } |
|
103 | 103 | |
104 | 104 | |
105 | - /** |
|
106 | - * Return the object as a string |
|
107 | - * |
|
108 | - * @return string |
|
109 | - */ |
|
110 | - public function __toString() |
|
111 | - { |
|
112 | - return $this->reg_url_link; |
|
113 | - } |
|
105 | + /** |
|
106 | + * Return the object as a string |
|
107 | + * |
|
108 | + * @return string |
|
109 | + */ |
|
110 | + public function __toString() |
|
111 | + { |
|
112 | + return $this->reg_url_link; |
|
113 | + } |
|
114 | 114 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | $base_code = '', |
73 | 73 | $reg_url_link = '' |
74 | 74 | ) { |
75 | - if (! empty($reg_url_link) && is_string($reg_url_link)) { |
|
75 | + if ( ! empty($reg_url_link) && is_string($reg_url_link)) { |
|
76 | 76 | $this->reg_url_link = apply_filters( |
77 | 77 | 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
78 | 78 | $reg_url_link, |
@@ -92,9 +92,9 @@ discard block |
||
92 | 92 | ) |
93 | 93 | ); |
94 | 94 | } |
95 | - $this->reg_url_link = (string)apply_filters( |
|
95 | + $this->reg_url_link = (string) apply_filters( |
|
96 | 96 | 'FHEE__\EventEspresso\core\domain\entities\RegUrlLink__construct__reg_url_link', |
97 | - $reg_count . '-' . md5($base_code . microtime()), |
|
97 | + $reg_count.'-'.md5($base_code.microtime()), |
|
98 | 98 | $reg_count, |
99 | 99 | $base_code, |
100 | 100 | $reg_url_link |
@@ -24,315 +24,315 @@ |
||
24 | 24 | class PersistentAdminNotice implements RequiresCapCheckInterface |
25 | 25 | { |
26 | 26 | |
27 | - /** |
|
28 | - * @var string $name |
|
29 | - */ |
|
30 | - protected $name = ''; |
|
31 | - |
|
32 | - /** |
|
33 | - * @var string $message |
|
34 | - */ |
|
35 | - protected $message = ''; |
|
36 | - |
|
37 | - /** |
|
38 | - * @var boolean $force_update |
|
39 | - */ |
|
40 | - protected $force_update = false; |
|
41 | - |
|
42 | - /** |
|
43 | - * @var string $capability |
|
44 | - */ |
|
45 | - protected $capability = 'manage_options'; |
|
46 | - |
|
47 | - /** |
|
48 | - * @var string $cap_context |
|
49 | - */ |
|
50 | - protected $cap_context = 'view persistent admin notice'; |
|
51 | - |
|
52 | - /** |
|
53 | - * @var boolean $dismissed |
|
54 | - */ |
|
55 | - protected $dismissed = false; |
|
56 | - |
|
57 | - /** |
|
58 | - * @var CapCheckInterface $cap_check |
|
59 | - */ |
|
60 | - protected $cap_check; |
|
61 | - |
|
62 | - /** |
|
63 | - * if true, then this notice will be deleted from the database |
|
64 | - * |
|
65 | - * @var boolean $purge |
|
66 | - */ |
|
67 | - protected $purge = false; |
|
68 | - |
|
69 | - /** |
|
70 | - * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
71 | - * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
72 | - * |
|
73 | - * @var boolean $registered |
|
74 | - */ |
|
75 | - private $registered = false; |
|
76 | - |
|
77 | - |
|
78 | - /** |
|
79 | - * PersistentAdminNotice constructor |
|
80 | - * |
|
81 | - * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
82 | - * @param string $message [required] the message to be stored persistently until dismissed |
|
83 | - * @param bool $force_update enforce the reappearance of a persistent message |
|
84 | - * @param string $capability user capability required to view this notice |
|
85 | - * @param string $cap_context description for why the cap check is being performed |
|
86 | - * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
87 | - * @throws InvalidDataTypeException |
|
88 | - */ |
|
89 | - public function __construct( |
|
90 | - $name, |
|
91 | - $message, |
|
92 | - $force_update = false, |
|
93 | - $capability = 'manage_options', |
|
94 | - $cap_context = 'view persistent admin notice', |
|
95 | - $dismissed = false |
|
96 | - ) { |
|
97 | - $this->setName($name); |
|
98 | - $this->setMessage($message); |
|
99 | - $this->setForceUpdate($force_update); |
|
100 | - $this->setCapability($capability); |
|
101 | - $this->setCapContext($cap_context); |
|
102 | - $this->setDismissed($dismissed); |
|
103 | - add_action( |
|
104 | - 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
105 | - array($this, 'registerPersistentAdminNotice') |
|
106 | - ); |
|
107 | - add_action('shutdown', array($this, 'confirmRegistered'), 999); |
|
108 | - } |
|
109 | - |
|
110 | - |
|
111 | - /** |
|
112 | - * @return string |
|
113 | - */ |
|
114 | - public function getName() |
|
115 | - { |
|
116 | - return $this->name; |
|
117 | - } |
|
118 | - |
|
119 | - |
|
120 | - /** |
|
121 | - * @param string $name |
|
122 | - * @throws InvalidDataTypeException |
|
123 | - */ |
|
124 | - private function setName($name) |
|
125 | - { |
|
126 | - if (! is_string($name)) { |
|
127 | - throw new InvalidDataTypeException('$name', $name, 'string'); |
|
128 | - } |
|
129 | - $this->name = sanitize_key($name); |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * @return string |
|
135 | - */ |
|
136 | - public function getMessage() |
|
137 | - { |
|
138 | - return $this->message; |
|
139 | - } |
|
140 | - |
|
141 | - |
|
142 | - /** |
|
143 | - * @param string $message |
|
144 | - * @throws InvalidDataTypeException |
|
145 | - */ |
|
146 | - private function setMessage($message) |
|
147 | - { |
|
148 | - if (! is_string($message)) { |
|
149 | - throw new InvalidDataTypeException('$message', $message, 'string'); |
|
150 | - } |
|
151 | - global $allowedtags; |
|
152 | - $allowedtags['br'] = array(); |
|
153 | - $this->message = wp_kses($message, $allowedtags); |
|
154 | - } |
|
155 | - |
|
156 | - |
|
157 | - /** |
|
158 | - * @return bool |
|
159 | - */ |
|
160 | - public function getForceUpdate() |
|
161 | - { |
|
162 | - return $this->force_update; |
|
163 | - } |
|
164 | - |
|
165 | - |
|
166 | - /** |
|
167 | - * @param bool $force_update |
|
168 | - */ |
|
169 | - private function setForceUpdate($force_update) |
|
170 | - { |
|
171 | - $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
172 | - } |
|
173 | - |
|
174 | - |
|
175 | - /** |
|
176 | - * @return string |
|
177 | - */ |
|
178 | - public function getCapability() |
|
179 | - { |
|
180 | - return $this->capability; |
|
181 | - } |
|
182 | - |
|
183 | - |
|
184 | - /** |
|
185 | - * @param string $capability |
|
186 | - * @throws InvalidDataTypeException |
|
187 | - */ |
|
188 | - private function setCapability($capability) |
|
189 | - { |
|
190 | - if (! is_string($capability)) { |
|
191 | - throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
192 | - } |
|
193 | - $this->capability = ! empty($capability) ? $capability : 'manage_options'; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @return string |
|
199 | - */ |
|
200 | - public function getCapContext() |
|
201 | - { |
|
202 | - return $this->cap_context; |
|
203 | - } |
|
204 | - |
|
205 | - |
|
206 | - /** |
|
207 | - * @param string $cap_context |
|
208 | - * @throws InvalidDataTypeException |
|
209 | - */ |
|
210 | - private function setCapContext($cap_context) |
|
211 | - { |
|
212 | - if (! is_string($cap_context)) { |
|
213 | - throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
214 | - } |
|
215 | - $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice'; |
|
216 | - } |
|
217 | - |
|
218 | - |
|
219 | - /** |
|
220 | - * @return bool |
|
221 | - */ |
|
222 | - public function getDismissed() |
|
223 | - { |
|
224 | - return $this->dismissed; |
|
225 | - } |
|
226 | - |
|
227 | - |
|
228 | - /** |
|
229 | - * @param bool $dismissed |
|
230 | - */ |
|
231 | - public function setDismissed($dismissed) |
|
232 | - { |
|
233 | - $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
234 | - } |
|
235 | - |
|
236 | - |
|
237 | - /** |
|
238 | - * @return CapCheckInterface |
|
239 | - * @throws InvalidDataTypeException |
|
240 | - */ |
|
241 | - public function getCapCheck() |
|
242 | - { |
|
243 | - if (! $this->cap_check instanceof CapCheckInterface) { |
|
244 | - $this->setCapCheck( |
|
245 | - new CapCheck( |
|
246 | - $this->capability, |
|
247 | - $this->cap_context |
|
248 | - ) |
|
249 | - ); |
|
250 | - } |
|
251 | - return $this->cap_check; |
|
252 | - } |
|
253 | - |
|
254 | - |
|
255 | - /** |
|
256 | - * @param CapCheckInterface $cap_check |
|
257 | - */ |
|
258 | - private function setCapCheck(CapCheckInterface $cap_check) |
|
259 | - { |
|
260 | - $this->cap_check = $cap_check; |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @return bool |
|
266 | - */ |
|
267 | - public function getPurge() |
|
268 | - { |
|
269 | - return $this->purge; |
|
270 | - } |
|
271 | - |
|
272 | - |
|
273 | - /** |
|
274 | - * @param bool $purge |
|
275 | - */ |
|
276 | - public function setPurge($purge) |
|
277 | - { |
|
278 | - $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
279 | - } |
|
280 | - |
|
281 | - |
|
282 | - /** |
|
283 | - * given a valid PersistentAdminNotice Collection, |
|
284 | - * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
285 | - * if an existing notice is found that has already been dismissed, |
|
286 | - * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
287 | - * so that the notice is displayed again |
|
288 | - * |
|
289 | - * @param Collection $persistent_admin_notice_collection |
|
290 | - * @throws InvalidEntityException |
|
291 | - * @throws InvalidDataTypeException |
|
292 | - */ |
|
293 | - public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
294 | - { |
|
295 | - if ($this->registered) { |
|
296 | - return; |
|
297 | - } |
|
298 | - // first check if this notice has already been added to the collection |
|
299 | - if ($persistent_admin_notice_collection->has($this->name)) { |
|
300 | - /** @var PersistentAdminNotice $existing */ |
|
301 | - $existing = $persistent_admin_notice_collection->get($this->name); |
|
302 | - // we don't need to add it again (we can't actually) |
|
303 | - // but if it has already been dismissed, and we are overriding with a forced update |
|
304 | - if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
305 | - // then toggle the notice's dismissed state to true |
|
306 | - // so that it gets displayed again |
|
307 | - $existing->setDismissed(false); |
|
308 | - // and make sure the message is set |
|
309 | - $existing->setMessage($this->message); |
|
310 | - } |
|
311 | - } else { |
|
312 | - $persistent_admin_notice_collection->add($this, $this->name); |
|
313 | - } |
|
314 | - $this->registered = true; |
|
315 | - } |
|
316 | - |
|
317 | - |
|
318 | - /** |
|
319 | - * @throws Exception |
|
320 | - */ |
|
321 | - public function confirmRegistered() |
|
322 | - { |
|
323 | - if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) { |
|
324 | - PersistentAdminNoticeManager::loadRegisterAndSaveNotices(); |
|
325 | - } |
|
326 | - if (! $this->registered && WP_DEBUG) { |
|
327 | - throw new DomainException( |
|
328 | - sprintf( |
|
329 | - esc_html__( |
|
330 | - 'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.', |
|
331 | - 'event_espresso' |
|
332 | - ), |
|
333 | - $this->name |
|
334 | - ) |
|
335 | - ); |
|
336 | - } |
|
337 | - } |
|
27 | + /** |
|
28 | + * @var string $name |
|
29 | + */ |
|
30 | + protected $name = ''; |
|
31 | + |
|
32 | + /** |
|
33 | + * @var string $message |
|
34 | + */ |
|
35 | + protected $message = ''; |
|
36 | + |
|
37 | + /** |
|
38 | + * @var boolean $force_update |
|
39 | + */ |
|
40 | + protected $force_update = false; |
|
41 | + |
|
42 | + /** |
|
43 | + * @var string $capability |
|
44 | + */ |
|
45 | + protected $capability = 'manage_options'; |
|
46 | + |
|
47 | + /** |
|
48 | + * @var string $cap_context |
|
49 | + */ |
|
50 | + protected $cap_context = 'view persistent admin notice'; |
|
51 | + |
|
52 | + /** |
|
53 | + * @var boolean $dismissed |
|
54 | + */ |
|
55 | + protected $dismissed = false; |
|
56 | + |
|
57 | + /** |
|
58 | + * @var CapCheckInterface $cap_check |
|
59 | + */ |
|
60 | + protected $cap_check; |
|
61 | + |
|
62 | + /** |
|
63 | + * if true, then this notice will be deleted from the database |
|
64 | + * |
|
65 | + * @var boolean $purge |
|
66 | + */ |
|
67 | + protected $purge = false; |
|
68 | + |
|
69 | + /** |
|
70 | + * gets set to true if notice is successfully registered with the PersistentAdminNoticeManager |
|
71 | + * if false, and WP_DEBUG is on, then an exception will be thrown in the admin footer |
|
72 | + * |
|
73 | + * @var boolean $registered |
|
74 | + */ |
|
75 | + private $registered = false; |
|
76 | + |
|
77 | + |
|
78 | + /** |
|
79 | + * PersistentAdminNotice constructor |
|
80 | + * |
|
81 | + * @param string $name [required] the name, or key of the Persistent Admin Notice to be stored |
|
82 | + * @param string $message [required] the message to be stored persistently until dismissed |
|
83 | + * @param bool $force_update enforce the reappearance of a persistent message |
|
84 | + * @param string $capability user capability required to view this notice |
|
85 | + * @param string $cap_context description for why the cap check is being performed |
|
86 | + * @param bool $dismissed whether or not the user has already dismissed/viewed this notice |
|
87 | + * @throws InvalidDataTypeException |
|
88 | + */ |
|
89 | + public function __construct( |
|
90 | + $name, |
|
91 | + $message, |
|
92 | + $force_update = false, |
|
93 | + $capability = 'manage_options', |
|
94 | + $cap_context = 'view persistent admin notice', |
|
95 | + $dismissed = false |
|
96 | + ) { |
|
97 | + $this->setName($name); |
|
98 | + $this->setMessage($message); |
|
99 | + $this->setForceUpdate($force_update); |
|
100 | + $this->setCapability($capability); |
|
101 | + $this->setCapContext($cap_context); |
|
102 | + $this->setDismissed($dismissed); |
|
103 | + add_action( |
|
104 | + 'AHEE__EventEspresso_core_services_notifications_PersistentAdminNoticeManager__registerNotices', |
|
105 | + array($this, 'registerPersistentAdminNotice') |
|
106 | + ); |
|
107 | + add_action('shutdown', array($this, 'confirmRegistered'), 999); |
|
108 | + } |
|
109 | + |
|
110 | + |
|
111 | + /** |
|
112 | + * @return string |
|
113 | + */ |
|
114 | + public function getName() |
|
115 | + { |
|
116 | + return $this->name; |
|
117 | + } |
|
118 | + |
|
119 | + |
|
120 | + /** |
|
121 | + * @param string $name |
|
122 | + * @throws InvalidDataTypeException |
|
123 | + */ |
|
124 | + private function setName($name) |
|
125 | + { |
|
126 | + if (! is_string($name)) { |
|
127 | + throw new InvalidDataTypeException('$name', $name, 'string'); |
|
128 | + } |
|
129 | + $this->name = sanitize_key($name); |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * @return string |
|
135 | + */ |
|
136 | + public function getMessage() |
|
137 | + { |
|
138 | + return $this->message; |
|
139 | + } |
|
140 | + |
|
141 | + |
|
142 | + /** |
|
143 | + * @param string $message |
|
144 | + * @throws InvalidDataTypeException |
|
145 | + */ |
|
146 | + private function setMessage($message) |
|
147 | + { |
|
148 | + if (! is_string($message)) { |
|
149 | + throw new InvalidDataTypeException('$message', $message, 'string'); |
|
150 | + } |
|
151 | + global $allowedtags; |
|
152 | + $allowedtags['br'] = array(); |
|
153 | + $this->message = wp_kses($message, $allowedtags); |
|
154 | + } |
|
155 | + |
|
156 | + |
|
157 | + /** |
|
158 | + * @return bool |
|
159 | + */ |
|
160 | + public function getForceUpdate() |
|
161 | + { |
|
162 | + return $this->force_update; |
|
163 | + } |
|
164 | + |
|
165 | + |
|
166 | + /** |
|
167 | + * @param bool $force_update |
|
168 | + */ |
|
169 | + private function setForceUpdate($force_update) |
|
170 | + { |
|
171 | + $this->force_update = filter_var($force_update, FILTER_VALIDATE_BOOLEAN); |
|
172 | + } |
|
173 | + |
|
174 | + |
|
175 | + /** |
|
176 | + * @return string |
|
177 | + */ |
|
178 | + public function getCapability() |
|
179 | + { |
|
180 | + return $this->capability; |
|
181 | + } |
|
182 | + |
|
183 | + |
|
184 | + /** |
|
185 | + * @param string $capability |
|
186 | + * @throws InvalidDataTypeException |
|
187 | + */ |
|
188 | + private function setCapability($capability) |
|
189 | + { |
|
190 | + if (! is_string($capability)) { |
|
191 | + throw new InvalidDataTypeException('$capability', $capability, 'string'); |
|
192 | + } |
|
193 | + $this->capability = ! empty($capability) ? $capability : 'manage_options'; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @return string |
|
199 | + */ |
|
200 | + public function getCapContext() |
|
201 | + { |
|
202 | + return $this->cap_context; |
|
203 | + } |
|
204 | + |
|
205 | + |
|
206 | + /** |
|
207 | + * @param string $cap_context |
|
208 | + * @throws InvalidDataTypeException |
|
209 | + */ |
|
210 | + private function setCapContext($cap_context) |
|
211 | + { |
|
212 | + if (! is_string($cap_context)) { |
|
213 | + throw new InvalidDataTypeException('$cap_context', $cap_context, 'string'); |
|
214 | + } |
|
215 | + $this->cap_context = ! empty($cap_context) ? $cap_context : 'view persistent admin notice'; |
|
216 | + } |
|
217 | + |
|
218 | + |
|
219 | + /** |
|
220 | + * @return bool |
|
221 | + */ |
|
222 | + public function getDismissed() |
|
223 | + { |
|
224 | + return $this->dismissed; |
|
225 | + } |
|
226 | + |
|
227 | + |
|
228 | + /** |
|
229 | + * @param bool $dismissed |
|
230 | + */ |
|
231 | + public function setDismissed($dismissed) |
|
232 | + { |
|
233 | + $this->dismissed = filter_var($dismissed, FILTER_VALIDATE_BOOLEAN); |
|
234 | + } |
|
235 | + |
|
236 | + |
|
237 | + /** |
|
238 | + * @return CapCheckInterface |
|
239 | + * @throws InvalidDataTypeException |
|
240 | + */ |
|
241 | + public function getCapCheck() |
|
242 | + { |
|
243 | + if (! $this->cap_check instanceof CapCheckInterface) { |
|
244 | + $this->setCapCheck( |
|
245 | + new CapCheck( |
|
246 | + $this->capability, |
|
247 | + $this->cap_context |
|
248 | + ) |
|
249 | + ); |
|
250 | + } |
|
251 | + return $this->cap_check; |
|
252 | + } |
|
253 | + |
|
254 | + |
|
255 | + /** |
|
256 | + * @param CapCheckInterface $cap_check |
|
257 | + */ |
|
258 | + private function setCapCheck(CapCheckInterface $cap_check) |
|
259 | + { |
|
260 | + $this->cap_check = $cap_check; |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @return bool |
|
266 | + */ |
|
267 | + public function getPurge() |
|
268 | + { |
|
269 | + return $this->purge; |
|
270 | + } |
|
271 | + |
|
272 | + |
|
273 | + /** |
|
274 | + * @param bool $purge |
|
275 | + */ |
|
276 | + public function setPurge($purge) |
|
277 | + { |
|
278 | + $this->purge = filter_var($purge, FILTER_VALIDATE_BOOLEAN); |
|
279 | + } |
|
280 | + |
|
281 | + |
|
282 | + /** |
|
283 | + * given a valid PersistentAdminNotice Collection, |
|
284 | + * this notice will be added if it is not already found in the collection (using its name as the identifier) |
|
285 | + * if an existing notice is found that has already been dismissed, |
|
286 | + * but we are overriding with a forced update, then we will toggle its dismissed state, |
|
287 | + * so that the notice is displayed again |
|
288 | + * |
|
289 | + * @param Collection $persistent_admin_notice_collection |
|
290 | + * @throws InvalidEntityException |
|
291 | + * @throws InvalidDataTypeException |
|
292 | + */ |
|
293 | + public function registerPersistentAdminNotice(Collection $persistent_admin_notice_collection) |
|
294 | + { |
|
295 | + if ($this->registered) { |
|
296 | + return; |
|
297 | + } |
|
298 | + // first check if this notice has already been added to the collection |
|
299 | + if ($persistent_admin_notice_collection->has($this->name)) { |
|
300 | + /** @var PersistentAdminNotice $existing */ |
|
301 | + $existing = $persistent_admin_notice_collection->get($this->name); |
|
302 | + // we don't need to add it again (we can't actually) |
|
303 | + // but if it has already been dismissed, and we are overriding with a forced update |
|
304 | + if ($existing->getDismissed() && $this->getForceUpdate()) { |
|
305 | + // then toggle the notice's dismissed state to true |
|
306 | + // so that it gets displayed again |
|
307 | + $existing->setDismissed(false); |
|
308 | + // and make sure the message is set |
|
309 | + $existing->setMessage($this->message); |
|
310 | + } |
|
311 | + } else { |
|
312 | + $persistent_admin_notice_collection->add($this, $this->name); |
|
313 | + } |
|
314 | + $this->registered = true; |
|
315 | + } |
|
316 | + |
|
317 | + |
|
318 | + /** |
|
319 | + * @throws Exception |
|
320 | + */ |
|
321 | + public function confirmRegistered() |
|
322 | + { |
|
323 | + if (! apply_filters('PersistentAdminNoticeManager__registerAndSaveNotices__complete', false)) { |
|
324 | + PersistentAdminNoticeManager::loadRegisterAndSaveNotices(); |
|
325 | + } |
|
326 | + if (! $this->registered && WP_DEBUG) { |
|
327 | + throw new DomainException( |
|
328 | + sprintf( |
|
329 | + esc_html__( |
|
330 | + 'The "%1$s" PersistentAdminNotice was not successfully registered. Please ensure that it is being created prior to either the "admin_notices" or "network_admin_notices" hooks being triggered.', |
|
331 | + 'event_espresso' |
|
332 | + ), |
|
333 | + $this->name |
|
334 | + ) |
|
335 | + ); |
|
336 | + } |
|
337 | + } |
|
338 | 338 | } |