Completed
Pull Request — master (#1286)
by Darren
10:33
created
core/domain/services/assets/CoreAssetManager.php 2 patches
Indentation   +468 added lines, -468 removed lines patch added patch discarded remove patch
@@ -32,491 +32,491 @@
 block discarded – undo
32 32
 class CoreAssetManager extends AssetManager
33 33
 {
34 34
 
35
-    // WordPress core / Third party JS asset handles
36
-    const JS_HANDLE_JQUERY = 'jquery';
35
+	// WordPress core / Third party JS asset handles
36
+	const JS_HANDLE_JQUERY = 'jquery';
37 37
 
38
-    const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
38
+	const JS_HANDLE_JQUERY_VALIDATE = 'jquery-validate';
39 39
 
40
-    const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
40
+	const JS_HANDLE_JQUERY_VALIDATE_EXTRA = 'jquery-validate-extra-methods';
41 41
 
42
-    const JS_HANDLE_UNDERSCORE = 'underscore';
42
+	const JS_HANDLE_UNDERSCORE = 'underscore';
43 43
 
44
-    const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
44
+	const JS_HANDLE_ACCOUNTING_CORE = 'ee-accounting-core';
45 45
 
46
-    /**
47
-     * @since 4.9.71.p
48
-     */
49
-    const JS_HANDLE_REACT = 'react';
46
+	/**
47
+	 * @since 4.9.71.p
48
+	 */
49
+	const JS_HANDLE_REACT = 'react';
50 50
 
51
-    /**
52
-     * @since 4.9.71.p
53
-     */
54
-    const JS_HANDLE_REACT_DOM = 'react-dom';
51
+	/**
52
+	 * @since 4.9.71.p
53
+	 */
54
+	const JS_HANDLE_REACT_DOM = 'react-dom';
55 55
 
56
-    /**
57
-     * @since 4.9.71.p
58
-     */
59
-    const JS_HANDLE_LODASH = 'lodash';
56
+	/**
57
+	 * @since 4.9.71.p
58
+	 */
59
+	const JS_HANDLE_LODASH = 'lodash';
60 60
 
61
-    const JS_HANDLE_JS_CORE = 'eejs-core';
61
+	const JS_HANDLE_JS_CORE = 'eejs-core';
62 62
 
63
-    const JS_HANDLE_VENDOR = 'eventespresso-vendor';
63
+	const JS_HANDLE_VENDOR = 'eventespresso-vendor';
64 64
 
65
-    const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
65
+	const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
66 66
 
67
-    const JS_HANDLE_HELPERS = 'eventespresso-helpers';
67
+	const JS_HANDLE_HELPERS = 'eventespresso-helpers';
68 68
 
69
-    const JS_HANDLE_MODEL = 'eventespresso-model';
69
+	const JS_HANDLE_MODEL = 'eventespresso-model';
70 70
 
71
-    const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
71
+	const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
72 72
 
73
-    const JS_HANDLE_HOCS = 'eventespresso-hocs';
73
+	const JS_HANDLE_HOCS = 'eventespresso-hocs';
74 74
 
75
-    const JS_HANDLE_COMPONENTS = 'eventespresso-components';
75
+	const JS_HANDLE_COMPONENTS = 'eventespresso-components';
76 76
 
77
-    const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs';
78
-
79
-    const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
77
+	const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs';
78
+
79
+	const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
80 80
 
81
-    const JS_HANDLE_CORE = 'espresso_core';
81
+	const JS_HANDLE_CORE = 'espresso_core';
82 82
 
83
-    const JS_HANDLE_I18N = 'eei18n';
83
+	const JS_HANDLE_I18N = 'eei18n';
84 84
 
85
-    const JS_HANDLE_ACCOUNTING = 'ee-accounting';
86
-
87
-    const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
88
-
89
-    // EE CSS assets handles
90
-    const CSS_HANDLE_DEFAULT = 'espresso_default';
91
-
92
-    const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
93
-
94
-    const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
95
-
96
-    const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
97
-
98
-    /**
99
-     * @var EE_Currency_Config $currency_config
100
-     */
101
-    protected $currency_config;
102
-
103
-    /**
104
-     * @var EE_Template_Config $template_config
105
-     */
106
-    protected $template_config;
107
-
108
-
109
-    /**
110
-     * CoreAssetRegister constructor.
111
-     *
112
-     * @param AssetCollection    $assets
113
-     * @param EE_Currency_Config $currency_config
114
-     * @param EE_Template_Config $template_config
115
-     * @param DomainInterface    $domain
116
-     * @param Registry           $registry
117
-     */
118
-    public function __construct(
119
-        AssetCollection $assets,
120
-        EE_Currency_Config $currency_config,
121
-        EE_Template_Config $template_config,
122
-        DomainInterface $domain,
123
-        Registry $registry
124
-    ) {
125
-        $this->currency_config = $currency_config;
126
-        $this->template_config = $template_config;
127
-        parent::__construct($domain, $assets, $registry);
128
-    }
129
-
130
-
131
-    /**
132
-     * @since 4.9.62.p
133
-     * @throws DomainException
134
-     * @throws DuplicateCollectionIdentifierException
135
-     * @throws InvalidArgumentException
136
-     * @throws InvalidDataTypeException
137
-     * @throws InvalidEntityException
138
-     * @throws InvalidInterfaceException
139
-     */
140
-    public function addAssets()
141
-    {
142
-        $this->addJavascriptFiles();
143
-        $this->addStylesheetFiles();
144
-    }
145
-
146
-
147
-    /**
148
-     * @since 4.9.62.p
149
-     * @throws DomainException
150
-     * @throws DuplicateCollectionIdentifierException
151
-     * @throws InvalidArgumentException
152
-     * @throws InvalidDataTypeException
153
-     * @throws InvalidEntityException
154
-     * @throws InvalidInterfaceException
155
-     */
156
-    public function addJavascriptFiles()
157
-    {
158
-        $this->loadCoreJs();
159
-        $this->loadJqueryValidate();
160
-        $this->loadAccountingJs();
161
-        add_action(
162
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
163
-            array($this, 'loadQtipJs')
164
-        );
165
-        $this->registerAdminAssets();
166
-    }
167
-
168
-
169
-    /**
170
-     * @since 4.9.62.p
171
-     * @throws DuplicateCollectionIdentifierException
172
-     * @throws InvalidDataTypeException
173
-     * @throws InvalidEntityException
174
-     */
175
-    public function addStylesheetFiles()
176
-    {
177
-        $this->loadCoreCss();
178
-    }
179
-
180
-
181
-    /**
182
-     * core default javascript
183
-     *
184
-     * @since 4.9.62.p
185
-     * @throws DomainException
186
-     * @throws DuplicateCollectionIdentifierException
187
-     * @throws InvalidArgumentException
188
-     * @throws InvalidDataTypeException
189
-     * @throws InvalidEntityException
190
-     * @throws InvalidInterfaceException
191
-     */
192
-    private function loadCoreJs()
193
-    {
194
-        // conditionally load third-party libraries that WP core MIGHT have.
195
-        $this->registerWpAssets();
196
-
197
-        $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
198
-        $this->addJs(self::JS_HANDLE_VENDOR);
199
-        $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
200
-        $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
201
-        $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
202
-        $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
203
-        $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
204
-            function () {
205
-                wp_add_inline_script(
206
-                    CoreAssetManager::JS_HANDLE_DATA_STORES,
207
-                    is_admin()
208
-                        ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
209
-                        : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
210
-                );
211
-            }
212
-        );
213
-        $this->addJs(self::JS_HANDLE_HOCS, self::JS_HANDLE_DATA_STORES)->setRequiresTranslation();
214
-        $this->addJs(self::JS_HANDLE_COMPONENTS, self::JS_HANDLE_DATA_STORES)->setRequiresTranslation();
215
-        $this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation();
216
-
217
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
218
-        $this->registry->addData(
219
-            'paths',
220
-            array(
221
-                'base_rest_route' => rest_url(),
222
-                'rest_route' => rest_url('ee/v4.8.36/'),
223
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
224
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
225
-                'site_url' => site_url('/'),
226
-                'admin_url' => admin_url('/'),
227
-            )
228
-        );
229
-        // Event Espresso brand name
230
-        $this->registry->addData('brandName', Domain::brandName());
231
-        /** site formatting values **/
232
-        $this->registry->addData(
233
-            'site_formats',
234
-            array(
235
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
236
-            )
237
-        );
238
-        /** currency data **/
239
-        $this->registry->addData(
240
-            'currency_config',
241
-            $this->getCurrencySettings()
242
-        );
243
-        /** site timezone */
244
-        $this->registry->addData(
245
-            'default_timezone',
246
-            array(
247
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
248
-                'string' => get_option('timezone_string'),
249
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
250
-            )
251
-        );
252
-        /** site locale (user locale if user logged in) */
253
-        $this->registry->addData(
254
-            'locale',
255
-            array(
256
-                'user' => get_user_locale(),
257
-                'site' => get_locale()
258
-            )
259
-        );
260
-
261
-        $this->addJavascript(
262
-            CoreAssetManager::JS_HANDLE_CORE,
263
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
264
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
265
-        )
266
-        ->setInlineDataCallback(
267
-            function () {
268
-                wp_localize_script(
269
-                    CoreAssetManager::JS_HANDLE_CORE,
270
-                    CoreAssetManager::JS_HANDLE_I18N,
271
-                    EE_Registry::$i18n_js_strings
272
-                );
273
-            }
274
-        );
275
-    }
276
-
277
-
278
-    /**
279
-     * Registers vendor files that are bundled with a later version WP but might not be for the current version of
280
-     * WordPress in the running environment.
281
-     *
282
-     * @throws DuplicateCollectionIdentifierException
283
-     * @throws InvalidDataTypeException
284
-     * @throws InvalidEntityException
285
-     * @throws DomainException
286
-     * @since 4.9.71.p
287
-     */
288
-    private function registerWpAssets()
289
-    {
290
-        global $wp_version;
291
-        if (version_compare($wp_version, '5.0.beta', '>=')) {
292
-            return;
293
-        }
294
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
295
-            ->setVersion('16.6.0');
296
-        $this->addVendorJavascript(
297
-            CoreAssetManager::JS_HANDLE_REACT_DOM,
298
-            array(CoreAssetManager::JS_HANDLE_REACT)
299
-        )->setVersion('16.6.0');
300
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
301
-            ->setInlineDataCallback(
302
-                function() {
303
-                    wp_add_inline_script(
304
-                        CoreAssetManager::JS_HANDLE_LODASH,
305
-                        'window.lodash = _.noConflict();'
306
-                    );
307
-                }
308
-            )
309
-            ->setVersion('4.17.11');
310
-    }
311
-
312
-
313
-    /**
314
-     * Returns configuration data for the accounting-js library.
315
-     * @since 4.9.71.p
316
-     * @return array
317
-     */
318
-    private function getAccountingSettings() {
319
-        return array(
320
-            'currency' => array(
321
-                'symbol'    => $this->currency_config->sign,
322
-                'format'    => array(
323
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
324
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
325
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
326
-                ),
327
-                'decimal'   => $this->currency_config->dec_mrk,
328
-                'thousand'  => $this->currency_config->thsnds,
329
-                'precision' => $this->currency_config->dec_plc,
330
-            ),
331
-            'number'   => array(
332
-                'precision' => $this->currency_config->dec_plc,
333
-                'thousand'  => $this->currency_config->thsnds,
334
-                'decimal'   => $this->currency_config->dec_mrk,
335
-            ),
336
-        );
337
-    }
338
-
339
-
340
-    /**
341
-     * Returns configuration data for the js Currency VO.
342
-     * @since 4.9.71.p
343
-     * @return array
344
-     */
345
-    private function getCurrencySettings()
346
-    {
347
-        return array(
348
-            'code' => $this->currency_config->code,
349
-            'singularLabel' => $this->currency_config->name,
350
-            'pluralLabel' => $this->currency_config->plural,
351
-            'sign' => $this->currency_config->sign,
352
-            'signB4' => $this->currency_config->sign_b4,
353
-            'decimalPlaces' => $this->currency_config->dec_plc,
354
-            'decimalMark' => $this->currency_config->dec_mrk,
355
-            'thousandsSeparator' => $this->currency_config->thsnds,
356
-        );
357
-    }
358
-
359
-
360
-    /**
361
-     * @since 4.9.62.p
362
-     * @throws DuplicateCollectionIdentifierException
363
-     * @throws InvalidDataTypeException
364
-     * @throws InvalidEntityException
365
-     */
366
-    private function loadCoreCss()
367
-    {
368
-        if ($this->template_config->enable_default_style && ! is_admin()) {
369
-            $this->addStylesheet(
370
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
371
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
372
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
373
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
374
-                array('dashicons')
375
-            );
376
-            //Load custom style sheet if available
377
-            if ($this->template_config->custom_style_sheet !== null) {
378
-                $this->addStylesheet(
379
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
380
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
381
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
382
-                );
383
-            }
384
-        }
385
-        $this->addStylesheet(
386
-            CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT,
387
-            $this->registry->getCssUrl(
388
-                $this->domain->assetNamespace(),
389
-                CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT
390
-            ),
391
-            ['dashicons']
392
-        );
393
-        $this->addStylesheet(
394
-            CoreAssetManager::CSS_HANDLE_COMPONENTS,
395
-            $this->registry->getCssUrl(
396
-                $this->domain->assetNamespace(),
397
-                CoreAssetManager::CSS_HANDLE_COMPONENTS
398
-            ),
399
-            array_merge(
400
-                $this->registry->getCssDependencies(
401
-                    $this->domain->assetNamespace(),
402
-                    CoreAssetManager::CSS_HANDLE_COMPONENTS
403
-                ),
404
-                [CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT]
405
-            )
406
-        );
407
-    }
408
-
409
-
410
-    /**
411
-     * jQuery Validate for form validation
412
-     *
413
-     * @since 4.9.62.p
414
-     * @throws DomainException
415
-     * @throws DuplicateCollectionIdentifierException
416
-     * @throws InvalidDataTypeException
417
-     * @throws InvalidEntityException
418
-     */
419
-    private function loadJqueryValidate()
420
-    {
421
-        $this->addJavascript(
422
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
423
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
424
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
425
-        )
426
-        ->setVersion('1.15.0');
427
-
428
-        $this->addJavascript(
429
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
430
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
431
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
432
-        )
433
-        ->setVersion('1.15.0');
434
-    }
435
-
436
-
437
-    /**
438
-     * accounting.js for performing client-side calculations
439
-     *
440
-     * @since 4.9.62.p
441
-     * @throws DomainException
442
-     * @throws DuplicateCollectionIdentifierException
443
-     * @throws InvalidDataTypeException
444
-     * @throws InvalidEntityException
445
-     */
446
-    private function loadAccountingJs()
447
-    {
448
-        //accounting.js library
449
-        // @link http://josscrowcroft.github.io/accounting.js/
450
-        $this->addJavascript(
451
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
452
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
453
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
454
-        )
455
-        ->setVersion('0.3.2');
456
-
457
-        $this->addJavascript(
458
-            CoreAssetManager::JS_HANDLE_ACCOUNTING,
459
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
460
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
461
-        )
462
-        ->setInlineDataCallback(
463
-            function () {
464
-                 wp_localize_script(
465
-                     CoreAssetManager::JS_HANDLE_ACCOUNTING,
466
-                     'EE_ACCOUNTING_CFG',
467
-                     $this->getAccountingSettings()
468
-                 );
469
-            }
470
-        )
471
-        ->setVersion();
472
-    }
473
-
474
-
475
-    /**
476
-     * registers assets for cleaning your ears
477
-     *
478
-     * @param JavascriptAsset $script
479
-     */
480
-    public function loadQtipJs(JavascriptAsset $script)
481
-    {
482
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
483
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
484
-        if (
485
-            $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
486
-            && apply_filters('FHEE_load_qtip', false)
487
-        ) {
488
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
489
-        }
490
-    }
491
-
492
-
493
-    /**
494
-     * assets that are used in the WordPress admin
495
-     *
496
-     * @since 4.9.62.p
497
-     * @throws DuplicateCollectionIdentifierException
498
-     * @throws InvalidDataTypeException
499
-     * @throws InvalidEntityException
500
-     */
501
-    private function registerAdminAssets()
502
-    {
503
-        $this->addJavascript(
504
-            CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
505
-            $this->registry->getJsUrl($this->domain->assetNamespace(), CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE),
506
-            $this->registry->getJsDependencies(
507
-                $this->domain->assetNamespace(),
508
-                CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
509
-            )
510
-        )
511
-        ->setRequiresTranslation();
512
-
513
-        $this->addStylesheet(
514
-            CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
515
-            $this->registry->getCssUrl($this->domain->assetNamespace(), CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE),
516
-            $this->registry->getCssDependencies(
517
-                $this->domain->assetNamespace(),
518
-                CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
519
-            )
520
-        );
521
-    }
85
+	const JS_HANDLE_ACCOUNTING = 'ee-accounting';
86
+
87
+	const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
88
+
89
+	// EE CSS assets handles
90
+	const CSS_HANDLE_DEFAULT = 'espresso_default';
91
+
92
+	const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
93
+
94
+	const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
95
+
96
+	const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
97
+
98
+	/**
99
+	 * @var EE_Currency_Config $currency_config
100
+	 */
101
+	protected $currency_config;
102
+
103
+	/**
104
+	 * @var EE_Template_Config $template_config
105
+	 */
106
+	protected $template_config;
107
+
108
+
109
+	/**
110
+	 * CoreAssetRegister constructor.
111
+	 *
112
+	 * @param AssetCollection    $assets
113
+	 * @param EE_Currency_Config $currency_config
114
+	 * @param EE_Template_Config $template_config
115
+	 * @param DomainInterface    $domain
116
+	 * @param Registry           $registry
117
+	 */
118
+	public function __construct(
119
+		AssetCollection $assets,
120
+		EE_Currency_Config $currency_config,
121
+		EE_Template_Config $template_config,
122
+		DomainInterface $domain,
123
+		Registry $registry
124
+	) {
125
+		$this->currency_config = $currency_config;
126
+		$this->template_config = $template_config;
127
+		parent::__construct($domain, $assets, $registry);
128
+	}
129
+
130
+
131
+	/**
132
+	 * @since 4.9.62.p
133
+	 * @throws DomainException
134
+	 * @throws DuplicateCollectionIdentifierException
135
+	 * @throws InvalidArgumentException
136
+	 * @throws InvalidDataTypeException
137
+	 * @throws InvalidEntityException
138
+	 * @throws InvalidInterfaceException
139
+	 */
140
+	public function addAssets()
141
+	{
142
+		$this->addJavascriptFiles();
143
+		$this->addStylesheetFiles();
144
+	}
145
+
146
+
147
+	/**
148
+	 * @since 4.9.62.p
149
+	 * @throws DomainException
150
+	 * @throws DuplicateCollectionIdentifierException
151
+	 * @throws InvalidArgumentException
152
+	 * @throws InvalidDataTypeException
153
+	 * @throws InvalidEntityException
154
+	 * @throws InvalidInterfaceException
155
+	 */
156
+	public function addJavascriptFiles()
157
+	{
158
+		$this->loadCoreJs();
159
+		$this->loadJqueryValidate();
160
+		$this->loadAccountingJs();
161
+		add_action(
162
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
163
+			array($this, 'loadQtipJs')
164
+		);
165
+		$this->registerAdminAssets();
166
+	}
167
+
168
+
169
+	/**
170
+	 * @since 4.9.62.p
171
+	 * @throws DuplicateCollectionIdentifierException
172
+	 * @throws InvalidDataTypeException
173
+	 * @throws InvalidEntityException
174
+	 */
175
+	public function addStylesheetFiles()
176
+	{
177
+		$this->loadCoreCss();
178
+	}
179
+
180
+
181
+	/**
182
+	 * core default javascript
183
+	 *
184
+	 * @since 4.9.62.p
185
+	 * @throws DomainException
186
+	 * @throws DuplicateCollectionIdentifierException
187
+	 * @throws InvalidArgumentException
188
+	 * @throws InvalidDataTypeException
189
+	 * @throws InvalidEntityException
190
+	 * @throws InvalidInterfaceException
191
+	 */
192
+	private function loadCoreJs()
193
+	{
194
+		// conditionally load third-party libraries that WP core MIGHT have.
195
+		$this->registerWpAssets();
196
+
197
+		$this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
198
+		$this->addJs(self::JS_HANDLE_VENDOR);
199
+		$this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
200
+		$this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
201
+		$this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
202
+		$this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
203
+		$this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
204
+			function () {
205
+				wp_add_inline_script(
206
+					CoreAssetManager::JS_HANDLE_DATA_STORES,
207
+					is_admin()
208
+						? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
209
+						: 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
210
+				);
211
+			}
212
+		);
213
+		$this->addJs(self::JS_HANDLE_HOCS, self::JS_HANDLE_DATA_STORES)->setRequiresTranslation();
214
+		$this->addJs(self::JS_HANDLE_COMPONENTS, self::JS_HANDLE_DATA_STORES)->setRequiresTranslation();
215
+		$this->addJs(self::JS_HANDLE_EDITOR_HOCS)->setRequiresTranslation();
216
+
217
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
218
+		$this->registry->addData(
219
+			'paths',
220
+			array(
221
+				'base_rest_route' => rest_url(),
222
+				'rest_route' => rest_url('ee/v4.8.36/'),
223
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
224
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
225
+				'site_url' => site_url('/'),
226
+				'admin_url' => admin_url('/'),
227
+			)
228
+		);
229
+		// Event Espresso brand name
230
+		$this->registry->addData('brandName', Domain::brandName());
231
+		/** site formatting values **/
232
+		$this->registry->addData(
233
+			'site_formats',
234
+			array(
235
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
236
+			)
237
+		);
238
+		/** currency data **/
239
+		$this->registry->addData(
240
+			'currency_config',
241
+			$this->getCurrencySettings()
242
+		);
243
+		/** site timezone */
244
+		$this->registry->addData(
245
+			'default_timezone',
246
+			array(
247
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
248
+				'string' => get_option('timezone_string'),
249
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
250
+			)
251
+		);
252
+		/** site locale (user locale if user logged in) */
253
+		$this->registry->addData(
254
+			'locale',
255
+			array(
256
+				'user' => get_user_locale(),
257
+				'site' => get_locale()
258
+			)
259
+		);
260
+
261
+		$this->addJavascript(
262
+			CoreAssetManager::JS_HANDLE_CORE,
263
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
264
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
265
+		)
266
+		->setInlineDataCallback(
267
+			function () {
268
+				wp_localize_script(
269
+					CoreAssetManager::JS_HANDLE_CORE,
270
+					CoreAssetManager::JS_HANDLE_I18N,
271
+					EE_Registry::$i18n_js_strings
272
+				);
273
+			}
274
+		);
275
+	}
276
+
277
+
278
+	/**
279
+	 * Registers vendor files that are bundled with a later version WP but might not be for the current version of
280
+	 * WordPress in the running environment.
281
+	 *
282
+	 * @throws DuplicateCollectionIdentifierException
283
+	 * @throws InvalidDataTypeException
284
+	 * @throws InvalidEntityException
285
+	 * @throws DomainException
286
+	 * @since 4.9.71.p
287
+	 */
288
+	private function registerWpAssets()
289
+	{
290
+		global $wp_version;
291
+		if (version_compare($wp_version, '5.0.beta', '>=')) {
292
+			return;
293
+		}
294
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
295
+			->setVersion('16.6.0');
296
+		$this->addVendorJavascript(
297
+			CoreAssetManager::JS_HANDLE_REACT_DOM,
298
+			array(CoreAssetManager::JS_HANDLE_REACT)
299
+		)->setVersion('16.6.0');
300
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
301
+			->setInlineDataCallback(
302
+				function() {
303
+					wp_add_inline_script(
304
+						CoreAssetManager::JS_HANDLE_LODASH,
305
+						'window.lodash = _.noConflict();'
306
+					);
307
+				}
308
+			)
309
+			->setVersion('4.17.11');
310
+	}
311
+
312
+
313
+	/**
314
+	 * Returns configuration data for the accounting-js library.
315
+	 * @since 4.9.71.p
316
+	 * @return array
317
+	 */
318
+	private function getAccountingSettings() {
319
+		return array(
320
+			'currency' => array(
321
+				'symbol'    => $this->currency_config->sign,
322
+				'format'    => array(
323
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
324
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
325
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
326
+				),
327
+				'decimal'   => $this->currency_config->dec_mrk,
328
+				'thousand'  => $this->currency_config->thsnds,
329
+				'precision' => $this->currency_config->dec_plc,
330
+			),
331
+			'number'   => array(
332
+				'precision' => $this->currency_config->dec_plc,
333
+				'thousand'  => $this->currency_config->thsnds,
334
+				'decimal'   => $this->currency_config->dec_mrk,
335
+			),
336
+		);
337
+	}
338
+
339
+
340
+	/**
341
+	 * Returns configuration data for the js Currency VO.
342
+	 * @since 4.9.71.p
343
+	 * @return array
344
+	 */
345
+	private function getCurrencySettings()
346
+	{
347
+		return array(
348
+			'code' => $this->currency_config->code,
349
+			'singularLabel' => $this->currency_config->name,
350
+			'pluralLabel' => $this->currency_config->plural,
351
+			'sign' => $this->currency_config->sign,
352
+			'signB4' => $this->currency_config->sign_b4,
353
+			'decimalPlaces' => $this->currency_config->dec_plc,
354
+			'decimalMark' => $this->currency_config->dec_mrk,
355
+			'thousandsSeparator' => $this->currency_config->thsnds,
356
+		);
357
+	}
358
+
359
+
360
+	/**
361
+	 * @since 4.9.62.p
362
+	 * @throws DuplicateCollectionIdentifierException
363
+	 * @throws InvalidDataTypeException
364
+	 * @throws InvalidEntityException
365
+	 */
366
+	private function loadCoreCss()
367
+	{
368
+		if ($this->template_config->enable_default_style && ! is_admin()) {
369
+			$this->addStylesheet(
370
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
371
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
372
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
373
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
374
+				array('dashicons')
375
+			);
376
+			//Load custom style sheet if available
377
+			if ($this->template_config->custom_style_sheet !== null) {
378
+				$this->addStylesheet(
379
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
380
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
381
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
382
+				);
383
+			}
384
+		}
385
+		$this->addStylesheet(
386
+			CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT,
387
+			$this->registry->getCssUrl(
388
+				$this->domain->assetNamespace(),
389
+				CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT
390
+			),
391
+			['dashicons']
392
+		);
393
+		$this->addStylesheet(
394
+			CoreAssetManager::CSS_HANDLE_COMPONENTS,
395
+			$this->registry->getCssUrl(
396
+				$this->domain->assetNamespace(),
397
+				CoreAssetManager::CSS_HANDLE_COMPONENTS
398
+			),
399
+			array_merge(
400
+				$this->registry->getCssDependencies(
401
+					$this->domain->assetNamespace(),
402
+					CoreAssetManager::CSS_HANDLE_COMPONENTS
403
+				),
404
+				[CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT]
405
+			)
406
+		);
407
+	}
408
+
409
+
410
+	/**
411
+	 * jQuery Validate for form validation
412
+	 *
413
+	 * @since 4.9.62.p
414
+	 * @throws DomainException
415
+	 * @throws DuplicateCollectionIdentifierException
416
+	 * @throws InvalidDataTypeException
417
+	 * @throws InvalidEntityException
418
+	 */
419
+	private function loadJqueryValidate()
420
+	{
421
+		$this->addJavascript(
422
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
423
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
424
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
425
+		)
426
+		->setVersion('1.15.0');
427
+
428
+		$this->addJavascript(
429
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
430
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
431
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
432
+		)
433
+		->setVersion('1.15.0');
434
+	}
435
+
436
+
437
+	/**
438
+	 * accounting.js for performing client-side calculations
439
+	 *
440
+	 * @since 4.9.62.p
441
+	 * @throws DomainException
442
+	 * @throws DuplicateCollectionIdentifierException
443
+	 * @throws InvalidDataTypeException
444
+	 * @throws InvalidEntityException
445
+	 */
446
+	private function loadAccountingJs()
447
+	{
448
+		//accounting.js library
449
+		// @link http://josscrowcroft.github.io/accounting.js/
450
+		$this->addJavascript(
451
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
452
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
453
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
454
+		)
455
+		->setVersion('0.3.2');
456
+
457
+		$this->addJavascript(
458
+			CoreAssetManager::JS_HANDLE_ACCOUNTING,
459
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
460
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
461
+		)
462
+		->setInlineDataCallback(
463
+			function () {
464
+				 wp_localize_script(
465
+					 CoreAssetManager::JS_HANDLE_ACCOUNTING,
466
+					 'EE_ACCOUNTING_CFG',
467
+					 $this->getAccountingSettings()
468
+				 );
469
+			}
470
+		)
471
+		->setVersion();
472
+	}
473
+
474
+
475
+	/**
476
+	 * registers assets for cleaning your ears
477
+	 *
478
+	 * @param JavascriptAsset $script
479
+	 */
480
+	public function loadQtipJs(JavascriptAsset $script)
481
+	{
482
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
483
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
484
+		if (
485
+			$script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
486
+			&& apply_filters('FHEE_load_qtip', false)
487
+		) {
488
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
489
+		}
490
+	}
491
+
492
+
493
+	/**
494
+	 * assets that are used in the WordPress admin
495
+	 *
496
+	 * @since 4.9.62.p
497
+	 * @throws DuplicateCollectionIdentifierException
498
+	 * @throws InvalidDataTypeException
499
+	 * @throws InvalidEntityException
500
+	 */
501
+	private function registerAdminAssets()
502
+	{
503
+		$this->addJavascript(
504
+			CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
505
+			$this->registry->getJsUrl($this->domain->assetNamespace(), CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE),
506
+			$this->registry->getJsDependencies(
507
+				$this->domain->assetNamespace(),
508
+				CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
509
+			)
510
+		)
511
+		->setRequiresTranslation();
512
+
513
+		$this->addStylesheet(
514
+			CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
515
+			$this->registry->getCssUrl($this->domain->assetNamespace(), CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE),
516
+			$this->registry->getCssDependencies(
517
+				$this->domain->assetNamespace(),
518
+				CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
519
+			)
520
+		);
521
+	}
522 522
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
         $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
202 202
         $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
203 203
         $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
204
-            function () {
204
+            function() {
205 205
                 wp_add_inline_script(
206 206
                     CoreAssetManager::JS_HANDLE_DATA_STORES,
207 207
                     is_admin()
@@ -260,11 +260,11 @@  discard block
 block discarded – undo
260 260
 
261 261
         $this->addJavascript(
262 262
             CoreAssetManager::JS_HANDLE_CORE,
263
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
263
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
264 264
             array(CoreAssetManager::JS_HANDLE_JQUERY)
265 265
         )
266 266
         ->setInlineDataCallback(
267
-            function () {
267
+            function() {
268 268
                 wp_localize_script(
269 269
                     CoreAssetManager::JS_HANDLE_CORE,
270 270
                     CoreAssetManager::JS_HANDLE_I18N,
@@ -368,16 +368,16 @@  discard block
 block discarded – undo
368 368
         if ($this->template_config->enable_default_style && ! is_admin()) {
369 369
             $this->addStylesheet(
370 370
                 CoreAssetManager::CSS_HANDLE_DEFAULT,
371
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
371
+                is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
372 372
                     ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
373
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
373
+                    : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
374 374
                 array('dashicons')
375 375
             );
376 376
             //Load custom style sheet if available
377 377
             if ($this->template_config->custom_style_sheet !== null) {
378 378
                 $this->addStylesheet(
379 379
                     CoreAssetManager::CSS_HANDLE_CUSTOM,
380
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
380
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
381 381
                     array(CoreAssetManager::CSS_HANDLE_DEFAULT)
382 382
                 );
383 383
             }
@@ -420,14 +420,14 @@  discard block
 block discarded – undo
420 420
     {
421 421
         $this->addJavascript(
422 422
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
423
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
423
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
424 424
             array(CoreAssetManager::JS_HANDLE_JQUERY)
425 425
         )
426 426
         ->setVersion('1.15.0');
427 427
 
428 428
         $this->addJavascript(
429 429
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
430
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
430
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
431 431
             array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
432 432
         )
433 433
         ->setVersion('1.15.0');
@@ -449,18 +449,18 @@  discard block
 block discarded – undo
449 449
         // @link http://josscrowcroft.github.io/accounting.js/
450 450
         $this->addJavascript(
451 451
             CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
452
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
452
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
453 453
             array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
454 454
         )
455 455
         ->setVersion('0.3.2');
456 456
 
457 457
         $this->addJavascript(
458 458
             CoreAssetManager::JS_HANDLE_ACCOUNTING,
459
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
459
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
460 460
             array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
461 461
         )
462 462
         ->setInlineDataCallback(
463
-            function () {
463
+            function() {
464 464
                  wp_localize_script(
465 465
                      CoreAssetManager::JS_HANDLE_ACCOUNTING,
466 466
                      'EE_ACCOUNTING_CFG',
Please login to merge, or discard this patch.
core/services/assets/AssetManager.php 2 patches
Indentation   +229 added lines, -229 removed lines patch added patch discarded remove patch
@@ -23,233 +23,233 @@
 block discarded – undo
23 23
 abstract class AssetManager implements AssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var AssetCollection $assets
28
-     */
29
-    protected $assets;
30
-
31
-    /**
32
-     * @var DomainInterface
33
-     */
34
-    protected $domain;
35
-
36
-    /**
37
-     * @var Registry $registry
38
-     */
39
-    protected $registry;
40
-
41
-
42
-    /**
43
-     * AssetRegister constructor.
44
-     *
45
-     * @param DomainInterface $domain
46
-     * @param AssetCollection $assets
47
-     * @param Registry        $registry
48
-     */
49
-    public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
-    {
51
-        $this->domain = $domain;
52
-        $this->assets = $assets;
53
-        $this->registry = $registry;
54
-        add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
55
-        add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
56
-        add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
57
-        add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
58
-    }
59
-
60
-
61
-    /**
62
-     * @since 4.9.71.p
63
-     * @return string
64
-     */
65
-    public function assetNamespace()
66
-    {
67
-        return $this->domain->assetNamespace();
68
-    }
69
-
70
-
71
-    /**
72
-     * @return void
73
-     * @throws DuplicateCollectionIdentifierException
74
-     * @throws InvalidDataTypeException
75
-     * @throws InvalidEntityException
76
-     * @since 4.9.62.p
77
-     */
78
-    public function addManifestFile()
79
-    {
80
-        // if a manifest file has already been added for this domain, then just return
81
-        if ($this->assets->has($this->domain->assetNamespace())) {
82
-            return;
83
-        }
84
-        $asset = new ManifestFile($this->domain);
85
-        $this->assets->add($asset, $this->domain->assetNamespace());
86
-    }
87
-
88
-
89
-    /**
90
-     * @return ManifestFile[]
91
-     * @since 4.9.62.p
92
-     */
93
-    public function getManifestFile()
94
-    {
95
-        return $this->assets->getManifestFiles();
96
-    }
97
-
98
-
99
-    /**
100
-     * @param string $handle
101
-     * @param string $source
102
-     * @param array  $dependencies
103
-     * @param bool   $load_in_footer
104
-     * @return JavascriptAsset
105
-     * @throws DuplicateCollectionIdentifierException
106
-     * @throws InvalidDataTypeException
107
-     * @throws InvalidEntityException
108
-     * @since 4.9.62.p
109
-     */
110
-    public function addJavascript(
111
-        $handle,
112
-        $source,
113
-        array $dependencies = array(),
114
-        $load_in_footer = true
115
-    ) {
116
-        $asset = new JavascriptAsset(
117
-            $handle,
118
-            $source,
119
-            array_unique($dependencies),
120
-            $load_in_footer,
121
-            $this->domain
122
-        );
123
-        $this->assets->add($asset, $handle);
124
-        return $asset;
125
-    }
126
-
127
-
128
-    /**
129
-     * Used to register a javascript asset where everything is dynamically derived from the given handle.
130
-     *
131
-     * @param string $handle
132
-     * @param string|array  $extra_dependencies
133
-     * @return JavascriptAsset
134
-     * @throws DuplicateCollectionIdentifierException
135
-     * @throws InvalidDataTypeException
136
-     * @throws InvalidEntityException
137
-     */
138
-    public function addJs($handle, $extra_dependencies = [])
139
-    {
140
-        $dependencies = $this->registry->getJsDependencies(
141
-            $this->domain->assetNamespace(),
142
-            $handle
143
-        );
144
-        $dependencies = ! empty( $extra_dependencies )
145
-            ? array_merge(( array ) $extra_dependencies, $dependencies)
146
-            : $dependencies;
147
-        return $this->addJavascript(
148
-            $handle,
149
-            $this->registry->getJsUrl($this->domain->assetNamespace(), $handle),
150
-            $dependencies
151
-        );
152
-    }
153
-
154
-
155
-    /**
156
-     * @param string $handle
157
-     * @param array  $dependencies
158
-     * @param bool   $load_in_footer
159
-     * @return JavascriptAsset
160
-     * @throws DuplicateCollectionIdentifierException
161
-     * @throws InvalidDataTypeException
162
-     * @throws InvalidEntityException
163
-     * @throws DomainException
164
-     * @since 4.9.71.p
165
-     */
166
-    public function addVendorJavascript(
167
-        $handle,
168
-        array $dependencies = array(),
169
-        $load_in_footer = true
170
-    ) {
171
-        $dev_suffix = wp_scripts_get_suffix('dev');
172
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
173
-        return $this->addJavascript(
174
-            $handle,
175
-            "{$vendor_path}{$handle}{$dev_suffix}.js",
176
-            $dependencies,
177
-            $load_in_footer
178
-        );
179
-    }
180
-
181
-
182
-
183
-    /**
184
-     * @param string $handle
185
-     * @param string $source
186
-     * @param array  $dependencies
187
-     * @param string $media
188
-     * @return StylesheetAsset
189
-     * @throws DuplicateCollectionIdentifierException
190
-     * @throws InvalidDataTypeException
191
-     * @throws InvalidEntityException
192
-     * @since 4.9.62.p
193
-     */
194
-    public function addStylesheet(
195
-        $handle,
196
-        $source,
197
-        array $dependencies = array(),
198
-        $media = 'all'
199
-    ) {
200
-        $asset = new StylesheetAsset(
201
-            $handle,
202
-            $source,
203
-            array_unique($dependencies),
204
-            $this->domain,
205
-            $media
206
-        );
207
-        $this->assets->add($asset, $handle);
208
-        return $asset;
209
-    }
210
-
211
-
212
-    /**
213
-     * Used to register a css asset where everything is dynamically derived from the given handle.
214
-     *
215
-     * @param string $handle
216
-     * @param string|array  $extra_dependencies
217
-     * @return StylesheetAsset
218
-     * @throws DuplicateCollectionIdentifierException
219
-     * @throws InvalidDataTypeException
220
-     * @throws InvalidEntityException
221
-     */
222
-    public function addCss($handle, $extra_dependencies = [])
223
-    {
224
-        $dependencies = $this->registry->getCssDependencies(
225
-            $this->domain->assetNamespace(),
226
-            $handle
227
-        );
228
-        $dependencies = ! empty( $extra_dependencies )
229
-            ? array_merge(( array ) $extra_dependencies, $dependencies)
230
-            : $dependencies;
231
-        return $this->addStylesheet(
232
-            $handle,
233
-            $this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
234
-            $dependencies
235
-        );
236
-    }
237
-
238
-
239
-    /**
240
-     * @param string $handle
241
-     * @return bool
242
-     * @since 4.9.62.p
243
-     */
244
-    public function enqueueAsset($handle)
245
-    {
246
-        if ($this->assets->has($handle)) {
247
-            $asset = $this->assets->get($handle);
248
-            if ($asset->isRegistered()) {
249
-                $asset->enqueueAsset();
250
-                return true;
251
-            }
252
-        }
253
-        return false;
254
-    }
26
+	/**
27
+	 * @var AssetCollection $assets
28
+	 */
29
+	protected $assets;
30
+
31
+	/**
32
+	 * @var DomainInterface
33
+	 */
34
+	protected $domain;
35
+
36
+	/**
37
+	 * @var Registry $registry
38
+	 */
39
+	protected $registry;
40
+
41
+
42
+	/**
43
+	 * AssetRegister constructor.
44
+	 *
45
+	 * @param DomainInterface $domain
46
+	 * @param AssetCollection $assets
47
+	 * @param Registry        $registry
48
+	 */
49
+	public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry)
50
+	{
51
+		$this->domain = $domain;
52
+		$this->assets = $assets;
53
+		$this->registry = $registry;
54
+		add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0);
55
+		add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0);
56
+		add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2);
57
+		add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2);
58
+	}
59
+
60
+
61
+	/**
62
+	 * @since 4.9.71.p
63
+	 * @return string
64
+	 */
65
+	public function assetNamespace()
66
+	{
67
+		return $this->domain->assetNamespace();
68
+	}
69
+
70
+
71
+	/**
72
+	 * @return void
73
+	 * @throws DuplicateCollectionIdentifierException
74
+	 * @throws InvalidDataTypeException
75
+	 * @throws InvalidEntityException
76
+	 * @since 4.9.62.p
77
+	 */
78
+	public function addManifestFile()
79
+	{
80
+		// if a manifest file has already been added for this domain, then just return
81
+		if ($this->assets->has($this->domain->assetNamespace())) {
82
+			return;
83
+		}
84
+		$asset = new ManifestFile($this->domain);
85
+		$this->assets->add($asset, $this->domain->assetNamespace());
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return ManifestFile[]
91
+	 * @since 4.9.62.p
92
+	 */
93
+	public function getManifestFile()
94
+	{
95
+		return $this->assets->getManifestFiles();
96
+	}
97
+
98
+
99
+	/**
100
+	 * @param string $handle
101
+	 * @param string $source
102
+	 * @param array  $dependencies
103
+	 * @param bool   $load_in_footer
104
+	 * @return JavascriptAsset
105
+	 * @throws DuplicateCollectionIdentifierException
106
+	 * @throws InvalidDataTypeException
107
+	 * @throws InvalidEntityException
108
+	 * @since 4.9.62.p
109
+	 */
110
+	public function addJavascript(
111
+		$handle,
112
+		$source,
113
+		array $dependencies = array(),
114
+		$load_in_footer = true
115
+	) {
116
+		$asset = new JavascriptAsset(
117
+			$handle,
118
+			$source,
119
+			array_unique($dependencies),
120
+			$load_in_footer,
121
+			$this->domain
122
+		);
123
+		$this->assets->add($asset, $handle);
124
+		return $asset;
125
+	}
126
+
127
+
128
+	/**
129
+	 * Used to register a javascript asset where everything is dynamically derived from the given handle.
130
+	 *
131
+	 * @param string $handle
132
+	 * @param string|array  $extra_dependencies
133
+	 * @return JavascriptAsset
134
+	 * @throws DuplicateCollectionIdentifierException
135
+	 * @throws InvalidDataTypeException
136
+	 * @throws InvalidEntityException
137
+	 */
138
+	public function addJs($handle, $extra_dependencies = [])
139
+	{
140
+		$dependencies = $this->registry->getJsDependencies(
141
+			$this->domain->assetNamespace(),
142
+			$handle
143
+		);
144
+		$dependencies = ! empty( $extra_dependencies )
145
+			? array_merge(( array ) $extra_dependencies, $dependencies)
146
+			: $dependencies;
147
+		return $this->addJavascript(
148
+			$handle,
149
+			$this->registry->getJsUrl($this->domain->assetNamespace(), $handle),
150
+			$dependencies
151
+		);
152
+	}
153
+
154
+
155
+	/**
156
+	 * @param string $handle
157
+	 * @param array  $dependencies
158
+	 * @param bool   $load_in_footer
159
+	 * @return JavascriptAsset
160
+	 * @throws DuplicateCollectionIdentifierException
161
+	 * @throws InvalidDataTypeException
162
+	 * @throws InvalidEntityException
163
+	 * @throws DomainException
164
+	 * @since 4.9.71.p
165
+	 */
166
+	public function addVendorJavascript(
167
+		$handle,
168
+		array $dependencies = array(),
169
+		$load_in_footer = true
170
+	) {
171
+		$dev_suffix = wp_scripts_get_suffix('dev');
172
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
173
+		return $this->addJavascript(
174
+			$handle,
175
+			"{$vendor_path}{$handle}{$dev_suffix}.js",
176
+			$dependencies,
177
+			$load_in_footer
178
+		);
179
+	}
180
+
181
+
182
+
183
+	/**
184
+	 * @param string $handle
185
+	 * @param string $source
186
+	 * @param array  $dependencies
187
+	 * @param string $media
188
+	 * @return StylesheetAsset
189
+	 * @throws DuplicateCollectionIdentifierException
190
+	 * @throws InvalidDataTypeException
191
+	 * @throws InvalidEntityException
192
+	 * @since 4.9.62.p
193
+	 */
194
+	public function addStylesheet(
195
+		$handle,
196
+		$source,
197
+		array $dependencies = array(),
198
+		$media = 'all'
199
+	) {
200
+		$asset = new StylesheetAsset(
201
+			$handle,
202
+			$source,
203
+			array_unique($dependencies),
204
+			$this->domain,
205
+			$media
206
+		);
207
+		$this->assets->add($asset, $handle);
208
+		return $asset;
209
+	}
210
+
211
+
212
+	/**
213
+	 * Used to register a css asset where everything is dynamically derived from the given handle.
214
+	 *
215
+	 * @param string $handle
216
+	 * @param string|array  $extra_dependencies
217
+	 * @return StylesheetAsset
218
+	 * @throws DuplicateCollectionIdentifierException
219
+	 * @throws InvalidDataTypeException
220
+	 * @throws InvalidEntityException
221
+	 */
222
+	public function addCss($handle, $extra_dependencies = [])
223
+	{
224
+		$dependencies = $this->registry->getCssDependencies(
225
+			$this->domain->assetNamespace(),
226
+			$handle
227
+		);
228
+		$dependencies = ! empty( $extra_dependencies )
229
+			? array_merge(( array ) $extra_dependencies, $dependencies)
230
+			: $dependencies;
231
+		return $this->addStylesheet(
232
+			$handle,
233
+			$this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
234
+			$dependencies
235
+		);
236
+	}
237
+
238
+
239
+	/**
240
+	 * @param string $handle
241
+	 * @return bool
242
+	 * @since 4.9.62.p
243
+	 */
244
+	public function enqueueAsset($handle)
245
+	{
246
+		if ($this->assets->has($handle)) {
247
+			$asset = $this->assets->get($handle);
248
+			if ($asset->isRegistered()) {
249
+				$asset->enqueueAsset();
250
+				return true;
251
+			}
252
+		}
253
+		return false;
254
+	}
255 255
 }
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
             $this->domain->assetNamespace(),
142 142
             $handle
143 143
         );
144
-        $dependencies = ! empty( $extra_dependencies )
145
-            ? array_merge(( array ) $extra_dependencies, $dependencies)
144
+        $dependencies = ! empty($extra_dependencies)
145
+            ? array_merge((array) $extra_dependencies, $dependencies)
146 146
             : $dependencies;
147 147
         return $this->addJavascript(
148 148
             $handle,
@@ -169,7 +169,7 @@  discard block
 block discarded – undo
169 169
         $load_in_footer = true
170 170
     ) {
171 171
         $dev_suffix = wp_scripts_get_suffix('dev');
172
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
172
+        $vendor_path = $this->domain->pluginUrl().'assets/vendor/';
173 173
         return $this->addJavascript(
174 174
             $handle,
175 175
             "{$vendor_path}{$handle}{$dev_suffix}.js",
@@ -225,8 +225,8 @@  discard block
 block discarded – undo
225 225
             $this->domain->assetNamespace(),
226 226
             $handle
227 227
         );
228
-        $dependencies = ! empty( $extra_dependencies )
229
-            ? array_merge(( array ) $extra_dependencies, $dependencies)
228
+        $dependencies = ! empty($extra_dependencies)
229
+            ? array_merge((array) $extra_dependencies, $dependencies)
230 230
             : $dependencies;
231 231
         return $this->addStylesheet(
232 232
             $handle,
Please login to merge, or discard this patch.