@@ -14,328 +14,328 @@ |
||
14 | 14 | class AssetManifest implements AssetManifestInterface |
15 | 15 | { |
16 | 16 | |
17 | - const ASSET_EXT_CSS = '.css'; |
|
18 | - |
|
19 | - const ASSET_EXT_JS = '.js'; |
|
20 | - |
|
21 | - const ASSET_EXT_PHP = '.php'; |
|
22 | - |
|
23 | - const FILE_NAME = 'asset-manifest.json'; |
|
24 | - |
|
25 | - const KEY_DEPENDENCIES = 'dependencies'; |
|
26 | - |
|
27 | - const KEY_ENTRY_POINTS = 'entrypoints'; |
|
28 | - |
|
29 | - const KEY_FILES = 'files'; |
|
30 | - |
|
31 | - const KEY_VERSION = 'version'; |
|
32 | - |
|
33 | - |
|
34 | - /** |
|
35 | - * @var array |
|
36 | - */ |
|
37 | - private $asset_files; |
|
38 | - |
|
39 | - /** |
|
40 | - * @var string |
|
41 | - */ |
|
42 | - private $assets_namespace; |
|
43 | - |
|
44 | - /** |
|
45 | - * @var string |
|
46 | - */ |
|
47 | - private $assets_path; |
|
48 | - |
|
49 | - /** |
|
50 | - * @var DomainInterface |
|
51 | - */ |
|
52 | - protected $domain; |
|
53 | - |
|
54 | - /** |
|
55 | - * @var array |
|
56 | - */ |
|
57 | - private $entry_points; |
|
58 | - |
|
59 | - /** |
|
60 | - * @var array |
|
61 | - */ |
|
62 | - private $manifest; |
|
63 | - |
|
64 | - /** |
|
65 | - * @var string |
|
66 | - */ |
|
67 | - private $manifest_path; |
|
68 | - |
|
69 | - /** |
|
70 | - * This is a list of known handles that are used for css. |
|
71 | - * @var array |
|
72 | - */ |
|
73 | - private $wp_css_handle_dependencies = [ |
|
74 | - 'wp-components', |
|
75 | - 'wp-block-editor', |
|
76 | - 'wp-block-library', |
|
77 | - 'wp-edit-post', |
|
78 | - 'wp-edit-widgets', |
|
79 | - 'wp-editor', |
|
80 | - 'wp-format-library', |
|
81 | - 'wp-list-reusable-blocks', |
|
82 | - 'wp-nux', |
|
83 | - ]; |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * AssetManifest constructor. |
|
88 | - * |
|
89 | - * @param DomainInterface $domain |
|
90 | - */ |
|
91 | - public function __construct(DomainInterface $domain) |
|
92 | - { |
|
93 | - $this->domain = $domain; |
|
94 | - $this->initialize(); |
|
95 | - } |
|
96 | - |
|
97 | - |
|
98 | - /** |
|
99 | - * @return void |
|
100 | - */ |
|
101 | - public function initialize() |
|
102 | - { |
|
103 | - if (! $this->manifest) { |
|
104 | - $this->assets_namespace = $this->domain->assetNamespace(); |
|
105 | - $assets_path = $this->domain->distributionAssetsPath(); |
|
106 | - $this->assets_path = trailingslashit($assets_path); |
|
107 | - $this->setManifestFilepath(); |
|
108 | - $this->loadManifest(); |
|
109 | - $this->getAssetFiles(); |
|
110 | - $this->getEntryPoints(); |
|
111 | - } |
|
112 | - } |
|
113 | - |
|
114 | - |
|
115 | - /** |
|
116 | - * @param string $manifest_path |
|
117 | - */ |
|
118 | - public function setManifestFilepath($manifest_path = '') |
|
119 | - { |
|
120 | - $manifest_path = $manifest_path ? $manifest_path : $this->assets_path . AssetManifest::FILE_NAME; |
|
121 | - if (! is_readable($manifest_path)) { |
|
122 | - throw new AssetManifestException( |
|
123 | - $manifest_path, |
|
124 | - '', |
|
125 | - sprintf( |
|
126 | - esc_html__( |
|
127 | - 'The "%1$s" file was not found or is not readable. Please verify that the file exists and has appropriate permissions.', |
|
128 | - 'event_espresso' |
|
129 | - ), |
|
130 | - $manifest_path |
|
131 | - ) |
|
132 | - ); |
|
133 | - } |
|
134 | - $this->manifest_path = $manifest_path; |
|
135 | - } |
|
136 | - |
|
137 | - |
|
138 | - /** |
|
139 | - * @return void |
|
140 | - */ |
|
141 | - private function loadManifest() |
|
142 | - { |
|
143 | - if (! $this->manifest) { |
|
144 | - // TODO May be use WP File system? ¯\_(ツ)_/¯ |
|
145 | - $manifest_json = file_get_contents($this->manifest_path); |
|
146 | - $this->manifest = json_decode($manifest_json, true); |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * @param string $file_name |
|
153 | - * @return string |
|
154 | - */ |
|
155 | - private function trimAssetFilename($file_name) |
|
156 | - { |
|
157 | - return ltrim($file_name, '/'); |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * @return array |
|
163 | - */ |
|
164 | - public function getAssetFiles() |
|
165 | - { |
|
166 | - if (! $this->asset_files) { |
|
167 | - if (empty($this->manifest[ AssetManifest::KEY_FILES ])) { |
|
168 | - if (WP_DEBUG) { |
|
169 | - throw new AssetManifestException(AssetManifest::KEY_FILES, $this->manifest_path); |
|
170 | - } |
|
171 | - return []; |
|
172 | - } |
|
173 | - $this->asset_files = $this->manifest[ AssetManifest::KEY_FILES ]; |
|
174 | - } |
|
175 | - return $this->asset_files; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @return array |
|
181 | - */ |
|
182 | - public function getEntryPoints() |
|
183 | - { |
|
184 | - if (! $this->entry_points) { |
|
185 | - if (empty($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ])) { |
|
186 | - if (WP_DEBUG) { |
|
187 | - throw new AssetManifestException(AssetManifest::KEY_ENTRY_POINTS, $this->manifest_path); |
|
188 | - } |
|
189 | - return []; |
|
190 | - } |
|
191 | - $this->entry_points = array_keys($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ]); |
|
192 | - } |
|
193 | - return $this->entry_points; |
|
194 | - } |
|
195 | - |
|
196 | - |
|
197 | - /** |
|
198 | - * @param string $entry_point |
|
199 | - * @param string $type |
|
200 | - * @return string |
|
201 | - */ |
|
202 | - private function getAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
203 | - { |
|
204 | - return $this->hasAsset($entry_point, $type) |
|
205 | - ? $this->trimAssetFilename($this->asset_files[ $entry_point . $type ]) |
|
206 | - : ''; |
|
207 | - } |
|
208 | - |
|
209 | - |
|
210 | - /** |
|
211 | - * @param string $entry_point |
|
212 | - * @param string $type |
|
213 | - * @return array |
|
214 | - */ |
|
215 | - public function getAssetDependencies($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
216 | - { |
|
217 | - $asset = $this->getAssetDetails($entry_point); |
|
218 | - if (! isset($asset[AssetManifest::KEY_DEPENDENCIES])) { |
|
219 | - return []; |
|
220 | - } |
|
221 | - $dependencies = $asset[AssetManifest::KEY_DEPENDENCIES]; |
|
222 | - // remove cyclical dependencies, if any |
|
223 | - if (($key = array_search($this->assets_namespace . '-' . $entry_point, $dependencies, true)) !== false) { |
|
224 | - unset($dependencies[ $key ]); |
|
225 | - } |
|
226 | - // currently need to derive dependencies for CSS from the JS dependencies |
|
227 | - if ($type === AssetManifest::ASSET_EXT_CSS) { |
|
228 | - $css_dependencies = []; |
|
229 | - foreach ($dependencies as $handle) { |
|
230 | - $dependency_style = $this->getEntryPointFromHandle($handle) . AssetManifest::ASSET_EXT_CSS; |
|
231 | - if (isset($this->asset_files[ $dependency_style ]) |
|
232 | - || in_array($handle, $this->wp_css_handle_dependencies) |
|
233 | - ) { |
|
234 | - $css_dependencies[] = $handle; |
|
235 | - } |
|
236 | - } |
|
237 | - return $css_dependencies; |
|
238 | - } |
|
239 | - return $dependencies; |
|
240 | - } |
|
241 | - |
|
242 | - |
|
243 | - /** |
|
244 | - * @param string $entry_point |
|
245 | - * @return array |
|
246 | - */ |
|
247 | - public function getAssetDetails($entry_point) |
|
248 | - { |
|
249 | - $file_name = $this->getAsset($entry_point, AssetManifest::ASSET_EXT_PHP); |
|
250 | - if (! $file_name) { |
|
251 | - return []; |
|
252 | - } |
|
253 | - $full_path = $this->assets_path . $file_name; |
|
254 | - if (! is_readable($full_path)) { |
|
255 | - if (WP_DEBUG) { |
|
256 | - throw new AssetManifestException(AssetManifest::KEY_DEPENDENCIES, $full_path); |
|
257 | - } |
|
258 | - return []; |
|
259 | - } |
|
260 | - return require($full_path); |
|
261 | - } |
|
262 | - |
|
263 | - |
|
264 | - /** |
|
265 | - * @param string $entry_point |
|
266 | - * @return string|int|false |
|
267 | - */ |
|
268 | - public function getAssetHandle($entry_point) |
|
269 | - { |
|
270 | - return $this->assets_namespace . '-' . $entry_point; |
|
271 | - } |
|
272 | - |
|
273 | - |
|
274 | - /** |
|
275 | - * @return string |
|
276 | - */ |
|
277 | - public function getAssetsPath() |
|
278 | - { |
|
279 | - return $this->assets_path; |
|
280 | - } |
|
281 | - |
|
282 | - |
|
283 | - /** |
|
284 | - * @param string $handle |
|
285 | - * @return string|int|false |
|
286 | - */ |
|
287 | - private function getEntryPointFromHandle($handle) |
|
288 | - { $find = $this->assets_namespace . '-'; |
|
289 | - return str_replace($find, '', $handle); |
|
290 | - } |
|
291 | - |
|
292 | - |
|
293 | - /** |
|
294 | - * @param string $entry_point |
|
295 | - * @param string $type |
|
296 | - * @return string |
|
297 | - */ |
|
298 | - public function getAssetPath($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
299 | - { |
|
300 | - $file_name = $this->getAsset($entry_point, $type); |
|
301 | - return $file_name ? $this->domain->distributionAssetsPath($file_name) : ''; |
|
302 | - } |
|
303 | - |
|
304 | - |
|
305 | - /** |
|
306 | - * @param string $entry_point |
|
307 | - * @param string $type |
|
308 | - * @return string |
|
309 | - */ |
|
310 | - public function getAssetUrl($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
311 | - { |
|
312 | - $file_name = $this->getAsset($entry_point, $type); |
|
313 | - return $file_name ? $this->domain->distributionAssetsUrl($file_name) : ''; |
|
314 | - } |
|
315 | - |
|
316 | - |
|
317 | - /** |
|
318 | - * @param string $entry_point |
|
319 | - * @param string $type |
|
320 | - * @return string|int|false |
|
321 | - */ |
|
322 | - public function getAssetVersion($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
323 | - { |
|
324 | - $asset = $this->getAssetDetails($entry_point); |
|
325 | - return $type === AssetManifest::ASSET_EXT_JS && isset($asset[AssetManifest::KEY_VERSION]) |
|
326 | - ? $asset[AssetManifest::KEY_VERSION] |
|
327 | - : filemtime($this->getAssetPath($entry_point, $type)); |
|
328 | - } |
|
329 | - |
|
330 | - |
|
331 | - /** |
|
332 | - * @param string $entry_point |
|
333 | - * @param string $type |
|
334 | - * @return string |
|
335 | - */ |
|
336 | - public function hasAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
337 | - { |
|
338 | - $file_name = $entry_point . $type; |
|
339 | - return ! empty($this->asset_files[ $file_name ]); |
|
340 | - } |
|
17 | + const ASSET_EXT_CSS = '.css'; |
|
18 | + |
|
19 | + const ASSET_EXT_JS = '.js'; |
|
20 | + |
|
21 | + const ASSET_EXT_PHP = '.php'; |
|
22 | + |
|
23 | + const FILE_NAME = 'asset-manifest.json'; |
|
24 | + |
|
25 | + const KEY_DEPENDENCIES = 'dependencies'; |
|
26 | + |
|
27 | + const KEY_ENTRY_POINTS = 'entrypoints'; |
|
28 | + |
|
29 | + const KEY_FILES = 'files'; |
|
30 | + |
|
31 | + const KEY_VERSION = 'version'; |
|
32 | + |
|
33 | + |
|
34 | + /** |
|
35 | + * @var array |
|
36 | + */ |
|
37 | + private $asset_files; |
|
38 | + |
|
39 | + /** |
|
40 | + * @var string |
|
41 | + */ |
|
42 | + private $assets_namespace; |
|
43 | + |
|
44 | + /** |
|
45 | + * @var string |
|
46 | + */ |
|
47 | + private $assets_path; |
|
48 | + |
|
49 | + /** |
|
50 | + * @var DomainInterface |
|
51 | + */ |
|
52 | + protected $domain; |
|
53 | + |
|
54 | + /** |
|
55 | + * @var array |
|
56 | + */ |
|
57 | + private $entry_points; |
|
58 | + |
|
59 | + /** |
|
60 | + * @var array |
|
61 | + */ |
|
62 | + private $manifest; |
|
63 | + |
|
64 | + /** |
|
65 | + * @var string |
|
66 | + */ |
|
67 | + private $manifest_path; |
|
68 | + |
|
69 | + /** |
|
70 | + * This is a list of known handles that are used for css. |
|
71 | + * @var array |
|
72 | + */ |
|
73 | + private $wp_css_handle_dependencies = [ |
|
74 | + 'wp-components', |
|
75 | + 'wp-block-editor', |
|
76 | + 'wp-block-library', |
|
77 | + 'wp-edit-post', |
|
78 | + 'wp-edit-widgets', |
|
79 | + 'wp-editor', |
|
80 | + 'wp-format-library', |
|
81 | + 'wp-list-reusable-blocks', |
|
82 | + 'wp-nux', |
|
83 | + ]; |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * AssetManifest constructor. |
|
88 | + * |
|
89 | + * @param DomainInterface $domain |
|
90 | + */ |
|
91 | + public function __construct(DomainInterface $domain) |
|
92 | + { |
|
93 | + $this->domain = $domain; |
|
94 | + $this->initialize(); |
|
95 | + } |
|
96 | + |
|
97 | + |
|
98 | + /** |
|
99 | + * @return void |
|
100 | + */ |
|
101 | + public function initialize() |
|
102 | + { |
|
103 | + if (! $this->manifest) { |
|
104 | + $this->assets_namespace = $this->domain->assetNamespace(); |
|
105 | + $assets_path = $this->domain->distributionAssetsPath(); |
|
106 | + $this->assets_path = trailingslashit($assets_path); |
|
107 | + $this->setManifestFilepath(); |
|
108 | + $this->loadManifest(); |
|
109 | + $this->getAssetFiles(); |
|
110 | + $this->getEntryPoints(); |
|
111 | + } |
|
112 | + } |
|
113 | + |
|
114 | + |
|
115 | + /** |
|
116 | + * @param string $manifest_path |
|
117 | + */ |
|
118 | + public function setManifestFilepath($manifest_path = '') |
|
119 | + { |
|
120 | + $manifest_path = $manifest_path ? $manifest_path : $this->assets_path . AssetManifest::FILE_NAME; |
|
121 | + if (! is_readable($manifest_path)) { |
|
122 | + throw new AssetManifestException( |
|
123 | + $manifest_path, |
|
124 | + '', |
|
125 | + sprintf( |
|
126 | + esc_html__( |
|
127 | + 'The "%1$s" file was not found or is not readable. Please verify that the file exists and has appropriate permissions.', |
|
128 | + 'event_espresso' |
|
129 | + ), |
|
130 | + $manifest_path |
|
131 | + ) |
|
132 | + ); |
|
133 | + } |
|
134 | + $this->manifest_path = $manifest_path; |
|
135 | + } |
|
136 | + |
|
137 | + |
|
138 | + /** |
|
139 | + * @return void |
|
140 | + */ |
|
141 | + private function loadManifest() |
|
142 | + { |
|
143 | + if (! $this->manifest) { |
|
144 | + // TODO May be use WP File system? ¯\_(ツ)_/¯ |
|
145 | + $manifest_json = file_get_contents($this->manifest_path); |
|
146 | + $this->manifest = json_decode($manifest_json, true); |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * @param string $file_name |
|
153 | + * @return string |
|
154 | + */ |
|
155 | + private function trimAssetFilename($file_name) |
|
156 | + { |
|
157 | + return ltrim($file_name, '/'); |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * @return array |
|
163 | + */ |
|
164 | + public function getAssetFiles() |
|
165 | + { |
|
166 | + if (! $this->asset_files) { |
|
167 | + if (empty($this->manifest[ AssetManifest::KEY_FILES ])) { |
|
168 | + if (WP_DEBUG) { |
|
169 | + throw new AssetManifestException(AssetManifest::KEY_FILES, $this->manifest_path); |
|
170 | + } |
|
171 | + return []; |
|
172 | + } |
|
173 | + $this->asset_files = $this->manifest[ AssetManifest::KEY_FILES ]; |
|
174 | + } |
|
175 | + return $this->asset_files; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @return array |
|
181 | + */ |
|
182 | + public function getEntryPoints() |
|
183 | + { |
|
184 | + if (! $this->entry_points) { |
|
185 | + if (empty($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ])) { |
|
186 | + if (WP_DEBUG) { |
|
187 | + throw new AssetManifestException(AssetManifest::KEY_ENTRY_POINTS, $this->manifest_path); |
|
188 | + } |
|
189 | + return []; |
|
190 | + } |
|
191 | + $this->entry_points = array_keys($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ]); |
|
192 | + } |
|
193 | + return $this->entry_points; |
|
194 | + } |
|
195 | + |
|
196 | + |
|
197 | + /** |
|
198 | + * @param string $entry_point |
|
199 | + * @param string $type |
|
200 | + * @return string |
|
201 | + */ |
|
202 | + private function getAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
203 | + { |
|
204 | + return $this->hasAsset($entry_point, $type) |
|
205 | + ? $this->trimAssetFilename($this->asset_files[ $entry_point . $type ]) |
|
206 | + : ''; |
|
207 | + } |
|
208 | + |
|
209 | + |
|
210 | + /** |
|
211 | + * @param string $entry_point |
|
212 | + * @param string $type |
|
213 | + * @return array |
|
214 | + */ |
|
215 | + public function getAssetDependencies($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
216 | + { |
|
217 | + $asset = $this->getAssetDetails($entry_point); |
|
218 | + if (! isset($asset[AssetManifest::KEY_DEPENDENCIES])) { |
|
219 | + return []; |
|
220 | + } |
|
221 | + $dependencies = $asset[AssetManifest::KEY_DEPENDENCIES]; |
|
222 | + // remove cyclical dependencies, if any |
|
223 | + if (($key = array_search($this->assets_namespace . '-' . $entry_point, $dependencies, true)) !== false) { |
|
224 | + unset($dependencies[ $key ]); |
|
225 | + } |
|
226 | + // currently need to derive dependencies for CSS from the JS dependencies |
|
227 | + if ($type === AssetManifest::ASSET_EXT_CSS) { |
|
228 | + $css_dependencies = []; |
|
229 | + foreach ($dependencies as $handle) { |
|
230 | + $dependency_style = $this->getEntryPointFromHandle($handle) . AssetManifest::ASSET_EXT_CSS; |
|
231 | + if (isset($this->asset_files[ $dependency_style ]) |
|
232 | + || in_array($handle, $this->wp_css_handle_dependencies) |
|
233 | + ) { |
|
234 | + $css_dependencies[] = $handle; |
|
235 | + } |
|
236 | + } |
|
237 | + return $css_dependencies; |
|
238 | + } |
|
239 | + return $dependencies; |
|
240 | + } |
|
241 | + |
|
242 | + |
|
243 | + /** |
|
244 | + * @param string $entry_point |
|
245 | + * @return array |
|
246 | + */ |
|
247 | + public function getAssetDetails($entry_point) |
|
248 | + { |
|
249 | + $file_name = $this->getAsset($entry_point, AssetManifest::ASSET_EXT_PHP); |
|
250 | + if (! $file_name) { |
|
251 | + return []; |
|
252 | + } |
|
253 | + $full_path = $this->assets_path . $file_name; |
|
254 | + if (! is_readable($full_path)) { |
|
255 | + if (WP_DEBUG) { |
|
256 | + throw new AssetManifestException(AssetManifest::KEY_DEPENDENCIES, $full_path); |
|
257 | + } |
|
258 | + return []; |
|
259 | + } |
|
260 | + return require($full_path); |
|
261 | + } |
|
262 | + |
|
263 | + |
|
264 | + /** |
|
265 | + * @param string $entry_point |
|
266 | + * @return string|int|false |
|
267 | + */ |
|
268 | + public function getAssetHandle($entry_point) |
|
269 | + { |
|
270 | + return $this->assets_namespace . '-' . $entry_point; |
|
271 | + } |
|
272 | + |
|
273 | + |
|
274 | + /** |
|
275 | + * @return string |
|
276 | + */ |
|
277 | + public function getAssetsPath() |
|
278 | + { |
|
279 | + return $this->assets_path; |
|
280 | + } |
|
281 | + |
|
282 | + |
|
283 | + /** |
|
284 | + * @param string $handle |
|
285 | + * @return string|int|false |
|
286 | + */ |
|
287 | + private function getEntryPointFromHandle($handle) |
|
288 | + { $find = $this->assets_namespace . '-'; |
|
289 | + return str_replace($find, '', $handle); |
|
290 | + } |
|
291 | + |
|
292 | + |
|
293 | + /** |
|
294 | + * @param string $entry_point |
|
295 | + * @param string $type |
|
296 | + * @return string |
|
297 | + */ |
|
298 | + public function getAssetPath($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
299 | + { |
|
300 | + $file_name = $this->getAsset($entry_point, $type); |
|
301 | + return $file_name ? $this->domain->distributionAssetsPath($file_name) : ''; |
|
302 | + } |
|
303 | + |
|
304 | + |
|
305 | + /** |
|
306 | + * @param string $entry_point |
|
307 | + * @param string $type |
|
308 | + * @return string |
|
309 | + */ |
|
310 | + public function getAssetUrl($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
311 | + { |
|
312 | + $file_name = $this->getAsset($entry_point, $type); |
|
313 | + return $file_name ? $this->domain->distributionAssetsUrl($file_name) : ''; |
|
314 | + } |
|
315 | + |
|
316 | + |
|
317 | + /** |
|
318 | + * @param string $entry_point |
|
319 | + * @param string $type |
|
320 | + * @return string|int|false |
|
321 | + */ |
|
322 | + public function getAssetVersion($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
323 | + { |
|
324 | + $asset = $this->getAssetDetails($entry_point); |
|
325 | + return $type === AssetManifest::ASSET_EXT_JS && isset($asset[AssetManifest::KEY_VERSION]) |
|
326 | + ? $asset[AssetManifest::KEY_VERSION] |
|
327 | + : filemtime($this->getAssetPath($entry_point, $type)); |
|
328 | + } |
|
329 | + |
|
330 | + |
|
331 | + /** |
|
332 | + * @param string $entry_point |
|
333 | + * @param string $type |
|
334 | + * @return string |
|
335 | + */ |
|
336 | + public function hasAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
|
337 | + { |
|
338 | + $file_name = $entry_point . $type; |
|
339 | + return ! empty($this->asset_files[ $file_name ]); |
|
340 | + } |
|
341 | 341 | } |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | class AssetManifest implements AssetManifestInterface |
15 | 15 | { |
16 | 16 | |
17 | - const ASSET_EXT_CSS = '.css'; |
|
17 | + const ASSET_EXT_CSS = '.css'; |
|
18 | 18 | |
19 | 19 | const ASSET_EXT_JS = '.js'; |
20 | 20 | |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | */ |
101 | 101 | public function initialize() |
102 | 102 | { |
103 | - if (! $this->manifest) { |
|
103 | + if ( ! $this->manifest) { |
|
104 | 104 | $this->assets_namespace = $this->domain->assetNamespace(); |
105 | 105 | $assets_path = $this->domain->distributionAssetsPath(); |
106 | 106 | $this->assets_path = trailingslashit($assets_path); |
@@ -117,8 +117,8 @@ discard block |
||
117 | 117 | */ |
118 | 118 | public function setManifestFilepath($manifest_path = '') |
119 | 119 | { |
120 | - $manifest_path = $manifest_path ? $manifest_path : $this->assets_path . AssetManifest::FILE_NAME; |
|
121 | - if (! is_readable($manifest_path)) { |
|
120 | + $manifest_path = $manifest_path ? $manifest_path : $this->assets_path.AssetManifest::FILE_NAME; |
|
121 | + if ( ! is_readable($manifest_path)) { |
|
122 | 122 | throw new AssetManifestException( |
123 | 123 | $manifest_path, |
124 | 124 | '', |
@@ -140,7 +140,7 @@ discard block |
||
140 | 140 | */ |
141 | 141 | private function loadManifest() |
142 | 142 | { |
143 | - if (! $this->manifest) { |
|
143 | + if ( ! $this->manifest) { |
|
144 | 144 | // TODO May be use WP File system? ¯\_(ツ)_/¯ |
145 | 145 | $manifest_json = file_get_contents($this->manifest_path); |
146 | 146 | $this->manifest = json_decode($manifest_json, true); |
@@ -163,14 +163,14 @@ discard block |
||
163 | 163 | */ |
164 | 164 | public function getAssetFiles() |
165 | 165 | { |
166 | - if (! $this->asset_files) { |
|
167 | - if (empty($this->manifest[ AssetManifest::KEY_FILES ])) { |
|
166 | + if ( ! $this->asset_files) { |
|
167 | + if (empty($this->manifest[AssetManifest::KEY_FILES])) { |
|
168 | 168 | if (WP_DEBUG) { |
169 | 169 | throw new AssetManifestException(AssetManifest::KEY_FILES, $this->manifest_path); |
170 | 170 | } |
171 | 171 | return []; |
172 | 172 | } |
173 | - $this->asset_files = $this->manifest[ AssetManifest::KEY_FILES ]; |
|
173 | + $this->asset_files = $this->manifest[AssetManifest::KEY_FILES]; |
|
174 | 174 | } |
175 | 175 | return $this->asset_files; |
176 | 176 | } |
@@ -181,14 +181,14 @@ discard block |
||
181 | 181 | */ |
182 | 182 | public function getEntryPoints() |
183 | 183 | { |
184 | - if (! $this->entry_points) { |
|
185 | - if (empty($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ])) { |
|
184 | + if ( ! $this->entry_points) { |
|
185 | + if (empty($this->manifest[AssetManifest::KEY_ENTRY_POINTS])) { |
|
186 | 186 | if (WP_DEBUG) { |
187 | 187 | throw new AssetManifestException(AssetManifest::KEY_ENTRY_POINTS, $this->manifest_path); |
188 | 188 | } |
189 | 189 | return []; |
190 | 190 | } |
191 | - $this->entry_points = array_keys($this->manifest[ AssetManifest::KEY_ENTRY_POINTS ]); |
|
191 | + $this->entry_points = array_keys($this->manifest[AssetManifest::KEY_ENTRY_POINTS]); |
|
192 | 192 | } |
193 | 193 | return $this->entry_points; |
194 | 194 | } |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | private function getAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
203 | 203 | { |
204 | 204 | return $this->hasAsset($entry_point, $type) |
205 | - ? $this->trimAssetFilename($this->asset_files[ $entry_point . $type ]) |
|
205 | + ? $this->trimAssetFilename($this->asset_files[$entry_point.$type]) |
|
206 | 206 | : ''; |
207 | 207 | } |
208 | 208 | |
@@ -215,20 +215,20 @@ discard block |
||
215 | 215 | public function getAssetDependencies($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
216 | 216 | { |
217 | 217 | $asset = $this->getAssetDetails($entry_point); |
218 | - if (! isset($asset[AssetManifest::KEY_DEPENDENCIES])) { |
|
218 | + if ( ! isset($asset[AssetManifest::KEY_DEPENDENCIES])) { |
|
219 | 219 | return []; |
220 | 220 | } |
221 | 221 | $dependencies = $asset[AssetManifest::KEY_DEPENDENCIES]; |
222 | 222 | // remove cyclical dependencies, if any |
223 | - if (($key = array_search($this->assets_namespace . '-' . $entry_point, $dependencies, true)) !== false) { |
|
224 | - unset($dependencies[ $key ]); |
|
223 | + if (($key = array_search($this->assets_namespace.'-'.$entry_point, $dependencies, true)) !== false) { |
|
224 | + unset($dependencies[$key]); |
|
225 | 225 | } |
226 | 226 | // currently need to derive dependencies for CSS from the JS dependencies |
227 | 227 | if ($type === AssetManifest::ASSET_EXT_CSS) { |
228 | 228 | $css_dependencies = []; |
229 | 229 | foreach ($dependencies as $handle) { |
230 | - $dependency_style = $this->getEntryPointFromHandle($handle) . AssetManifest::ASSET_EXT_CSS; |
|
231 | - if (isset($this->asset_files[ $dependency_style ]) |
|
230 | + $dependency_style = $this->getEntryPointFromHandle($handle).AssetManifest::ASSET_EXT_CSS; |
|
231 | + if (isset($this->asset_files[$dependency_style]) |
|
232 | 232 | || in_array($handle, $this->wp_css_handle_dependencies) |
233 | 233 | ) { |
234 | 234 | $css_dependencies[] = $handle; |
@@ -247,11 +247,11 @@ discard block |
||
247 | 247 | public function getAssetDetails($entry_point) |
248 | 248 | { |
249 | 249 | $file_name = $this->getAsset($entry_point, AssetManifest::ASSET_EXT_PHP); |
250 | - if (! $file_name) { |
|
250 | + if ( ! $file_name) { |
|
251 | 251 | return []; |
252 | 252 | } |
253 | - $full_path = $this->assets_path . $file_name; |
|
254 | - if (! is_readable($full_path)) { |
|
253 | + $full_path = $this->assets_path.$file_name; |
|
254 | + if ( ! is_readable($full_path)) { |
|
255 | 255 | if (WP_DEBUG) { |
256 | 256 | throw new AssetManifestException(AssetManifest::KEY_DEPENDENCIES, $full_path); |
257 | 257 | } |
@@ -267,7 +267,7 @@ discard block |
||
267 | 267 | */ |
268 | 268 | public function getAssetHandle($entry_point) |
269 | 269 | { |
270 | - return $this->assets_namespace . '-' . $entry_point; |
|
270 | + return $this->assets_namespace.'-'.$entry_point; |
|
271 | 271 | } |
272 | 272 | |
273 | 273 | |
@@ -285,7 +285,7 @@ discard block |
||
285 | 285 | * @return string|int|false |
286 | 286 | */ |
287 | 287 | private function getEntryPointFromHandle($handle) |
288 | - { $find = $this->assets_namespace . '-'; |
|
288 | + { $find = $this->assets_namespace.'-'; |
|
289 | 289 | return str_replace($find, '', $handle); |
290 | 290 | } |
291 | 291 | |
@@ -335,7 +335,7 @@ discard block |
||
335 | 335 | */ |
336 | 336 | public function hasAsset($entry_point, $type = AssetManifest::ASSET_EXT_JS) |
337 | 337 | { |
338 | - $file_name = $entry_point . $type; |
|
339 | - return ! empty($this->asset_files[ $file_name ]); |
|
338 | + $file_name = $entry_point.$type; |
|
339 | + return ! empty($this->asset_files[$file_name]); |
|
340 | 340 | } |
341 | 341 | } |
@@ -72,13 +72,13 @@ |
||
72 | 72 | private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
73 | 73 | { |
74 | 74 | $domain_fqcn = get_class($domain); |
75 | - if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
75 | + if ( ! isset(BaristaFactory::$baristas[$domain_fqcn])) { |
|
76 | 76 | $barista = new Barista($asset_manifest); |
77 | 77 | // we still need to share this with the core loader to facilitate automatic dependency injection |
78 | 78 | $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
79 | - BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
79 | + BaristaFactory::$baristas[$domain_fqcn] = $barista; |
|
80 | 80 | } |
81 | - return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
81 | + return BaristaFactory::$baristas[$domain_fqcn]; |
|
82 | 82 | } |
83 | 83 | |
84 | 84 |
@@ -11,114 +11,114 @@ |
||
11 | 11 | |
12 | 12 | class BaristaFactory implements FactoryInterface |
13 | 13 | { |
14 | - /** |
|
15 | - * @var AssetManifestFactory |
|
16 | - */ |
|
17 | - private $manifest_factory; |
|
18 | - |
|
19 | - /** |
|
20 | - * @var BaristaInterface[] |
|
21 | - */ |
|
22 | - private static $baristas = []; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var LoaderInterface $loader |
|
26 | - */ |
|
27 | - protected $loader; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * BaristaFactory constructor. |
|
32 | - * |
|
33 | - * @param AssetManifestFactory $manifest_factory |
|
34 | - * @param LoaderInterface $loader |
|
35 | - */ |
|
36 | - public function __construct(AssetManifestFactory $manifest_factory, LoaderInterface $loader) |
|
37 | - { |
|
38 | - $this->manifest_factory = $manifest_factory; |
|
39 | - $this->loader = $loader; |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @param string $domain_fqcn |
|
45 | - * @return BaristaInterface |
|
46 | - */ |
|
47 | - public function createFromDomainClass($domain_fqcn) |
|
48 | - { |
|
49 | - /** @var DomainInterface $domain */ |
|
50 | - $domain = $this->loader->getShared($domain_fqcn); |
|
51 | - return $this->createFromDomainObject($domain); |
|
52 | - } |
|
53 | - |
|
54 | - |
|
55 | - /** |
|
56 | - * @param DomainInterface $domain |
|
57 | - * @return BaristaInterface |
|
58 | - */ |
|
59 | - public function createFromDomainObject($domain) |
|
60 | - { |
|
61 | - $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
62 | - return $this->getBaristaForDomain($asset_manifest, $domain); |
|
63 | - } |
|
64 | - |
|
65 | - |
|
66 | - /** |
|
67 | - * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
68 | - * @param array $domain_arguments arguments required by the applicable DomainInterface class |
|
69 | - * @return BaristaInterface |
|
70 | - */ |
|
71 | - public function create($domain_fqcn = '', $domain_arguments = []) |
|
72 | - { |
|
73 | - $domain = $this->getDomain($domain_fqcn, $domain_arguments); |
|
74 | - $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
75 | - return $this->getBaristaForDomain($asset_manifest, $domain); |
|
76 | - } |
|
77 | - |
|
78 | - |
|
79 | - /** |
|
80 | - * @param AssetManifestInterface $asset_manifest |
|
81 | - * @param DomainInterface $domain |
|
82 | - * @return BaristaInterface |
|
83 | - */ |
|
84 | - private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
|
85 | - { |
|
86 | - $domain_fqcn = get_class($domain); |
|
87 | - if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
88 | - $barista = new Barista($asset_manifest); |
|
89 | - // we still need to share this with the core loader to facilitate automatic dependency injection |
|
90 | - $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
|
91 | - BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
92 | - } |
|
93 | - return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
94 | - } |
|
95 | - |
|
96 | - |
|
97 | - /** |
|
98 | - * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
99 | - * @param array $arguments |
|
100 | - * @return DomainInterface |
|
101 | - */ |
|
102 | - private function getDomain($domain_fqcn, array $arguments = []) |
|
103 | - { |
|
104 | - // if no FQCN is supplied for the domain, then we are loading the defaults for core |
|
105 | - // add-ons will always have to supply their domain FQCN and arguments to retrieve their manifest |
|
106 | - $domain = empty($domain_fqcn) |
|
107 | - ? DomainFactory::getEventEspressoCoreDomain() |
|
108 | - : DomainFactory::getShared(new FullyQualifiedName($domain_fqcn), $arguments); |
|
109 | - if ($domain instanceof DomainInterface) { |
|
110 | - return $domain; |
|
111 | - } |
|
112 | - throw new DomainException( |
|
113 | - sprintf( |
|
114 | - esc_html__( |
|
115 | - 'BaristaFactory::create() requires a fully qualified class name (FQCN) for the currently applicable Domain object. |
|
14 | + /** |
|
15 | + * @var AssetManifestFactory |
|
16 | + */ |
|
17 | + private $manifest_factory; |
|
18 | + |
|
19 | + /** |
|
20 | + * @var BaristaInterface[] |
|
21 | + */ |
|
22 | + private static $baristas = []; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var LoaderInterface $loader |
|
26 | + */ |
|
27 | + protected $loader; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * BaristaFactory constructor. |
|
32 | + * |
|
33 | + * @param AssetManifestFactory $manifest_factory |
|
34 | + * @param LoaderInterface $loader |
|
35 | + */ |
|
36 | + public function __construct(AssetManifestFactory $manifest_factory, LoaderInterface $loader) |
|
37 | + { |
|
38 | + $this->manifest_factory = $manifest_factory; |
|
39 | + $this->loader = $loader; |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @param string $domain_fqcn |
|
45 | + * @return BaristaInterface |
|
46 | + */ |
|
47 | + public function createFromDomainClass($domain_fqcn) |
|
48 | + { |
|
49 | + /** @var DomainInterface $domain */ |
|
50 | + $domain = $this->loader->getShared($domain_fqcn); |
|
51 | + return $this->createFromDomainObject($domain); |
|
52 | + } |
|
53 | + |
|
54 | + |
|
55 | + /** |
|
56 | + * @param DomainInterface $domain |
|
57 | + * @return BaristaInterface |
|
58 | + */ |
|
59 | + public function createFromDomainObject($domain) |
|
60 | + { |
|
61 | + $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
62 | + return $this->getBaristaForDomain($asset_manifest, $domain); |
|
63 | + } |
|
64 | + |
|
65 | + |
|
66 | + /** |
|
67 | + * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
68 | + * @param array $domain_arguments arguments required by the applicable DomainInterface class |
|
69 | + * @return BaristaInterface |
|
70 | + */ |
|
71 | + public function create($domain_fqcn = '', $domain_arguments = []) |
|
72 | + { |
|
73 | + $domain = $this->getDomain($domain_fqcn, $domain_arguments); |
|
74 | + $asset_manifest = $this->manifest_factory->createFromDomainObject($domain); |
|
75 | + return $this->getBaristaForDomain($asset_manifest, $domain); |
|
76 | + } |
|
77 | + |
|
78 | + |
|
79 | + /** |
|
80 | + * @param AssetManifestInterface $asset_manifest |
|
81 | + * @param DomainInterface $domain |
|
82 | + * @return BaristaInterface |
|
83 | + */ |
|
84 | + private function getBaristaForDomain(AssetManifestInterface $asset_manifest, DomainInterface $domain) |
|
85 | + { |
|
86 | + $domain_fqcn = get_class($domain); |
|
87 | + if (! isset(BaristaFactory::$baristas[ $domain_fqcn ])) { |
|
88 | + $barista = new Barista($asset_manifest); |
|
89 | + // we still need to share this with the core loader to facilitate automatic dependency injection |
|
90 | + $this->loader->share(Barista::class, $barista, [$asset_manifest]); |
|
91 | + BaristaFactory::$baristas[ $domain_fqcn ] = $barista; |
|
92 | + } |
|
93 | + return BaristaFactory::$baristas[ $domain_fqcn ]; |
|
94 | + } |
|
95 | + |
|
96 | + |
|
97 | + /** |
|
98 | + * @param string $domain_fqcn Fully Qualified Class Name for the applicable DomainInterface class |
|
99 | + * @param array $arguments |
|
100 | + * @return DomainInterface |
|
101 | + */ |
|
102 | + private function getDomain($domain_fqcn, array $arguments = []) |
|
103 | + { |
|
104 | + // if no FQCN is supplied for the domain, then we are loading the defaults for core |
|
105 | + // add-ons will always have to supply their domain FQCN and arguments to retrieve their manifest |
|
106 | + $domain = empty($domain_fqcn) |
|
107 | + ? DomainFactory::getEventEspressoCoreDomain() |
|
108 | + : DomainFactory::getShared(new FullyQualifiedName($domain_fqcn), $arguments); |
|
109 | + if ($domain instanceof DomainInterface) { |
|
110 | + return $domain; |
|
111 | + } |
|
112 | + throw new DomainException( |
|
113 | + sprintf( |
|
114 | + esc_html__( |
|
115 | + 'BaristaFactory::create() requires a fully qualified class name (FQCN) for the currently applicable Domain object. |
|
116 | 116 | %1$sThe supplied FQCN ("%2$s") is either invalid or the class is missing.', |
117 | - 'event_espresso' |
|
118 | - ), |
|
119 | - '<br />', |
|
120 | - $domain_fqcn |
|
121 | - ) |
|
122 | - ); |
|
123 | - } |
|
117 | + 'event_espresso' |
|
118 | + ), |
|
119 | + '<br />', |
|
120 | + $domain_fqcn |
|
121 | + ) |
|
122 | + ); |
|
123 | + } |
|
124 | 124 | } |
@@ -15,35 +15,35 @@ |
||
15 | 15 | class JedLocaleData |
16 | 16 | { |
17 | 17 | |
18 | - /** |
|
19 | - * @var array $locales |
|
20 | - */ |
|
21 | - protected $locales = []; |
|
18 | + /** |
|
19 | + * @var array $locales |
|
20 | + */ |
|
21 | + protected $locales = []; |
|
22 | 22 | |
23 | - /** |
|
24 | - * Returns Jed-formatted localization data. |
|
25 | - * |
|
26 | - * @param string $domain Translation domain. |
|
27 | - * @return array |
|
28 | - */ |
|
29 | - public function getData($domain = Domain::TEXT_DOMAIN) |
|
30 | - { |
|
31 | - if (! isset($locales[ $domain ])) { |
|
32 | - $translations = get_translations_for_domain($domain); |
|
33 | - $locale = [ |
|
34 | - '' => [ |
|
35 | - 'domain' => $domain, |
|
36 | - 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
37 | - ], |
|
38 | - ]; |
|
39 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
40 | - $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
41 | - } |
|
42 | - foreach ($translations->entries as $id => $entry) { |
|
43 | - $locale[ $id ] = $entry->translations; |
|
44 | - } |
|
45 | - $locales[ $domain ] = $locale; |
|
46 | - } |
|
47 | - return $locales[ $domain ]; |
|
48 | - } |
|
23 | + /** |
|
24 | + * Returns Jed-formatted localization data. |
|
25 | + * |
|
26 | + * @param string $domain Translation domain. |
|
27 | + * @return array |
|
28 | + */ |
|
29 | + public function getData($domain = Domain::TEXT_DOMAIN) |
|
30 | + { |
|
31 | + if (! isset($locales[ $domain ])) { |
|
32 | + $translations = get_translations_for_domain($domain); |
|
33 | + $locale = [ |
|
34 | + '' => [ |
|
35 | + 'domain' => $domain, |
|
36 | + 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
|
37 | + ], |
|
38 | + ]; |
|
39 | + if (! empty($translations->headers['Plural-Forms'])) { |
|
40 | + $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
|
41 | + } |
|
42 | + foreach ($translations->entries as $id => $entry) { |
|
43 | + $locale[ $id ] = $entry->translations; |
|
44 | + } |
|
45 | + $locales[ $domain ] = $locale; |
|
46 | + } |
|
47 | + return $locales[ $domain ]; |
|
48 | + } |
|
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -28,7 +28,7 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function getData($domain = Domain::TEXT_DOMAIN) |
30 | 30 | { |
31 | - if (! isset($locales[ $domain ])) { |
|
31 | + if ( ! isset($locales[$domain])) { |
|
32 | 32 | $translations = get_translations_for_domain($domain); |
33 | 33 | $locale = [ |
34 | 34 | '' => [ |
@@ -36,14 +36,14 @@ discard block |
||
36 | 36 | 'lang' => is_admin() ? EEH_DTT_Helper::get_user_locale() : get_locale() |
37 | 37 | ], |
38 | 38 | ]; |
39 | - if (! empty($translations->headers['Plural-Forms'])) { |
|
39 | + if ( ! empty($translations->headers['Plural-Forms'])) { |
|
40 | 40 | $locale['']['plural_forms'] = $translations->headers['Plural-Forms']; |
41 | 41 | } |
42 | 42 | foreach ($translations->entries as $id => $entry) { |
43 | - $locale[ $id ] = $entry->translations; |
|
43 | + $locale[$id] = $entry->translations; |
|
44 | 44 | } |
45 | - $locales[ $domain ] = $locale; |
|
45 | + $locales[$domain] = $locale; |
|
46 | 46 | } |
47 | - return $locales[ $domain ]; |
|
47 | + return $locales[$domain]; |
|
48 | 48 | } |
49 | 49 | } |
50 | 50 | \ No newline at end of file |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | return; |
151 | 151 | } |
152 | 152 | $attributes = $this->getAttributes(); |
153 | - if (!empty($attributes)) { |
|
153 | + if ( ! empty($attributes)) { |
|
154 | 154 | add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2); |
155 | 155 | } |
156 | 156 | wp_enqueue_script($this->handle()); |
@@ -169,7 +169,7 @@ discard block |
||
169 | 169 | $attributes_string .= " {$key}='{$value}'"; |
170 | 170 | } |
171 | 171 | } |
172 | - $tag = str_replace('></script>', $attributes_string . '></script>', $tag); |
|
172 | + $tag = str_replace('></script>', $attributes_string.'></script>', $tag); |
|
173 | 173 | } |
174 | 174 | |
175 | 175 | return $tag; |
@@ -18,172 +18,172 @@ |
||
18 | 18 | class JavascriptAsset extends BrowserAsset |
19 | 19 | { |
20 | 20 | |
21 | - /** |
|
22 | - * @var boolean $load_in_footer |
|
23 | - */ |
|
24 | - private $load_in_footer = false; |
|
25 | - |
|
26 | - /** |
|
27 | - * @var boolean $requires_translation |
|
28 | - */ |
|
29 | - private $requires_translation = false; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var boolean $has_inline_data |
|
33 | - */ |
|
34 | - private $has_inline_data = false; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Closure $inline_data_callback |
|
38 | - */ |
|
39 | - private $inline_data_callback; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * Asset constructor. |
|
44 | - * |
|
45 | - * @param string $handle |
|
46 | - * @param string $source |
|
47 | - * @param array $dependencies |
|
48 | - * @param bool $load_in_footer |
|
49 | - * @param DomainInterface $domain |
|
50 | - * @param string $version |
|
51 | - * @throws InvalidDataTypeException |
|
52 | - * @throws DomainException |
|
53 | - */ |
|
54 | - public function __construct( |
|
55 | - $handle, |
|
56 | - $source, |
|
57 | - array $dependencies, |
|
58 | - $load_in_footer, |
|
59 | - DomainInterface $domain, |
|
60 | - $version = '' |
|
61 | - ) { |
|
62 | - parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version); |
|
63 | - $this->setLoadInFooter($load_in_footer); |
|
64 | - } |
|
65 | - |
|
66 | - |
|
67 | - /** |
|
68 | - * @return bool |
|
69 | - */ |
|
70 | - public function loadInFooter() |
|
71 | - { |
|
72 | - return $this->load_in_footer; |
|
73 | - } |
|
74 | - |
|
75 | - |
|
76 | - /** |
|
77 | - * @param bool $load_in_footer |
|
78 | - */ |
|
79 | - private function setLoadInFooter($load_in_footer = true) |
|
80 | - { |
|
81 | - $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
82 | - } |
|
83 | - |
|
84 | - |
|
85 | - /** |
|
86 | - * @return bool |
|
87 | - */ |
|
88 | - public function requiresTranslation() |
|
89 | - { |
|
90 | - return $this->requires_translation; |
|
91 | - } |
|
92 | - |
|
93 | - |
|
94 | - /** |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function hasInlineData() |
|
98 | - { |
|
99 | - return $this->has_inline_data; |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * @param bool $has_inline_data |
|
105 | - * @return JavascriptAsset |
|
106 | - */ |
|
107 | - public function setHasInlineData($has_inline_data = true) |
|
108 | - { |
|
109 | - $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN); |
|
110 | - return $this; |
|
111 | - } |
|
112 | - |
|
113 | - |
|
114 | - /** |
|
115 | - * @return Closure |
|
116 | - */ |
|
117 | - public function inlineDataCallback() |
|
118 | - { |
|
119 | - return $this->inline_data_callback; |
|
120 | - } |
|
121 | - |
|
122 | - |
|
123 | - /** |
|
124 | - * @return bool |
|
125 | - */ |
|
126 | - public function hasInlineDataCallback() |
|
127 | - { |
|
128 | - return $this->inline_data_callback instanceof Closure; |
|
129 | - } |
|
130 | - |
|
131 | - |
|
132 | - /** |
|
133 | - * @param Closure $inline_data_callback |
|
134 | - * @return JavascriptAsset |
|
135 | - */ |
|
136 | - public function setInlineDataCallback($inline_data_callback) |
|
137 | - { |
|
138 | - $this->inline_data_callback = $inline_data_callback; |
|
139 | - $this->setHasInlineData(); |
|
140 | - return $this; |
|
141 | - } |
|
142 | - |
|
143 | - |
|
144 | - /** |
|
145 | - * @since 4.9.62.p |
|
146 | - */ |
|
147 | - public function enqueueAsset() |
|
148 | - { |
|
149 | - if ($this->source() === '') { |
|
150 | - return; |
|
151 | - } |
|
152 | - $attributes = $this->getAttributes(); |
|
153 | - if (!empty($attributes)) { |
|
154 | - add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2); |
|
155 | - } |
|
156 | - wp_enqueue_script($this->handle()); |
|
157 | - } |
|
158 | - |
|
159 | - |
|
160 | - public function addAttributeTagsToScript($tag, $handle) |
|
161 | - { |
|
162 | - if ($handle === $this->handle()) { |
|
163 | - $attributes = $this->getAttributes(); |
|
164 | - $attributes_string = ''; |
|
165 | - foreach ($attributes as $key => $value) { |
|
166 | - if (is_int($key)) { |
|
167 | - $attributes_string .= " {$value}"; |
|
168 | - } else { |
|
169 | - $attributes_string .= " {$key}='{$value}'"; |
|
170 | - } |
|
171 | - } |
|
172 | - $tag = str_replace('></script>', $attributes_string . '></script>', $tag); |
|
173 | - } |
|
174 | - |
|
175 | - return $tag; |
|
176 | - } |
|
177 | - |
|
178 | - |
|
179 | - /** |
|
180 | - * @deprecated $VID:$ |
|
181 | - * @param bool $requires_translation |
|
182 | - * @return JavascriptAsset |
|
183 | - */ |
|
184 | - public function setRequiresTranslation($requires_translation = true) |
|
185 | - { |
|
186 | - $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
187 | - return $this; |
|
188 | - } |
|
21 | + /** |
|
22 | + * @var boolean $load_in_footer |
|
23 | + */ |
|
24 | + private $load_in_footer = false; |
|
25 | + |
|
26 | + /** |
|
27 | + * @var boolean $requires_translation |
|
28 | + */ |
|
29 | + private $requires_translation = false; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var boolean $has_inline_data |
|
33 | + */ |
|
34 | + private $has_inline_data = false; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Closure $inline_data_callback |
|
38 | + */ |
|
39 | + private $inline_data_callback; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * Asset constructor. |
|
44 | + * |
|
45 | + * @param string $handle |
|
46 | + * @param string $source |
|
47 | + * @param array $dependencies |
|
48 | + * @param bool $load_in_footer |
|
49 | + * @param DomainInterface $domain |
|
50 | + * @param string $version |
|
51 | + * @throws InvalidDataTypeException |
|
52 | + * @throws DomainException |
|
53 | + */ |
|
54 | + public function __construct( |
|
55 | + $handle, |
|
56 | + $source, |
|
57 | + array $dependencies, |
|
58 | + $load_in_footer, |
|
59 | + DomainInterface $domain, |
|
60 | + $version = '' |
|
61 | + ) { |
|
62 | + parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version); |
|
63 | + $this->setLoadInFooter($load_in_footer); |
|
64 | + } |
|
65 | + |
|
66 | + |
|
67 | + /** |
|
68 | + * @return bool |
|
69 | + */ |
|
70 | + public function loadInFooter() |
|
71 | + { |
|
72 | + return $this->load_in_footer; |
|
73 | + } |
|
74 | + |
|
75 | + |
|
76 | + /** |
|
77 | + * @param bool $load_in_footer |
|
78 | + */ |
|
79 | + private function setLoadInFooter($load_in_footer = true) |
|
80 | + { |
|
81 | + $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN); |
|
82 | + } |
|
83 | + |
|
84 | + |
|
85 | + /** |
|
86 | + * @return bool |
|
87 | + */ |
|
88 | + public function requiresTranslation() |
|
89 | + { |
|
90 | + return $this->requires_translation; |
|
91 | + } |
|
92 | + |
|
93 | + |
|
94 | + /** |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function hasInlineData() |
|
98 | + { |
|
99 | + return $this->has_inline_data; |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * @param bool $has_inline_data |
|
105 | + * @return JavascriptAsset |
|
106 | + */ |
|
107 | + public function setHasInlineData($has_inline_data = true) |
|
108 | + { |
|
109 | + $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN); |
|
110 | + return $this; |
|
111 | + } |
|
112 | + |
|
113 | + |
|
114 | + /** |
|
115 | + * @return Closure |
|
116 | + */ |
|
117 | + public function inlineDataCallback() |
|
118 | + { |
|
119 | + return $this->inline_data_callback; |
|
120 | + } |
|
121 | + |
|
122 | + |
|
123 | + /** |
|
124 | + * @return bool |
|
125 | + */ |
|
126 | + public function hasInlineDataCallback() |
|
127 | + { |
|
128 | + return $this->inline_data_callback instanceof Closure; |
|
129 | + } |
|
130 | + |
|
131 | + |
|
132 | + /** |
|
133 | + * @param Closure $inline_data_callback |
|
134 | + * @return JavascriptAsset |
|
135 | + */ |
|
136 | + public function setInlineDataCallback($inline_data_callback) |
|
137 | + { |
|
138 | + $this->inline_data_callback = $inline_data_callback; |
|
139 | + $this->setHasInlineData(); |
|
140 | + return $this; |
|
141 | + } |
|
142 | + |
|
143 | + |
|
144 | + /** |
|
145 | + * @since 4.9.62.p |
|
146 | + */ |
|
147 | + public function enqueueAsset() |
|
148 | + { |
|
149 | + if ($this->source() === '') { |
|
150 | + return; |
|
151 | + } |
|
152 | + $attributes = $this->getAttributes(); |
|
153 | + if (!empty($attributes)) { |
|
154 | + add_filter('script_loader_tag', [$this, 'addAttributeTagsToScript'], 10, 2); |
|
155 | + } |
|
156 | + wp_enqueue_script($this->handle()); |
|
157 | + } |
|
158 | + |
|
159 | + |
|
160 | + public function addAttributeTagsToScript($tag, $handle) |
|
161 | + { |
|
162 | + if ($handle === $this->handle()) { |
|
163 | + $attributes = $this->getAttributes(); |
|
164 | + $attributes_string = ''; |
|
165 | + foreach ($attributes as $key => $value) { |
|
166 | + if (is_int($key)) { |
|
167 | + $attributes_string .= " {$value}"; |
|
168 | + } else { |
|
169 | + $attributes_string .= " {$key}='{$value}'"; |
|
170 | + } |
|
171 | + } |
|
172 | + $tag = str_replace('></script>', $attributes_string . '></script>', $tag); |
|
173 | + } |
|
174 | + |
|
175 | + return $tag; |
|
176 | + } |
|
177 | + |
|
178 | + |
|
179 | + /** |
|
180 | + * @deprecated $VID:$ |
|
181 | + * @param bool $requires_translation |
|
182 | + * @return JavascriptAsset |
|
183 | + */ |
|
184 | + public function setRequiresTranslation($requires_translation = true) |
|
185 | + { |
|
186 | + $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN); |
|
187 | + return $this; |
|
188 | + } |
|
189 | 189 | } |
@@ -14,19 +14,19 @@ |
||
14 | 14 | */ |
15 | 15 | class EventEditorAssetManager extends ReactAssetManager |
16 | 16 | { |
17 | - const DOMAIN = 'eventEditor'; |
|
17 | + const DOMAIN = 'eventEditor'; |
|
18 | 18 | |
19 | - const ASSET_HANDLE_EVENT_EDITOR = Domain::ASSET_NAMESPACE . '-' . EventEditorAssetManager::DOMAIN; |
|
19 | + const ASSET_HANDLE_EVENT_EDITOR = Domain::ASSET_NAMESPACE . '-' . EventEditorAssetManager::DOMAIN; |
|
20 | 20 | |
21 | 21 | |
22 | - /** |
|
23 | - * @throws DomainException |
|
24 | - */ |
|
25 | - public function enqueueEventEditor() |
|
26 | - { |
|
27 | - if ($this->verifyAssetIsRegistered(EventEditorAssetManager::ASSET_HANDLE_EVENT_EDITOR)) { |
|
28 | - wp_enqueue_script(EventEditorAssetManager::ASSET_HANDLE_EVENT_EDITOR); |
|
29 | - wp_enqueue_style(EventEditorAssetManager::ASSET_HANDLE_EVENT_EDITOR); |
|
30 | - } |
|
31 | - } |
|
22 | + /** |
|
23 | + * @throws DomainException |
|
24 | + */ |
|
25 | + public function enqueueEventEditor() |
|
26 | + { |
|
27 | + if ($this->verifyAssetIsRegistered(EventEditorAssetManager::ASSET_HANDLE_EVENT_EDITOR)) { |
|
28 | + wp_enqueue_script(EventEditorAssetManager::ASSET_HANDLE_EVENT_EDITOR); |
|
29 | + wp_enqueue_style(EventEditorAssetManager::ASSET_HANDLE_EVENT_EDITOR); |
|
30 | + } |
|
31 | + } |
|
32 | 32 | } |
@@ -16,7 +16,7 @@ |
||
16 | 16 | { |
17 | 17 | const DOMAIN = 'eventEditor'; |
18 | 18 | |
19 | - const ASSET_HANDLE_EVENT_EDITOR = Domain::ASSET_NAMESPACE . '-' . EventEditorAssetManager::DOMAIN; |
|
19 | + const ASSET_HANDLE_EVENT_EDITOR = Domain::ASSET_NAMESPACE.'-'.EventEditorAssetManager::DOMAIN; |
|
20 | 20 | |
21 | 21 | |
22 | 22 | /** |
@@ -15,18 +15,18 @@ |
||
15 | 15 | */ |
16 | 16 | class WordPressPluginsPageAssetManager extends ReactAssetManager |
17 | 17 | { |
18 | - const DOMAIN = 'wpPluginsPage'; |
|
18 | + const DOMAIN = 'wpPluginsPage'; |
|
19 | 19 | |
20 | - const ASSET_HANDLE_WP_PLUGINS_PAGE = Domain::ASSET_NAMESPACE . '-' . WordPressPluginsPageAssetManager::DOMAIN; |
|
20 | + const ASSET_HANDLE_WP_PLUGINS_PAGE = Domain::ASSET_NAMESPACE . '-' . WordPressPluginsPageAssetManager::DOMAIN; |
|
21 | 21 | |
22 | - /** |
|
23 | - * @throws DomainException |
|
24 | - */ |
|
25 | - public function enqueueAssets() |
|
26 | - { |
|
27 | - if ($this->verifyAssetIsRegistered(WordPressPluginsPageAssetManager::ASSET_HANDLE_WP_PLUGINS_PAGE)) { |
|
28 | - wp_enqueue_script(WordPressPluginsPageAssetManager::ASSET_HANDLE_WP_PLUGINS_PAGE); |
|
29 | - wp_enqueue_style(WordPressPluginsPageAssetManager::ASSET_HANDLE_WP_PLUGINS_PAGE); |
|
30 | - } |
|
31 | - } |
|
22 | + /** |
|
23 | + * @throws DomainException |
|
24 | + */ |
|
25 | + public function enqueueAssets() |
|
26 | + { |
|
27 | + if ($this->verifyAssetIsRegistered(WordPressPluginsPageAssetManager::ASSET_HANDLE_WP_PLUGINS_PAGE)) { |
|
28 | + wp_enqueue_script(WordPressPluginsPageAssetManager::ASSET_HANDLE_WP_PLUGINS_PAGE); |
|
29 | + wp_enqueue_style(WordPressPluginsPageAssetManager::ASSET_HANDLE_WP_PLUGINS_PAGE); |
|
30 | + } |
|
31 | + } |
|
32 | 32 | } |
@@ -17,7 +17,7 @@ |
||
17 | 17 | { |
18 | 18 | const DOMAIN = 'wpPluginsPage'; |
19 | 19 | |
20 | - const ASSET_HANDLE_WP_PLUGINS_PAGE = Domain::ASSET_NAMESPACE . '-' . WordPressPluginsPageAssetManager::DOMAIN; |
|
20 | + const ASSET_HANDLE_WP_PLUGINS_PAGE = Domain::ASSET_NAMESPACE.'-'.WordPressPluginsPageAssetManager::DOMAIN; |
|
21 | 21 | |
22 | 22 | /** |
23 | 23 | * @throws DomainException |
@@ -76,7 +76,7 @@ discard block |
||
76 | 76 | { |
77 | 77 | $setterOrGetter = $this->convertCase($property, $getter); |
78 | 78 | // if not a getter, prepend with "set". ex: Show_expired => setShowExpired |
79 | - $setterOrGetter = ! $getter ? 'set' . $setterOrGetter : $setterOrGetter; |
|
79 | + $setterOrGetter = ! $getter ? 'set'.$setterOrGetter : $setterOrGetter; |
|
80 | 80 | return $this->isValidMethod($setterOrGetter) ? $setterOrGetter : ''; |
81 | 81 | } |
82 | 82 | |
@@ -125,7 +125,7 @@ discard block |
||
125 | 125 | } |
126 | 126 | // convert to PascalCase and prepend with "set". ex: show_expired => setShowExpired |
127 | 127 | $setter = $this->createGetterSetter($property, false); |
128 | - $value = array_key_exists($property, $config) ? $config[ $property ] : null; |
|
128 | + $value = array_key_exists($property, $config) ? $config[$property] : null; |
|
129 | 129 | $this->{$setter}($value); |
130 | 130 | } |
131 | 131 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | continue; |
195 | 195 | } |
196 | 196 | $getter = $this->createGetterSetter($property); |
197 | - $config[ $property ] = $this->{$getter}(); |
|
197 | + $config[$property] = $this->{$getter}(); |
|
198 | 198 | } |
199 | 199 | $config = wp_json_encode($config); |
200 | 200 | if ($config_exists) { |
@@ -16,191 +16,191 @@ |
||
16 | 16 | */ |
17 | 17 | abstract class JsonConfig |
18 | 18 | { |
19 | - /** |
|
20 | - * @var boolean $has_changes |
|
21 | - */ |
|
22 | - private $has_changes = false; |
|
23 | - |
|
24 | - /** |
|
25 | - * @var string $option_name |
|
26 | - */ |
|
27 | - private $option_name; |
|
28 | - |
|
29 | - |
|
30 | - /** |
|
31 | - * SettingsConfig constructor. |
|
32 | - * |
|
33 | - * @param array $defaults |
|
34 | - */ |
|
35 | - public function __construct(array $defaults) |
|
36 | - { |
|
37 | - $this->setOptionName(); |
|
38 | - $this->load($defaults); |
|
39 | - $this->clearChanges(); |
|
40 | - } |
|
41 | - |
|
42 | - |
|
43 | - /** |
|
44 | - * @return array |
|
45 | - */ |
|
46 | - abstract protected function getProperties(); |
|
47 | - |
|
48 | - |
|
49 | - /** |
|
50 | - * converts property name to: |
|
51 | - * camelCase for getters ex: show_expired => showExpired |
|
52 | - * PascalCase for setters ex: show_expired => ShowExpired |
|
53 | - * |
|
54 | - * @param string $string |
|
55 | - * @param false $camelCase |
|
56 | - * @return string|string[] |
|
57 | - * @since $VID:$ |
|
58 | - */ |
|
59 | - private function convertCase($string, $camelCase = false) |
|
60 | - { |
|
61 | - $string = str_replace(' ', '', ucwords(str_replace('_', ' ', $string))); |
|
62 | - if ($camelCase) { |
|
63 | - $string = lcfirst($string); |
|
64 | - } |
|
65 | - return $string; |
|
66 | - } |
|
67 | - |
|
68 | - |
|
69 | - /** |
|
70 | - * @param string $property |
|
71 | - * @param bool $getter |
|
72 | - * @return string |
|
73 | - */ |
|
74 | - private function createGetterSetter($property, $getter = true) |
|
75 | - { |
|
76 | - $setterOrGetter = $this->convertCase($property, $getter); |
|
77 | - // if not a getter, prepend with "set". ex: Show_expired => setShowExpired |
|
78 | - $setterOrGetter = ! $getter ? 'set' . $setterOrGetter : $setterOrGetter; |
|
79 | - return $this->isValidMethod($setterOrGetter) ? $setterOrGetter : ''; |
|
80 | - } |
|
81 | - |
|
82 | - |
|
83 | - /** |
|
84 | - * @param string $method |
|
85 | - * @return bool |
|
86 | - * @throws DomainException |
|
87 | - */ |
|
88 | - private function isValidMethod($method) |
|
89 | - { |
|
90 | - if (method_exists($this, $method)) { |
|
91 | - return true; |
|
92 | - } |
|
93 | - throw new DomainException( |
|
94 | - sprintf( |
|
95 | - esc_html__('Missing %1$s method on JsonConfig class %2$s.', 'event_espresso'), |
|
96 | - $method, |
|
97 | - get_class($this) |
|
98 | - ) |
|
99 | - ); |
|
100 | - } |
|
101 | - |
|
102 | - |
|
103 | - /** |
|
104 | - * converts class name to option name by changing backslashes to dashes |
|
105 | - */ |
|
106 | - private function setOptionName() |
|
107 | - { |
|
108 | - $this->option_name = str_replace(['EventEspresso', '\\'], ['ee', '-'], get_class($this)); |
|
109 | - } |
|
110 | - |
|
111 | - |
|
112 | - /** |
|
113 | - * retrieves WP option for class, decodes the data, and resigns values to properties |
|
114 | - * |
|
115 | - * @param array $defaults |
|
116 | - */ |
|
117 | - protected function load($defaults) |
|
118 | - { |
|
119 | - $config = get_option($this->option_name, '{}'); |
|
120 | - $config = (array) json_decode($config) + $defaults; |
|
121 | - foreach ($this->getProperties() as $property => $value) { |
|
122 | - if ($property === 'option_name') { |
|
123 | - continue; |
|
124 | - } |
|
125 | - // convert to PascalCase and prepend with "set". ex: show_expired => setShowExpired |
|
126 | - $setter = $this->createGetterSetter($property, false); |
|
127 | - $value = array_key_exists($property, $config) ? $config[ $property ] : null; |
|
128 | - $this->{$setter}($value); |
|
129 | - } |
|
130 | - } |
|
131 | - |
|
132 | - |
|
133 | - /** |
|
134 | - * updates property value and marks changes if property value has changed |
|
135 | - * |
|
136 | - * @param string $property |
|
137 | - * @param mixed $value |
|
138 | - */ |
|
139 | - protected function setProperty($property, $value) |
|
140 | - { |
|
141 | - $this->markChanges($this->{$property} === $value); |
|
142 | - $this->{$property} = $value; |
|
143 | - } |
|
144 | - |
|
145 | - |
|
146 | - /** |
|
147 | - * will only toggle has_changes to true otherwise keeps existing value (ie: will never toggle to false) |
|
148 | - * why? this allows this method to be fed with the result of a conditional |
|
149 | - * that compares an incoming value in a setter with it's previously set value. |
|
150 | - * ie: if $x = 1 and you call setX(1) then the value has not really changed. |
|
151 | - * |
|
152 | - * @param bool $changes |
|
153 | - * @since $VID:$ |
|
154 | - */ |
|
155 | - protected function markChanges($changes = true) |
|
156 | - { |
|
157 | - $this->has_changes = filter_var($changes, FILTER_VALIDATE_BOOLEAN) ? true : $this->has_changes; |
|
158 | - } |
|
159 | - |
|
160 | - |
|
161 | - /** |
|
162 | - * resets $has_changes flag to false but does NOT actually reset any data |
|
163 | - */ |
|
164 | - public function clearChanges() |
|
165 | - { |
|
166 | - $this->has_changes = false; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * flag for marking that changes have been made to property data |
|
172 | - * |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function hasChanges() |
|
176 | - { |
|
177 | - return $this->has_changes; |
|
178 | - } |
|
179 | - |
|
180 | - |
|
181 | - /** |
|
182 | - * encodes all property data to JSON and saves it to a WP option |
|
183 | - */ |
|
184 | - public function update() |
|
185 | - { |
|
186 | - $config_exists = get_option($this->option_name); |
|
187 | - if ($config_exists && ! $this->has_changes) { |
|
188 | - return; |
|
189 | - } |
|
190 | - $config = []; |
|
191 | - foreach ($this->getProperties() as $property => $value) { |
|
192 | - if ($property === 'option_name') { |
|
193 | - continue; |
|
194 | - } |
|
195 | - $getter = $this->createGetterSetter($property); |
|
196 | - $config[ $property ] = $this->{$getter}(); |
|
197 | - } |
|
198 | - $config = wp_json_encode($config); |
|
199 | - if ($config_exists) { |
|
200 | - update_option($this->option_name, $config); |
|
201 | - } else { |
|
202 | - add_option($this->option_name, $config, '', 'no'); |
|
203 | - } |
|
204 | - $this->clearChanges(); |
|
205 | - } |
|
19 | + /** |
|
20 | + * @var boolean $has_changes |
|
21 | + */ |
|
22 | + private $has_changes = false; |
|
23 | + |
|
24 | + /** |
|
25 | + * @var string $option_name |
|
26 | + */ |
|
27 | + private $option_name; |
|
28 | + |
|
29 | + |
|
30 | + /** |
|
31 | + * SettingsConfig constructor. |
|
32 | + * |
|
33 | + * @param array $defaults |
|
34 | + */ |
|
35 | + public function __construct(array $defaults) |
|
36 | + { |
|
37 | + $this->setOptionName(); |
|
38 | + $this->load($defaults); |
|
39 | + $this->clearChanges(); |
|
40 | + } |
|
41 | + |
|
42 | + |
|
43 | + /** |
|
44 | + * @return array |
|
45 | + */ |
|
46 | + abstract protected function getProperties(); |
|
47 | + |
|
48 | + |
|
49 | + /** |
|
50 | + * converts property name to: |
|
51 | + * camelCase for getters ex: show_expired => showExpired |
|
52 | + * PascalCase for setters ex: show_expired => ShowExpired |
|
53 | + * |
|
54 | + * @param string $string |
|
55 | + * @param false $camelCase |
|
56 | + * @return string|string[] |
|
57 | + * @since $VID:$ |
|
58 | + */ |
|
59 | + private function convertCase($string, $camelCase = false) |
|
60 | + { |
|
61 | + $string = str_replace(' ', '', ucwords(str_replace('_', ' ', $string))); |
|
62 | + if ($camelCase) { |
|
63 | + $string = lcfirst($string); |
|
64 | + } |
|
65 | + return $string; |
|
66 | + } |
|
67 | + |
|
68 | + |
|
69 | + /** |
|
70 | + * @param string $property |
|
71 | + * @param bool $getter |
|
72 | + * @return string |
|
73 | + */ |
|
74 | + private function createGetterSetter($property, $getter = true) |
|
75 | + { |
|
76 | + $setterOrGetter = $this->convertCase($property, $getter); |
|
77 | + // if not a getter, prepend with "set". ex: Show_expired => setShowExpired |
|
78 | + $setterOrGetter = ! $getter ? 'set' . $setterOrGetter : $setterOrGetter; |
|
79 | + return $this->isValidMethod($setterOrGetter) ? $setterOrGetter : ''; |
|
80 | + } |
|
81 | + |
|
82 | + |
|
83 | + /** |
|
84 | + * @param string $method |
|
85 | + * @return bool |
|
86 | + * @throws DomainException |
|
87 | + */ |
|
88 | + private function isValidMethod($method) |
|
89 | + { |
|
90 | + if (method_exists($this, $method)) { |
|
91 | + return true; |
|
92 | + } |
|
93 | + throw new DomainException( |
|
94 | + sprintf( |
|
95 | + esc_html__('Missing %1$s method on JsonConfig class %2$s.', 'event_espresso'), |
|
96 | + $method, |
|
97 | + get_class($this) |
|
98 | + ) |
|
99 | + ); |
|
100 | + } |
|
101 | + |
|
102 | + |
|
103 | + /** |
|
104 | + * converts class name to option name by changing backslashes to dashes |
|
105 | + */ |
|
106 | + private function setOptionName() |
|
107 | + { |
|
108 | + $this->option_name = str_replace(['EventEspresso', '\\'], ['ee', '-'], get_class($this)); |
|
109 | + } |
|
110 | + |
|
111 | + |
|
112 | + /** |
|
113 | + * retrieves WP option for class, decodes the data, and resigns values to properties |
|
114 | + * |
|
115 | + * @param array $defaults |
|
116 | + */ |
|
117 | + protected function load($defaults) |
|
118 | + { |
|
119 | + $config = get_option($this->option_name, '{}'); |
|
120 | + $config = (array) json_decode($config) + $defaults; |
|
121 | + foreach ($this->getProperties() as $property => $value) { |
|
122 | + if ($property === 'option_name') { |
|
123 | + continue; |
|
124 | + } |
|
125 | + // convert to PascalCase and prepend with "set". ex: show_expired => setShowExpired |
|
126 | + $setter = $this->createGetterSetter($property, false); |
|
127 | + $value = array_key_exists($property, $config) ? $config[ $property ] : null; |
|
128 | + $this->{$setter}($value); |
|
129 | + } |
|
130 | + } |
|
131 | + |
|
132 | + |
|
133 | + /** |
|
134 | + * updates property value and marks changes if property value has changed |
|
135 | + * |
|
136 | + * @param string $property |
|
137 | + * @param mixed $value |
|
138 | + */ |
|
139 | + protected function setProperty($property, $value) |
|
140 | + { |
|
141 | + $this->markChanges($this->{$property} === $value); |
|
142 | + $this->{$property} = $value; |
|
143 | + } |
|
144 | + |
|
145 | + |
|
146 | + /** |
|
147 | + * will only toggle has_changes to true otherwise keeps existing value (ie: will never toggle to false) |
|
148 | + * why? this allows this method to be fed with the result of a conditional |
|
149 | + * that compares an incoming value in a setter with it's previously set value. |
|
150 | + * ie: if $x = 1 and you call setX(1) then the value has not really changed. |
|
151 | + * |
|
152 | + * @param bool $changes |
|
153 | + * @since $VID:$ |
|
154 | + */ |
|
155 | + protected function markChanges($changes = true) |
|
156 | + { |
|
157 | + $this->has_changes = filter_var($changes, FILTER_VALIDATE_BOOLEAN) ? true : $this->has_changes; |
|
158 | + } |
|
159 | + |
|
160 | + |
|
161 | + /** |
|
162 | + * resets $has_changes flag to false but does NOT actually reset any data |
|
163 | + */ |
|
164 | + public function clearChanges() |
|
165 | + { |
|
166 | + $this->has_changes = false; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * flag for marking that changes have been made to property data |
|
172 | + * |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function hasChanges() |
|
176 | + { |
|
177 | + return $this->has_changes; |
|
178 | + } |
|
179 | + |
|
180 | + |
|
181 | + /** |
|
182 | + * encodes all property data to JSON and saves it to a WP option |
|
183 | + */ |
|
184 | + public function update() |
|
185 | + { |
|
186 | + $config_exists = get_option($this->option_name); |
|
187 | + if ($config_exists && ! $this->has_changes) { |
|
188 | + return; |
|
189 | + } |
|
190 | + $config = []; |
|
191 | + foreach ($this->getProperties() as $property => $value) { |
|
192 | + if ($property === 'option_name') { |
|
193 | + continue; |
|
194 | + } |
|
195 | + $getter = $this->createGetterSetter($property); |
|
196 | + $config[ $property ] = $this->{$getter}(); |
|
197 | + } |
|
198 | + $config = wp_json_encode($config); |
|
199 | + if ($config_exists) { |
|
200 | + update_option($this->option_name, $config); |
|
201 | + } else { |
|
202 | + add_option($this->option_name, $config, '', 'no'); |
|
203 | + } |
|
204 | + $this->clearChanges(); |
|
205 | + } |
|
206 | 206 | } |
@@ -7,32 +7,32 @@ |
||
7 | 7 | |
8 | 8 | class Capabilities extends JsonDataNode |
9 | 9 | { |
10 | - const NODE_NAME = 'capabilities'; |
|
10 | + const NODE_NAME = 'capabilities'; |
|
11 | 11 | |
12 | 12 | |
13 | - /** |
|
14 | - * @param JsonDataNodeValidator $validator |
|
15 | - */ |
|
16 | - public function __construct(JsonDataNodeValidator $validator) |
|
17 | - { |
|
18 | - parent::__construct($validator); |
|
19 | - $this->setNodeName(Capabilities::NODE_NAME); |
|
20 | - } |
|
13 | + /** |
|
14 | + * @param JsonDataNodeValidator $validator |
|
15 | + */ |
|
16 | + public function __construct(JsonDataNodeValidator $validator) |
|
17 | + { |
|
18 | + parent::__construct($validator); |
|
19 | + $this->setNodeName(Capabilities::NODE_NAME); |
|
20 | + } |
|
21 | 21 | |
22 | 22 | |
23 | - /** |
|
24 | - * @inheritDoc |
|
25 | - */ |
|
26 | - public function initialize() |
|
27 | - { |
|
28 | - $current_user = wp_get_current_user(); |
|
29 | - $capabilities = []; |
|
30 | - $role_capabilities = $current_user->get_role_caps(); |
|
31 | - foreach ($role_capabilities as $capability => $you_can_do_it) { |
|
32 | - if ($you_can_do_it) { |
|
33 | - $capabilities[] = $capability; |
|
34 | - } |
|
35 | - } |
|
36 | - $this->setDataArray($capabilities); |
|
37 | - } |
|
23 | + /** |
|
24 | + * @inheritDoc |
|
25 | + */ |
|
26 | + public function initialize() |
|
27 | + { |
|
28 | + $current_user = wp_get_current_user(); |
|
29 | + $capabilities = []; |
|
30 | + $role_capabilities = $current_user->get_role_caps(); |
|
31 | + foreach ($role_capabilities as $capability => $you_can_do_it) { |
|
32 | + if ($you_can_do_it) { |
|
33 | + $capabilities[] = $capability; |
|
34 | + } |
|
35 | + } |
|
36 | + $this->setDataArray($capabilities); |
|
37 | + } |
|
38 | 38 | } |
@@ -79,7 +79,7 @@ discard block |
||
79 | 79 | * Collect the input_fields and sanitize them to prepare them for sending to the Query |
80 | 80 | */ |
81 | 81 | $input_fields = []; |
82 | - if (! empty($this->args['where'])) { |
|
82 | + if ( ! empty($this->args['where'])) { |
|
83 | 83 | $input_fields = $this->sanitizeInputFields($this->args['where']); |
84 | 84 | |
85 | 85 | // Since we do not have any falsy values in query params |
@@ -87,15 +87,15 @@ discard block |
||
87 | 87 | $input_fields = array_filter($input_fields); |
88 | 88 | |
89 | 89 | // Use the proper operator. |
90 | - if (! empty($input_fields['Registration.Event.EVT_ID']) && is_array($input_fields['Registration.Event.EVT_ID'])) { |
|
90 | + if ( ! empty($input_fields['Registration.Event.EVT_ID']) && is_array($input_fields['Registration.Event.EVT_ID'])) { |
|
91 | 91 | $input_fields['Registration.Event.EVT_ID'] = ['IN', $input_fields['Registration.Event.EVT_ID']]; |
92 | 92 | } |
93 | - if (! empty($input_fields['Registration.Ticket.TKT_ID']) && is_array($input_fields['Registration.Ticket.TKT_ID'])) { |
|
93 | + if ( ! empty($input_fields['Registration.Ticket.TKT_ID']) && is_array($input_fields['Registration.Ticket.TKT_ID'])) { |
|
94 | 94 | $input_fields['Registration.Ticket.TKT_ID'] = ['IN', $input_fields['Registration.Ticket.TKT_ID']]; |
95 | 95 | } |
96 | 96 | // If Ticket param is passed, it will have preference over Datetime param |
97 | 97 | // So, use Datetime param only if a Ticket param is not passed |
98 | - if (! empty($input_fields['Datetime.DTT_ID']) && empty($input_fields['Registration.Ticket.TKT_ID'])) { |
|
98 | + if ( ! empty($input_fields['Datetime.DTT_ID']) && empty($input_fields['Registration.Ticket.TKT_ID'])) { |
|
99 | 99 | $datetimeIds = $input_fields['Datetime.DTT_ID']; |
100 | 100 | // Make sure it's an array, ready for "IN" operator |
101 | 101 | $datetimeIds = is_array($datetimeIds) ? $datetimeIds : [$datetimeIds]; |
@@ -113,7 +113,7 @@ discard block |
||
113 | 113 | $ticketIds = []; |
114 | 114 | } |
115 | 115 | |
116 | - if (!empty($ticketIds)) { |
|
116 | + if ( ! empty($ticketIds)) { |
|
117 | 117 | $input_fields['Registration.Ticket.TKT_ID'] = ['IN', $ticketIds]; |
118 | 118 | } |
119 | 119 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | /** |
125 | 125 | * Merge the input_fields with the default query_args |
126 | 126 | */ |
127 | - if (! empty($input_fields)) { |
|
127 | + if ( ! empty($input_fields)) { |
|
128 | 128 | $where_params = array_merge($where_params, $input_fields); |
129 | 129 | } |
130 | 130 | |
@@ -132,12 +132,12 @@ discard block |
||
132 | 132 | |
133 | 133 | $search = $this->getSearchKeywords($this->args['where']); |
134 | 134 | |
135 | - if (! empty($search)) { |
|
135 | + if ( ! empty($search)) { |
|
136 | 136 | // use OR operator to search in any of the fields |
137 | 137 | $where_params['OR'] = array( |
138 | - 'ATT_full_name' => array('LIKE', '%' . $search . '%'), |
|
139 | - 'ATT_bio' => array('LIKE', '%' . $search . '%'), |
|
140 | - 'ATT_short_bio' => array('LIKE', '%' . $search . '%'), |
|
138 | + 'ATT_full_name' => array('LIKE', '%'.$search.'%'), |
|
139 | + 'ATT_bio' => array('LIKE', '%'.$search.'%'), |
|
140 | + 'ATT_short_bio' => array('LIKE', '%'.$search.'%'), |
|
141 | 141 | ); |
142 | 142 | } |
143 | 143 |
@@ -17,182 +17,182 @@ |
||
17 | 17 | */ |
18 | 18 | class AttendeeConnectionResolver extends AbstractConnectionResolver |
19 | 19 | { |
20 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
21 | - /** |
|
22 | - * @return string |
|
23 | - */ |
|
24 | - public function get_loader_name() |
|
25 | - { |
|
26 | - return 'espresso_attendee'; |
|
27 | - } |
|
28 | - |
|
29 | - /** |
|
30 | - * @return EEM_Attendee |
|
31 | - * @throws EE_Error |
|
32 | - * @throws InvalidArgumentException |
|
33 | - * @throws InvalidDataTypeException |
|
34 | - * @throws InvalidInterfaceException |
|
35 | - * @throws ReflectionException |
|
36 | - */ |
|
37 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
38 | - public function get_query() |
|
39 | - { |
|
40 | - return EEM_Attendee::instance(); |
|
41 | - } |
|
42 | - |
|
43 | - |
|
44 | - /** |
|
45 | - * Return an array of item IDs from the query |
|
46 | - * |
|
47 | - * @return array |
|
48 | - */ |
|
49 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
50 | - public function get_ids() |
|
51 | - { |
|
52 | - $results = $this->query->get_col($this->query_args); |
|
53 | - |
|
54 | - return ! empty($results) ? $results : []; |
|
55 | - } |
|
56 | - |
|
57 | - |
|
58 | - /** |
|
59 | - * Here, we map the args from the input, then we make sure that we're only querying |
|
60 | - * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
61 | - * handle batch resolution of the posts. |
|
62 | - * |
|
63 | - * @return array |
|
64 | - * @throws InvalidArgumentException |
|
65 | - * @throws InvalidDataTypeException |
|
66 | - * @throws InvalidInterfaceException |
|
67 | - */ |
|
68 | - // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
69 | - public function get_query_args() |
|
70 | - { |
|
71 | - $where_params = []; |
|
72 | - $query_args = []; |
|
73 | - |
|
74 | - $query_args['limit'] = $this->getLimit(); |
|
75 | - |
|
76 | - // Avoid multiple entries by join. |
|
77 | - $query_args['group_by'] = 'ATT_ID'; |
|
78 | - |
|
79 | - $query_args['default_where_conditions'] = 'minimum'; |
|
80 | - |
|
81 | - /** |
|
82 | - * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
83 | - */ |
|
84 | - $input_fields = []; |
|
85 | - if (! empty($this->args['where'])) { |
|
86 | - $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
87 | - |
|
88 | - // Since we do not have any falsy values in query params |
|
89 | - // Lets get rid of empty values |
|
90 | - $input_fields = array_filter($input_fields); |
|
91 | - |
|
92 | - // Use the proper operator. |
|
93 | - if (! empty($input_fields['Registration.Event.EVT_ID']) && is_array($input_fields['Registration.Event.EVT_ID'])) { |
|
94 | - $input_fields['Registration.Event.EVT_ID'] = ['IN', $input_fields['Registration.Event.EVT_ID']]; |
|
95 | - } |
|
96 | - if (! empty($input_fields['Registration.Ticket.TKT_ID']) && is_array($input_fields['Registration.Ticket.TKT_ID'])) { |
|
97 | - $input_fields['Registration.Ticket.TKT_ID'] = ['IN', $input_fields['Registration.Ticket.TKT_ID']]; |
|
98 | - } |
|
99 | - // If Ticket param is passed, it will have preference over Datetime param |
|
100 | - // So, use Datetime param only if a Ticket param is not passed |
|
101 | - if (! empty($input_fields['Datetime.DTT_ID']) && empty($input_fields['Registration.Ticket.TKT_ID'])) { |
|
102 | - $datetimeIds = $input_fields['Datetime.DTT_ID']; |
|
103 | - // Make sure it's an array, ready for "IN" operator |
|
104 | - $datetimeIds = is_array($datetimeIds) ? $datetimeIds : [$datetimeIds]; |
|
105 | - |
|
106 | - try { |
|
107 | - // Get related ticket IDs for the given dates |
|
108 | - $ticketIds = EEM_Ticket::instance()->get_col([ |
|
109 | - [ |
|
110 | - 'Datetime.DTT_ID' => ['IN', $datetimeIds], |
|
111 | - 'TKT_deleted' => ['IN', [true, false]], |
|
112 | - ], |
|
113 | - 'default_where_conditions' => 'minimum', |
|
114 | - ]); |
|
115 | - } catch (Throwable $th) { |
|
116 | - $ticketIds = []; |
|
117 | - } catch (Exception $th) { |
|
118 | - $ticketIds = []; |
|
119 | - } |
|
120 | - |
|
121 | - if (!empty($ticketIds)) { |
|
122 | - $input_fields['Registration.Ticket.TKT_ID'] = ['IN', $ticketIds]; |
|
123 | - } |
|
124 | - } |
|
125 | - // Since there is no relation between Attendee and Datetime, we need to remove it |
|
126 | - unset($input_fields['Datetime.DTT_ID']); |
|
127 | - } |
|
128 | - |
|
129 | - /** |
|
130 | - * Merge the input_fields with the default query_args |
|
131 | - */ |
|
132 | - if (! empty($input_fields)) { |
|
133 | - $where_params = array_merge($where_params, $input_fields); |
|
134 | - } |
|
135 | - |
|
136 | - list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'ATT_ID'); |
|
137 | - |
|
138 | - $search = $this->getSearchKeywords($this->args['where']); |
|
139 | - |
|
140 | - if (! empty($search)) { |
|
141 | - // use OR operator to search in any of the fields |
|
142 | - $where_params['OR'] = array( |
|
143 | - 'ATT_full_name' => array('LIKE', '%' . $search . '%'), |
|
144 | - 'ATT_bio' => array('LIKE', '%' . $search . '%'), |
|
145 | - 'ATT_short_bio' => array('LIKE', '%' . $search . '%'), |
|
146 | - ); |
|
147 | - } |
|
148 | - |
|
149 | - $where_params = apply_filters( |
|
150 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__attendee_where_params', |
|
151 | - $where_params, |
|
152 | - $this->source, |
|
153 | - $this->args |
|
154 | - ); |
|
155 | - |
|
156 | - $query_args[] = $where_params; |
|
157 | - |
|
158 | - /** |
|
159 | - * Return the $query_args |
|
160 | - */ |
|
161 | - return apply_filters( |
|
162 | - 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__attendee_query_args', |
|
163 | - $query_args, |
|
164 | - $this->source, |
|
165 | - $this->args |
|
166 | - ); |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
172 | - * friendly keys. |
|
173 | - * |
|
174 | - * @param array $where_args |
|
175 | - * @return array |
|
176 | - */ |
|
177 | - public function sanitizeInputFields($where_args) |
|
178 | - { |
|
179 | - $arg_mapping = [ |
|
180 | - // There is no direct relation between Attendee and Datetime |
|
181 | - // But we will handle it via Tickets related to given dates |
|
182 | - 'datetime' => 'Datetime.DTT_ID', |
|
183 | - 'datetimeIn' => 'Datetime.DTT_ID', |
|
184 | - 'event' => 'Registration.Event.EVT_ID', |
|
185 | - 'eventIn' => 'Registration.Event.EVT_ID', |
|
186 | - 'regTicket' => 'Registration.Ticket.TKT_ID', |
|
187 | - 'regTicketIn' => 'Registration.Ticket.TKT_ID', |
|
188 | - 'regTicketIdIn' => 'Registration.Ticket.TKT_ID', |
|
189 | - 'regTicketId' => 'Registration.Ticket.TKT_ID', // priority. |
|
190 | - 'regStatus' => 'Registration.Status.STS_ID', |
|
191 | - ]; |
|
192 | - return $this->sanitizeWhereArgsForInputFields( |
|
193 | - $where_args, |
|
194 | - $arg_mapping, |
|
195 | - ['datetime', 'datetimeIn', 'event', 'eventIn', 'regTicket', 'regTicketIn'] |
|
196 | - ); |
|
197 | - } |
|
20 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
21 | + /** |
|
22 | + * @return string |
|
23 | + */ |
|
24 | + public function get_loader_name() |
|
25 | + { |
|
26 | + return 'espresso_attendee'; |
|
27 | + } |
|
28 | + |
|
29 | + /** |
|
30 | + * @return EEM_Attendee |
|
31 | + * @throws EE_Error |
|
32 | + * @throws InvalidArgumentException |
|
33 | + * @throws InvalidDataTypeException |
|
34 | + * @throws InvalidInterfaceException |
|
35 | + * @throws ReflectionException |
|
36 | + */ |
|
37 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
38 | + public function get_query() |
|
39 | + { |
|
40 | + return EEM_Attendee::instance(); |
|
41 | + } |
|
42 | + |
|
43 | + |
|
44 | + /** |
|
45 | + * Return an array of item IDs from the query |
|
46 | + * |
|
47 | + * @return array |
|
48 | + */ |
|
49 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
50 | + public function get_ids() |
|
51 | + { |
|
52 | + $results = $this->query->get_col($this->query_args); |
|
53 | + |
|
54 | + return ! empty($results) ? $results : []; |
|
55 | + } |
|
56 | + |
|
57 | + |
|
58 | + /** |
|
59 | + * Here, we map the args from the input, then we make sure that we're only querying |
|
60 | + * for IDs. The IDs are then passed down the resolve tree, and deferred resolvers |
|
61 | + * handle batch resolution of the posts. |
|
62 | + * |
|
63 | + * @return array |
|
64 | + * @throws InvalidArgumentException |
|
65 | + * @throws InvalidDataTypeException |
|
66 | + * @throws InvalidInterfaceException |
|
67 | + */ |
|
68 | + // phpcs:ignore PSR1.Methods.CamelCapsMethodName.NotCamelCaps |
|
69 | + public function get_query_args() |
|
70 | + { |
|
71 | + $where_params = []; |
|
72 | + $query_args = []; |
|
73 | + |
|
74 | + $query_args['limit'] = $this->getLimit(); |
|
75 | + |
|
76 | + // Avoid multiple entries by join. |
|
77 | + $query_args['group_by'] = 'ATT_ID'; |
|
78 | + |
|
79 | + $query_args['default_where_conditions'] = 'minimum'; |
|
80 | + |
|
81 | + /** |
|
82 | + * Collect the input_fields and sanitize them to prepare them for sending to the Query |
|
83 | + */ |
|
84 | + $input_fields = []; |
|
85 | + if (! empty($this->args['where'])) { |
|
86 | + $input_fields = $this->sanitizeInputFields($this->args['where']); |
|
87 | + |
|
88 | + // Since we do not have any falsy values in query params |
|
89 | + // Lets get rid of empty values |
|
90 | + $input_fields = array_filter($input_fields); |
|
91 | + |
|
92 | + // Use the proper operator. |
|
93 | + if (! empty($input_fields['Registration.Event.EVT_ID']) && is_array($input_fields['Registration.Event.EVT_ID'])) { |
|
94 | + $input_fields['Registration.Event.EVT_ID'] = ['IN', $input_fields['Registration.Event.EVT_ID']]; |
|
95 | + } |
|
96 | + if (! empty($input_fields['Registration.Ticket.TKT_ID']) && is_array($input_fields['Registration.Ticket.TKT_ID'])) { |
|
97 | + $input_fields['Registration.Ticket.TKT_ID'] = ['IN', $input_fields['Registration.Ticket.TKT_ID']]; |
|
98 | + } |
|
99 | + // If Ticket param is passed, it will have preference over Datetime param |
|
100 | + // So, use Datetime param only if a Ticket param is not passed |
|
101 | + if (! empty($input_fields['Datetime.DTT_ID']) && empty($input_fields['Registration.Ticket.TKT_ID'])) { |
|
102 | + $datetimeIds = $input_fields['Datetime.DTT_ID']; |
|
103 | + // Make sure it's an array, ready for "IN" operator |
|
104 | + $datetimeIds = is_array($datetimeIds) ? $datetimeIds : [$datetimeIds]; |
|
105 | + |
|
106 | + try { |
|
107 | + // Get related ticket IDs for the given dates |
|
108 | + $ticketIds = EEM_Ticket::instance()->get_col([ |
|
109 | + [ |
|
110 | + 'Datetime.DTT_ID' => ['IN', $datetimeIds], |
|
111 | + 'TKT_deleted' => ['IN', [true, false]], |
|
112 | + ], |
|
113 | + 'default_where_conditions' => 'minimum', |
|
114 | + ]); |
|
115 | + } catch (Throwable $th) { |
|
116 | + $ticketIds = []; |
|
117 | + } catch (Exception $th) { |
|
118 | + $ticketIds = []; |
|
119 | + } |
|
120 | + |
|
121 | + if (!empty($ticketIds)) { |
|
122 | + $input_fields['Registration.Ticket.TKT_ID'] = ['IN', $ticketIds]; |
|
123 | + } |
|
124 | + } |
|
125 | + // Since there is no relation between Attendee and Datetime, we need to remove it |
|
126 | + unset($input_fields['Datetime.DTT_ID']); |
|
127 | + } |
|
128 | + |
|
129 | + /** |
|
130 | + * Merge the input_fields with the default query_args |
|
131 | + */ |
|
132 | + if (! empty($input_fields)) { |
|
133 | + $where_params = array_merge($where_params, $input_fields); |
|
134 | + } |
|
135 | + |
|
136 | + list($query_args, $where_params) = $this->mapOrderbyInputArgs($query_args, $where_params, 'ATT_ID'); |
|
137 | + |
|
138 | + $search = $this->getSearchKeywords($this->args['where']); |
|
139 | + |
|
140 | + if (! empty($search)) { |
|
141 | + // use OR operator to search in any of the fields |
|
142 | + $where_params['OR'] = array( |
|
143 | + 'ATT_full_name' => array('LIKE', '%' . $search . '%'), |
|
144 | + 'ATT_bio' => array('LIKE', '%' . $search . '%'), |
|
145 | + 'ATT_short_bio' => array('LIKE', '%' . $search . '%'), |
|
146 | + ); |
|
147 | + } |
|
148 | + |
|
149 | + $where_params = apply_filters( |
|
150 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__attendee_where_params', |
|
151 | + $where_params, |
|
152 | + $this->source, |
|
153 | + $this->args |
|
154 | + ); |
|
155 | + |
|
156 | + $query_args[] = $where_params; |
|
157 | + |
|
158 | + /** |
|
159 | + * Return the $query_args |
|
160 | + */ |
|
161 | + return apply_filters( |
|
162 | + 'FHEE__EventEspresso_core_domain_services_graphql_connection_resolvers__attendee_query_args', |
|
163 | + $query_args, |
|
164 | + $this->source, |
|
165 | + $this->args |
|
166 | + ); |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * This sets up the "allowed" args, and translates the GraphQL-friendly keys to model |
|
172 | + * friendly keys. |
|
173 | + * |
|
174 | + * @param array $where_args |
|
175 | + * @return array |
|
176 | + */ |
|
177 | + public function sanitizeInputFields($where_args) |
|
178 | + { |
|
179 | + $arg_mapping = [ |
|
180 | + // There is no direct relation between Attendee and Datetime |
|
181 | + // But we will handle it via Tickets related to given dates |
|
182 | + 'datetime' => 'Datetime.DTT_ID', |
|
183 | + 'datetimeIn' => 'Datetime.DTT_ID', |
|
184 | + 'event' => 'Registration.Event.EVT_ID', |
|
185 | + 'eventIn' => 'Registration.Event.EVT_ID', |
|
186 | + 'regTicket' => 'Registration.Ticket.TKT_ID', |
|
187 | + 'regTicketIn' => 'Registration.Ticket.TKT_ID', |
|
188 | + 'regTicketIdIn' => 'Registration.Ticket.TKT_ID', |
|
189 | + 'regTicketId' => 'Registration.Ticket.TKT_ID', // priority. |
|
190 | + 'regStatus' => 'Registration.Status.STS_ID', |
|
191 | + ]; |
|
192 | + return $this->sanitizeWhereArgsForInputFields( |
|
193 | + $where_args, |
|
194 | + $arg_mapping, |
|
195 | + ['datetime', 'datetimeIn', 'event', 'eventIn', 'regTicket', 'regTicketIn'] |
|
196 | + ); |
|
197 | + } |
|
198 | 198 | } |