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