Completed
Branch BUG/11493/convert-exception-to... (a02a03)
by
unknown
12:58 queued 27s
created
core/services/assets/Registry.php 1 patch
Indentation   +654 added lines, -654 removed lines patch added patch discarded remove patch
@@ -26,662 +26,662 @@
 block discarded – undo
26 26
 class Registry
27 27
 {
28 28
 
29
-    const ASSET_TYPE_CSS = 'css';
30
-    const ASSET_TYPE_JS = 'js';
31
-    const ASSET_NAMESPACE = 'core';
32
-
33
-    /**
34
-     * @var EE_Template_Config $template_config
35
-     */
36
-    protected $template_config;
37
-
38
-    /**
39
-     * @var EE_Currency_Config $currency_config
40
-     */
41
-    protected $currency_config;
42
-
43
-    /**
44
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
45
-     *
46
-     * @var array
47
-     */
48
-    protected $jsdata = array();
49
-
50
-
51
-    /**
52
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
53
-     * page source.
54
-     * @var array
55
-     */
56
-    protected $script_handles_with_data = array();
57
-
58
-
59
-    /**
60
-     * @var DomainInterface
61
-     */
62
-    protected $domain;
63
-
64
-
65
-
66
-    /**
67
-     * Holds the manifest data obtained from registered manifest files.
68
-     * Manifests are maps of asset chunk name to actual built asset file names.
69
-     * Shape of this array is:
70
-     *
71
-     * array(
72
-     *  'some_namespace_slug' => array(
73
-     *      'some_chunk_name' => array(
74
-     *          'js' => 'filename.js'
75
-     *          'css' => 'filename.js'
76
-     *      ),
77
-     *      'url_base' => 'https://baseurl.com/to/assets
78
-     *  )
79
-     * )
80
-     *
81
-     * @var array
82
-     */
83
-    private $manifest_data = array();
84
-
85
-
86
-    /**
87
-     * Registry constructor.
88
-     * Hooking into WP actions for script registry.
89
-     *
90
-     * @param EE_Template_Config $template_config
91
-     * @param EE_Currency_Config $currency_config
92
-     * @param DomainInterface    $domain
93
-     * @throws InvalidArgumentException
94
-     * @throws InvalidFilePathException
95
-     */
96
-    public function __construct(
97
-        EE_Template_Config $template_config,
98
-        EE_Currency_Config $currency_config,
99
-        DomainInterface $domain
100
-    ) {
101
-        $this->template_config = $template_config;
102
-        $this->currency_config = $currency_config;
103
-        $this->domain = $domain;
104
-        $this->registerManifestFile(
105
-            self::ASSET_NAMESPACE,
106
-            $this->domain->distributionAssetsUrl(),
107
-            $this->domain->distributionAssetsPath() . 'build-manifest.json'
108
-        );
109
-        add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
110
-        add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
111
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
112
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
113
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
114
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
115
-    }
116
-
117
-    /**
118
-     * Callback for the WP script actions.
119
-     * Used to register globally accessible core scripts.
120
-     * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
121
-     *
122
-     */
123
-    public function scripts()
124
-    {
125
-        global $wp_version;
126
-        wp_register_script(
127
-            'ee-manifest',
128
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'),
129
-            array(),
130
-            null,
131
-            true
132
-        );
133
-        wp_register_script(
134
-            'eejs-core',
135
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'),
136
-            array('ee-manifest'),
137
-            null,
138
-            true
139
-        );
140
-        wp_register_script(
141
-            'ee-vendor-react',
142
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'),
143
-            array('eejs-core'),
144
-            null,
145
-            true
146
-        );
147
-        //only run this if WordPress 4.4.0 > is in use.
148
-        if (version_compare($wp_version, '4.4.0', '>')) {
149
-            //js.api
150
-            wp_register_script(
151
-                'eejs-api',
152
-                EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
153
-                array('underscore', 'eejs-core'),
154
-                EVENT_ESPRESSO_VERSION,
155
-                true
156
-            );
157
-            $this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
158
-            $this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
159
-        }
160
-        if (! is_admin()) {
161
-            $this->loadCoreCss();
162
-        }
163
-        $this->loadCoreJs();
164
-        $this->loadJqueryValidate();
165
-        $this->loadAccountingJs();
166
-        $this->loadQtipJs();
167
-        $this->registerAdminAssets();
168
-    }
169
-
170
-
171
-
172
-    /**
173
-     * Call back for the script print in frontend and backend.
174
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
175
-     *
176
-     * @since 4.9.31.rc.015
177
-     */
178
-    public function enqueueData()
179
-    {
180
-        $this->removeAlreadyRegisteredDataForScriptHandles();
181
-        wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata));
182
-        wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
183
-        $this->localizeAccountingJs();
184
-        $this->addRegisteredScriptHandlesWithData('eejs-core');
185
-        $this->addRegisteredScriptHandlesWithData('espresso_core');
186
-    }
187
-
188
-
189
-
190
-    /**
191
-     * Used to add data to eejs.data object.
192
-     * Note:  Overriding existing data is not allowed.
193
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
194
-     * If the data you add is something like this:
195
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
196
-     * It will be exposed in the page source as:
197
-     *  eejs.data.my_plugin_data.foo == gar
198
-     *
199
-     * @param string       $key   Key used to access your data
200
-     * @param string|array $value Value to attach to key
201
-     * @throws InvalidArgumentException
202
-     */
203
-    public function addData($key, $value)
204
-    {
205
-        if ($this->verifyDataNotExisting($key)) {
206
-            $this->jsdata[$key] = $value;
207
-        }
208
-    }
209
-
210
-
211
-
212
-    /**
213
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
214
-     * elements in an array.
215
-     * When you use this method, the value you include will be appended to the end of an array on $key.
216
-     * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
217
-     * object like this, eejs.data.test = [ my_data,
218
-     * ]
219
-     * If there has already been a scalar value attached to the data object given key, then
220
-     * this will throw an exception.
221
-     *
222
-     * @param string       $key   Key to attach data to.
223
-     * @param string|array $value Value being registered.
224
-     * @throws InvalidArgumentException
225
-     */
226
-    public function pushData($key, $value)
227
-    {
228
-        if (isset($this->jsdata[$key])
229
-            && ! is_array($this->jsdata[$key])
230
-        ) {
231
-            throw new invalidArgumentException(
232
-                sprintf(
233
-                    __(
234
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
29
+	const ASSET_TYPE_CSS = 'css';
30
+	const ASSET_TYPE_JS = 'js';
31
+	const ASSET_NAMESPACE = 'core';
32
+
33
+	/**
34
+	 * @var EE_Template_Config $template_config
35
+	 */
36
+	protected $template_config;
37
+
38
+	/**
39
+	 * @var EE_Currency_Config $currency_config
40
+	 */
41
+	protected $currency_config;
42
+
43
+	/**
44
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
45
+	 *
46
+	 * @var array
47
+	 */
48
+	protected $jsdata = array();
49
+
50
+
51
+	/**
52
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
53
+	 * page source.
54
+	 * @var array
55
+	 */
56
+	protected $script_handles_with_data = array();
57
+
58
+
59
+	/**
60
+	 * @var DomainInterface
61
+	 */
62
+	protected $domain;
63
+
64
+
65
+
66
+	/**
67
+	 * Holds the manifest data obtained from registered manifest files.
68
+	 * Manifests are maps of asset chunk name to actual built asset file names.
69
+	 * Shape of this array is:
70
+	 *
71
+	 * array(
72
+	 *  'some_namespace_slug' => array(
73
+	 *      'some_chunk_name' => array(
74
+	 *          'js' => 'filename.js'
75
+	 *          'css' => 'filename.js'
76
+	 *      ),
77
+	 *      'url_base' => 'https://baseurl.com/to/assets
78
+	 *  )
79
+	 * )
80
+	 *
81
+	 * @var array
82
+	 */
83
+	private $manifest_data = array();
84
+
85
+
86
+	/**
87
+	 * Registry constructor.
88
+	 * Hooking into WP actions for script registry.
89
+	 *
90
+	 * @param EE_Template_Config $template_config
91
+	 * @param EE_Currency_Config $currency_config
92
+	 * @param DomainInterface    $domain
93
+	 * @throws InvalidArgumentException
94
+	 * @throws InvalidFilePathException
95
+	 */
96
+	public function __construct(
97
+		EE_Template_Config $template_config,
98
+		EE_Currency_Config $currency_config,
99
+		DomainInterface $domain
100
+	) {
101
+		$this->template_config = $template_config;
102
+		$this->currency_config = $currency_config;
103
+		$this->domain = $domain;
104
+		$this->registerManifestFile(
105
+			self::ASSET_NAMESPACE,
106
+			$this->domain->distributionAssetsUrl(),
107
+			$this->domain->distributionAssetsPath() . 'build-manifest.json'
108
+		);
109
+		add_action('wp_enqueue_scripts', array($this, 'scripts'), 1);
110
+		add_action('admin_enqueue_scripts', array($this, 'scripts'), 1);
111
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 2);
112
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 2);
113
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
114
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
115
+	}
116
+
117
+	/**
118
+	 * Callback for the WP script actions.
119
+	 * Used to register globally accessible core scripts.
120
+	 * Also used to add the eejs.data object to the source for any js having eejs-core as a dependency.
121
+	 *
122
+	 */
123
+	public function scripts()
124
+	{
125
+		global $wp_version;
126
+		wp_register_script(
127
+			'ee-manifest',
128
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'manifest'),
129
+			array(),
130
+			null,
131
+			true
132
+		);
133
+		wp_register_script(
134
+			'eejs-core',
135
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'eejs'),
136
+			array('ee-manifest'),
137
+			null,
138
+			true
139
+		);
140
+		wp_register_script(
141
+			'ee-vendor-react',
142
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'reactVendor'),
143
+			array('eejs-core'),
144
+			null,
145
+			true
146
+		);
147
+		//only run this if WordPress 4.4.0 > is in use.
148
+		if (version_compare($wp_version, '4.4.0', '>')) {
149
+			//js.api
150
+			wp_register_script(
151
+				'eejs-api',
152
+				EE_LIBRARIES_URL . 'rest_api/assets/js/eejs-api.min.js',
153
+				array('underscore', 'eejs-core'),
154
+				EVENT_ESPRESSO_VERSION,
155
+				true
156
+			);
157
+			$this->jsdata['eejs_api_nonce'] = wp_create_nonce('wp_rest');
158
+			$this->jsdata['paths'] = array('rest_route' => rest_url('ee/v4.8.36/'));
159
+		}
160
+		if (! is_admin()) {
161
+			$this->loadCoreCss();
162
+		}
163
+		$this->loadCoreJs();
164
+		$this->loadJqueryValidate();
165
+		$this->loadAccountingJs();
166
+		$this->loadQtipJs();
167
+		$this->registerAdminAssets();
168
+	}
169
+
170
+
171
+
172
+	/**
173
+	 * Call back for the script print in frontend and backend.
174
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
175
+	 *
176
+	 * @since 4.9.31.rc.015
177
+	 */
178
+	public function enqueueData()
179
+	{
180
+		$this->removeAlreadyRegisteredDataForScriptHandles();
181
+		wp_localize_script('eejs-core', 'eejsdata', array('data' => $this->jsdata));
182
+		wp_localize_script('espresso_core', 'eei18n', EE_Registry::$i18n_js_strings);
183
+		$this->localizeAccountingJs();
184
+		$this->addRegisteredScriptHandlesWithData('eejs-core');
185
+		$this->addRegisteredScriptHandlesWithData('espresso_core');
186
+	}
187
+
188
+
189
+
190
+	/**
191
+	 * Used to add data to eejs.data object.
192
+	 * Note:  Overriding existing data is not allowed.
193
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
194
+	 * If the data you add is something like this:
195
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
196
+	 * It will be exposed in the page source as:
197
+	 *  eejs.data.my_plugin_data.foo == gar
198
+	 *
199
+	 * @param string       $key   Key used to access your data
200
+	 * @param string|array $value Value to attach to key
201
+	 * @throws InvalidArgumentException
202
+	 */
203
+	public function addData($key, $value)
204
+	{
205
+		if ($this->verifyDataNotExisting($key)) {
206
+			$this->jsdata[$key] = $value;
207
+		}
208
+	}
209
+
210
+
211
+
212
+	/**
213
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
214
+	 * elements in an array.
215
+	 * When you use this method, the value you include will be appended to the end of an array on $key.
216
+	 * So if the $key was 'test' and you added a value of 'my_data' then it would be represented in the javascript
217
+	 * object like this, eejs.data.test = [ my_data,
218
+	 * ]
219
+	 * If there has already been a scalar value attached to the data object given key, then
220
+	 * this will throw an exception.
221
+	 *
222
+	 * @param string       $key   Key to attach data to.
223
+	 * @param string|array $value Value being registered.
224
+	 * @throws InvalidArgumentException
225
+	 */
226
+	public function pushData($key, $value)
227
+	{
228
+		if (isset($this->jsdata[$key])
229
+			&& ! is_array($this->jsdata[$key])
230
+		) {
231
+			throw new invalidArgumentException(
232
+				sprintf(
233
+					__(
234
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
235 235
                          push values to this data element when it is an array.',
236
-                        'event_espresso'
237
-                    ),
238
-                    $key,
239
-                    __METHOD__
240
-                )
241
-            );
242
-        }
243
-        $this->jsdata[$key][] = $value;
244
-    }
245
-
246
-
247
-
248
-    /**
249
-     * Used to set content used by javascript for a template.
250
-     * Note: Overrides of existing registered templates are not allowed.
251
-     *
252
-     * @param string $template_reference
253
-     * @param string $template_content
254
-     * @throws InvalidArgumentException
255
-     */
256
-    public function addTemplate($template_reference, $template_content)
257
-    {
258
-        if (! isset($this->jsdata['templates'])) {
259
-            $this->jsdata['templates'] = array();
260
-        }
261
-        //no overrides allowed.
262
-        if (isset($this->jsdata['templates'][$template_reference])) {
263
-            throw new invalidArgumentException(
264
-                sprintf(
265
-                    __(
266
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
267
-                        'event_espresso'
268
-                    ),
269
-                    $template_reference
270
-                )
271
-            );
272
-        }
273
-        $this->jsdata['templates'][$template_reference] = $template_content;
274
-    }
275
-
276
-
277
-
278
-    /**
279
-     * Retrieve the template content already registered for the given reference.
280
-     *
281
-     * @param string $template_reference
282
-     * @return string
283
-     */
284
-    public function getTemplate($template_reference)
285
-    {
286
-        return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
287
-            ? $this->jsdata['templates'][$template_reference]
288
-            : '';
289
-    }
290
-
291
-
292
-
293
-    /**
294
-     * Retrieve registered data.
295
-     *
296
-     * @param string $key Name of key to attach data to.
297
-     * @return mixed                If there is no for the given key, then false is returned.
298
-     */
299
-    public function getData($key)
300
-    {
301
-        return isset($this->jsdata[$key])
302
-            ? $this->jsdata[$key]
303
-            : false;
304
-    }
305
-
306
-
307
-    /**
308
-     * Get the actual asset path for asset manifests.
309
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
310
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
311
-     *                           asset file location.
312
-     * @param string $chunk_name
313
-     * @param string $asset_type
314
-     * @return string
315
-     * @since 4.9.59.p
316
-     */
317
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
318
-    {
319
-        $url = isset(
320
-            $this->manifest_data[$namespace][$chunk_name][$asset_type],
321
-            $this->manifest_data[$namespace]['url_base']
322
-        )
323
-            ? $this->manifest_data[$namespace]['url_base']
324
-              . $this->manifest_data[$namespace][$chunk_name][$asset_type]
325
-            : $chunk_name;
326
-        return apply_filters(
327
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
328
-            $url,
329
-            $namespace,
330
-            $chunk_name,
331
-            $asset_type
332
-        );
333
-    }
334
-
335
-
336
-    /**
337
-     * Return the url to a js file for the given namespace and chunk name.
338
-     *
339
-     * @param string $namespace
340
-     * @param string $chunk_name
341
-     * @return string
342
-     */
343
-    public function getJsUrl($namespace, $chunk_name)
344
-    {
345
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
346
-    }
347
-
348
-
349
-    /**
350
-     * Return the url to a css file for the given namespace and chunk name.
351
-     *
352
-     * @param string $namespace
353
-     * @param string $chunk_name
354
-     * @return string
355
-     */
356
-    public function getCssUrl($namespace, $chunk_name)
357
-    {
358
-        return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
359
-    }
360
-
361
-
362
-    /**
363
-     * Used to register a js/css manifest file with the registered_manifest_files property.
364
-     *
365
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
366
-     * @param string $url_base      The url base for the manifest file location.
367
-     * @param string $manifest_file The absolute path to the manifest file.
368
-     * @throws InvalidArgumentException
369
-     * @throws InvalidFilePathException
370
-     * @since 4.9.59.p
371
-     */
372
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
373
-    {
374
-        if (isset($this->manifest_data[$namespace])) {
375
-            throw new InvalidArgumentException(
376
-                sprintf(
377
-                    esc_html__(
378
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
379
-                        'event_espresso'
380
-                    ),
381
-                    $namespace
382
-                )
383
-            );
384
-        }
385
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
386
-            if ( WP_DEBUG ) {
387
-                throw new InvalidArgumentException(
388
-                    sprintf(
389
-                        esc_html__(
390
-                            'The provided value for %1$s is not a valid url.  The url provided was: %2$s',
391
-                            'event_espresso'
392
-                        ),
393
-                        '$url_base',
394
-                        $url_base
395
-                    )
396
-                );
397
-            }
398
-            if (is_admin()) {
399
-                EE_Error::add_error(
400
-                    sprintf(
401
-                        esc_html__(
402
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
403
-                            'event_espresso'
404
-                        ),
405
-                        'Event Espresso',
406
-                        $url_base,
407
-                        'plugins_url',
408
-                        'WP_PLUGIN_URL'
409
-                    ),
410
-                    __FILE__,
411
-                    __FUNCTION__,
412
-                    __LINE__
413
-                );
414
-            }
415
-            return;
416
-        }
417
-        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
418
-        if (! isset($this->manifest_data[$namespace]['url_base'])) {
419
-            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
420
-        }
421
-    }
422
-
423
-
424
-
425
-    /**
426
-     * Decodes json from the provided manifest file.
427
-     *
428
-     * @since 4.9.59.p
429
-     * @param string $manifest_file Path to manifest file.
430
-     * @return array
431
-     * @throws InvalidFilePathException
432
-     */
433
-    private function decodeManifestFile($manifest_file)
434
-    {
435
-        if (! file_exists($manifest_file)) {
436
-            throw new InvalidFilePathException($manifest_file);
437
-        }
438
-        return json_decode(file_get_contents($manifest_file), true);
439
-    }
440
-
441
-
442
-
443
-    /**
444
-     * Verifies whether the given data exists already on the jsdata array.
445
-     * Overriding data is not allowed.
446
-     *
447
-     * @param string $key Index for data.
448
-     * @return bool        If valid then return true.
449
-     * @throws InvalidArgumentException if data already exists.
450
-     */
451
-    protected function verifyDataNotExisting($key)
452
-    {
453
-        if (isset($this->jsdata[$key])) {
454
-            if (is_array($this->jsdata[$key])) {
455
-                throw new InvalidArgumentException(
456
-                    sprintf(
457
-                        __(
458
-                            'The value for %1$s already exists in the Registry::eejs object.
236
+						'event_espresso'
237
+					),
238
+					$key,
239
+					__METHOD__
240
+				)
241
+			);
242
+		}
243
+		$this->jsdata[$key][] = $value;
244
+	}
245
+
246
+
247
+
248
+	/**
249
+	 * Used to set content used by javascript for a template.
250
+	 * Note: Overrides of existing registered templates are not allowed.
251
+	 *
252
+	 * @param string $template_reference
253
+	 * @param string $template_content
254
+	 * @throws InvalidArgumentException
255
+	 */
256
+	public function addTemplate($template_reference, $template_content)
257
+	{
258
+		if (! isset($this->jsdata['templates'])) {
259
+			$this->jsdata['templates'] = array();
260
+		}
261
+		//no overrides allowed.
262
+		if (isset($this->jsdata['templates'][$template_reference])) {
263
+			throw new invalidArgumentException(
264
+				sprintf(
265
+					__(
266
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
267
+						'event_espresso'
268
+					),
269
+					$template_reference
270
+				)
271
+			);
272
+		}
273
+		$this->jsdata['templates'][$template_reference] = $template_content;
274
+	}
275
+
276
+
277
+
278
+	/**
279
+	 * Retrieve the template content already registered for the given reference.
280
+	 *
281
+	 * @param string $template_reference
282
+	 * @return string
283
+	 */
284
+	public function getTemplate($template_reference)
285
+	{
286
+		return isset($this->jsdata['templates'], $this->jsdata['templates'][$template_reference])
287
+			? $this->jsdata['templates'][$template_reference]
288
+			: '';
289
+	}
290
+
291
+
292
+
293
+	/**
294
+	 * Retrieve registered data.
295
+	 *
296
+	 * @param string $key Name of key to attach data to.
297
+	 * @return mixed                If there is no for the given key, then false is returned.
298
+	 */
299
+	public function getData($key)
300
+	{
301
+		return isset($this->jsdata[$key])
302
+			? $this->jsdata[$key]
303
+			: false;
304
+	}
305
+
306
+
307
+	/**
308
+	 * Get the actual asset path for asset manifests.
309
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
310
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
311
+	 *                           asset file location.
312
+	 * @param string $chunk_name
313
+	 * @param string $asset_type
314
+	 * @return string
315
+	 * @since 4.9.59.p
316
+	 */
317
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
318
+	{
319
+		$url = isset(
320
+			$this->manifest_data[$namespace][$chunk_name][$asset_type],
321
+			$this->manifest_data[$namespace]['url_base']
322
+		)
323
+			? $this->manifest_data[$namespace]['url_base']
324
+			  . $this->manifest_data[$namespace][$chunk_name][$asset_type]
325
+			: $chunk_name;
326
+		return apply_filters(
327
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
328
+			$url,
329
+			$namespace,
330
+			$chunk_name,
331
+			$asset_type
332
+		);
333
+	}
334
+
335
+
336
+	/**
337
+	 * Return the url to a js file for the given namespace and chunk name.
338
+	 *
339
+	 * @param string $namespace
340
+	 * @param string $chunk_name
341
+	 * @return string
342
+	 */
343
+	public function getJsUrl($namespace, $chunk_name)
344
+	{
345
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_JS);
346
+	}
347
+
348
+
349
+	/**
350
+	 * Return the url to a css file for the given namespace and chunk name.
351
+	 *
352
+	 * @param string $namespace
353
+	 * @param string $chunk_name
354
+	 * @return string
355
+	 */
356
+	public function getCssUrl($namespace, $chunk_name)
357
+	{
358
+		return $this->getAssetUrl($namespace, $chunk_name, self::ASSET_TYPE_CSS);
359
+	}
360
+
361
+
362
+	/**
363
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
364
+	 *
365
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
366
+	 * @param string $url_base      The url base for the manifest file location.
367
+	 * @param string $manifest_file The absolute path to the manifest file.
368
+	 * @throws InvalidArgumentException
369
+	 * @throws InvalidFilePathException
370
+	 * @since 4.9.59.p
371
+	 */
372
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
373
+	{
374
+		if (isset($this->manifest_data[$namespace])) {
375
+			throw new InvalidArgumentException(
376
+				sprintf(
377
+					esc_html__(
378
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
379
+						'event_espresso'
380
+					),
381
+					$namespace
382
+				)
383
+			);
384
+		}
385
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
386
+			if ( WP_DEBUG ) {
387
+				throw new InvalidArgumentException(
388
+					sprintf(
389
+						esc_html__(
390
+							'The provided value for %1$s is not a valid url.  The url provided was: %2$s',
391
+							'event_espresso'
392
+						),
393
+						'$url_base',
394
+						$url_base
395
+					)
396
+				);
397
+			}
398
+			if (is_admin()) {
399
+				EE_Error::add_error(
400
+					sprintf(
401
+						esc_html__(
402
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
403
+							'event_espresso'
404
+						),
405
+						'Event Espresso',
406
+						$url_base,
407
+						'plugins_url',
408
+						'WP_PLUGIN_URL'
409
+					),
410
+					__FILE__,
411
+					__FUNCTION__,
412
+					__LINE__
413
+				);
414
+			}
415
+			return;
416
+		}
417
+		$this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
418
+		if (! isset($this->manifest_data[$namespace]['url_base'])) {
419
+			$this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
420
+		}
421
+	}
422
+
423
+
424
+
425
+	/**
426
+	 * Decodes json from the provided manifest file.
427
+	 *
428
+	 * @since 4.9.59.p
429
+	 * @param string $manifest_file Path to manifest file.
430
+	 * @return array
431
+	 * @throws InvalidFilePathException
432
+	 */
433
+	private function decodeManifestFile($manifest_file)
434
+	{
435
+		if (! file_exists($manifest_file)) {
436
+			throw new InvalidFilePathException($manifest_file);
437
+		}
438
+		return json_decode(file_get_contents($manifest_file), true);
439
+	}
440
+
441
+
442
+
443
+	/**
444
+	 * Verifies whether the given data exists already on the jsdata array.
445
+	 * Overriding data is not allowed.
446
+	 *
447
+	 * @param string $key Index for data.
448
+	 * @return bool        If valid then return true.
449
+	 * @throws InvalidArgumentException if data already exists.
450
+	 */
451
+	protected function verifyDataNotExisting($key)
452
+	{
453
+		if (isset($this->jsdata[$key])) {
454
+			if (is_array($this->jsdata[$key])) {
455
+				throw new InvalidArgumentException(
456
+					sprintf(
457
+						__(
458
+							'The value for %1$s already exists in the Registry::eejs object.
459 459
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
460 460
                             %2$s method to push your value to the array.',
461
-                            'event_espresso'
462
-                        ),
463
-                        $key,
464
-                        'pushData()'
465
-                    )
466
-                );
467
-            }
468
-            throw new InvalidArgumentException(
469
-                sprintf(
470
-                    __(
471
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
461
+							'event_espresso'
462
+						),
463
+						$key,
464
+						'pushData()'
465
+					)
466
+				);
467
+			}
468
+			throw new InvalidArgumentException(
469
+				sprintf(
470
+					__(
471
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
472 472
                         allowed.  Consider attaching your value to a different key',
473
-                        'event_espresso'
474
-                    ),
475
-                    $key
476
-                )
477
-            );
478
-        }
479
-        return true;
480
-    }
481
-
482
-
483
-
484
-    /**
485
-     * registers core default stylesheets
486
-     */
487
-    private function loadCoreCss()
488
-    {
489
-        if ($this->template_config->enable_default_style) {
490
-            $default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
491
-                ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
492
-                : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
493
-            wp_register_style(
494
-                'espresso_default',
495
-                $default_stylesheet_path,
496
-                array('dashicons'),
497
-                EVENT_ESPRESSO_VERSION
498
-            );
499
-            //Load custom style sheet if available
500
-            if ($this->template_config->custom_style_sheet !== null) {
501
-                wp_register_style(
502
-                    'espresso_custom_css',
503
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
504
-                    array('espresso_default'),
505
-                    EVENT_ESPRESSO_VERSION
506
-                );
507
-            }
508
-        }
509
-    }
510
-
511
-
512
-
513
-    /**
514
-     * registers core default javascript
515
-     */
516
-    private function loadCoreJs()
517
-    {
518
-        // load core js
519
-        wp_register_script(
520
-            'espresso_core',
521
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
522
-            array('jquery'),
523
-            EVENT_ESPRESSO_VERSION,
524
-            true
525
-        );
526
-    }
527
-
528
-
529
-
530
-    /**
531
-     * registers jQuery Validate for form validation
532
-     */
533
-    private function loadJqueryValidate()
534
-    {
535
-        // register jQuery Validate and additional methods
536
-        wp_register_script(
537
-            'jquery-validate',
538
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
539
-            array('jquery'),
540
-            '1.15.0',
541
-            true
542
-        );
543
-        wp_register_script(
544
-            'jquery-validate-extra-methods',
545
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
546
-            array('jquery', 'jquery-validate'),
547
-            '1.15.0',
548
-            true
549
-        );
550
-    }
551
-
552
-
553
-
554
-    /**
555
-     * registers accounting.js for performing client-side calculations
556
-     */
557
-    private function loadAccountingJs()
558
-    {
559
-        //accounting.js library
560
-        // @link http://josscrowcroft.github.io/accounting.js/
561
-        wp_register_script(
562
-            'ee-accounting-core',
563
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
564
-            array('underscore'),
565
-            '0.3.2',
566
-            true
567
-        );
568
-        wp_register_script(
569
-            'ee-accounting',
570
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
571
-            array('ee-accounting-core'),
572
-            EVENT_ESPRESSO_VERSION,
573
-            true
574
-        );
575
-    }
576
-
577
-
578
-
579
-    /**
580
-     * registers accounting.js for performing client-side calculations
581
-     */
582
-    private function localizeAccountingJs()
583
-    {
584
-        wp_localize_script(
585
-            'ee-accounting',
586
-            'EE_ACCOUNTING_CFG',
587
-            array(
588
-                'currency' => array(
589
-                    'symbol'    => $this->currency_config->sign,
590
-                    'format'    => array(
591
-                        'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
592
-                        'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
593
-                        'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
594
-                    ),
595
-                    'decimal'   => $this->currency_config->dec_mrk,
596
-                    'thousand'  => $this->currency_config->thsnds,
597
-                    'precision' => $this->currency_config->dec_plc,
598
-                ),
599
-                'number'   => array(
600
-                    'precision' => $this->currency_config->dec_plc,
601
-                    'thousand'  => $this->currency_config->thsnds,
602
-                    'decimal'   => $this->currency_config->dec_mrk,
603
-                ),
604
-            )
605
-        );
606
-        $this->addRegisteredScriptHandlesWithData('ee-accounting');
607
-    }
608
-
609
-
610
-
611
-    /**
612
-     * registers assets for cleaning your ears
613
-     */
614
-    private function loadQtipJs()
615
-    {
616
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
617
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
618
-        if (apply_filters('FHEE_load_qtip', false)) {
619
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
620
-        }
621
-    }
622
-
623
-
624
-    /**
625
-     * This is used to set registered script handles that have data.
626
-     * @param string $script_handle
627
-     */
628
-    private function addRegisteredScriptHandlesWithData($script_handle)
629
-    {
630
-        $this->script_handles_with_data[$script_handle] = $script_handle;
631
-    }
632
-
633
-
634
-    /**
635
-     * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
636
-     * Dependency stored in WP_Scripts if its set.
637
-     */
638
-    private function removeAlreadyRegisteredDataForScriptHandles()
639
-    {
640
-        if (empty($this->script_handles_with_data)) {
641
-            return;
642
-        }
643
-        foreach ($this->script_handles_with_data as $script_handle) {
644
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
645
-        }
646
-    }
647
-
648
-
649
-    /**
650
-     * Removes any data dependency registered in WP_Scripts if its set.
651
-     * @param string $script_handle
652
-     */
653
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
654
-    {
655
-        if (isset($this->script_handles_with_data[$script_handle])) {
656
-            global $wp_scripts;
657
-            if ($wp_scripts->get_data($script_handle, 'data')) {
658
-                unset($wp_scripts->registered[$script_handle]->extra['data']);
659
-                unset($this->script_handles_with_data[$script_handle]);
660
-            }
661
-        }
662
-    }
663
-
664
-
665
-    /**
666
-     * Registers assets that are used in the WordPress admin.
667
-     */
668
-    private function registerAdminAssets()
669
-    {
670
-        wp_register_script(
671
-            'ee-wp-plugins-page',
672
-            $this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
673
-            array(
674
-                'jquery',
675
-                'ee-vendor-react'
676
-            ),
677
-            null,
678
-            true
679
-        );
680
-        wp_register_style(
681
-            'ee-wp-plugins-page',
682
-            $this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
683
-            array(),
684
-            null
685
-        );
686
-    }
473
+						'event_espresso'
474
+					),
475
+					$key
476
+				)
477
+			);
478
+		}
479
+		return true;
480
+	}
481
+
482
+
483
+
484
+	/**
485
+	 * registers core default stylesheets
486
+	 */
487
+	private function loadCoreCss()
488
+	{
489
+		if ($this->template_config->enable_default_style) {
490
+			$default_stylesheet_path = is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
491
+				? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
492
+				: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css';
493
+			wp_register_style(
494
+				'espresso_default',
495
+				$default_stylesheet_path,
496
+				array('dashicons'),
497
+				EVENT_ESPRESSO_VERSION
498
+			);
499
+			//Load custom style sheet if available
500
+			if ($this->template_config->custom_style_sheet !== null) {
501
+				wp_register_style(
502
+					'espresso_custom_css',
503
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
504
+					array('espresso_default'),
505
+					EVENT_ESPRESSO_VERSION
506
+				);
507
+			}
508
+		}
509
+	}
510
+
511
+
512
+
513
+	/**
514
+	 * registers core default javascript
515
+	 */
516
+	private function loadCoreJs()
517
+	{
518
+		// load core js
519
+		wp_register_script(
520
+			'espresso_core',
521
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
522
+			array('jquery'),
523
+			EVENT_ESPRESSO_VERSION,
524
+			true
525
+		);
526
+	}
527
+
528
+
529
+
530
+	/**
531
+	 * registers jQuery Validate for form validation
532
+	 */
533
+	private function loadJqueryValidate()
534
+	{
535
+		// register jQuery Validate and additional methods
536
+		wp_register_script(
537
+			'jquery-validate',
538
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
539
+			array('jquery'),
540
+			'1.15.0',
541
+			true
542
+		);
543
+		wp_register_script(
544
+			'jquery-validate-extra-methods',
545
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
546
+			array('jquery', 'jquery-validate'),
547
+			'1.15.0',
548
+			true
549
+		);
550
+	}
551
+
552
+
553
+
554
+	/**
555
+	 * registers accounting.js for performing client-side calculations
556
+	 */
557
+	private function loadAccountingJs()
558
+	{
559
+		//accounting.js library
560
+		// @link http://josscrowcroft.github.io/accounting.js/
561
+		wp_register_script(
562
+			'ee-accounting-core',
563
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
564
+			array('underscore'),
565
+			'0.3.2',
566
+			true
567
+		);
568
+		wp_register_script(
569
+			'ee-accounting',
570
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
571
+			array('ee-accounting-core'),
572
+			EVENT_ESPRESSO_VERSION,
573
+			true
574
+		);
575
+	}
576
+
577
+
578
+
579
+	/**
580
+	 * registers accounting.js for performing client-side calculations
581
+	 */
582
+	private function localizeAccountingJs()
583
+	{
584
+		wp_localize_script(
585
+			'ee-accounting',
586
+			'EE_ACCOUNTING_CFG',
587
+			array(
588
+				'currency' => array(
589
+					'symbol'    => $this->currency_config->sign,
590
+					'format'    => array(
591
+						'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
592
+						'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
593
+						'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
594
+					),
595
+					'decimal'   => $this->currency_config->dec_mrk,
596
+					'thousand'  => $this->currency_config->thsnds,
597
+					'precision' => $this->currency_config->dec_plc,
598
+				),
599
+				'number'   => array(
600
+					'precision' => $this->currency_config->dec_plc,
601
+					'thousand'  => $this->currency_config->thsnds,
602
+					'decimal'   => $this->currency_config->dec_mrk,
603
+				),
604
+			)
605
+		);
606
+		$this->addRegisteredScriptHandlesWithData('ee-accounting');
607
+	}
608
+
609
+
610
+
611
+	/**
612
+	 * registers assets for cleaning your ears
613
+	 */
614
+	private function loadQtipJs()
615
+	{
616
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
617
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
618
+		if (apply_filters('FHEE_load_qtip', false)) {
619
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
620
+		}
621
+	}
622
+
623
+
624
+	/**
625
+	 * This is used to set registered script handles that have data.
626
+	 * @param string $script_handle
627
+	 */
628
+	private function addRegisteredScriptHandlesWithData($script_handle)
629
+	{
630
+		$this->script_handles_with_data[$script_handle] = $script_handle;
631
+	}
632
+
633
+
634
+	/**
635
+	 * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
636
+	 * Dependency stored in WP_Scripts if its set.
637
+	 */
638
+	private function removeAlreadyRegisteredDataForScriptHandles()
639
+	{
640
+		if (empty($this->script_handles_with_data)) {
641
+			return;
642
+		}
643
+		foreach ($this->script_handles_with_data as $script_handle) {
644
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
645
+		}
646
+	}
647
+
648
+
649
+	/**
650
+	 * Removes any data dependency registered in WP_Scripts if its set.
651
+	 * @param string $script_handle
652
+	 */
653
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
654
+	{
655
+		if (isset($this->script_handles_with_data[$script_handle])) {
656
+			global $wp_scripts;
657
+			if ($wp_scripts->get_data($script_handle, 'data')) {
658
+				unset($wp_scripts->registered[$script_handle]->extra['data']);
659
+				unset($this->script_handles_with_data[$script_handle]);
660
+			}
661
+		}
662
+	}
663
+
664
+
665
+	/**
666
+	 * Registers assets that are used in the WordPress admin.
667
+	 */
668
+	private function registerAdminAssets()
669
+	{
670
+		wp_register_script(
671
+			'ee-wp-plugins-page',
672
+			$this->getJsUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
673
+			array(
674
+				'jquery',
675
+				'ee-vendor-react'
676
+			),
677
+			null,
678
+			true
679
+		);
680
+		wp_register_style(
681
+			'ee-wp-plugins-page',
682
+			$this->getCssUrl(self::ASSET_NAMESPACE, 'wp-plugins-page'),
683
+			array(),
684
+			null
685
+		);
686
+	}
687 687
 }
Please login to merge, or discard this patch.