Completed
Pull Request — master (#1116)
by Darren
09:07
created
core/services/assets/Registry.php 2 patches
Indentation   +584 added lines, -584 removed lines patch added patch discarded remove patch
@@ -23,595 +23,595 @@
 block discarded – undo
23 23
 class Registry
24 24
 {
25 25
 
26
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
-
28
-    /**
29
-     * @var AssetCollection $assets
30
-     */
31
-    protected $assets;
32
-
33
-    /**
34
-     * @var I18nRegistry
35
-     */
36
-    private $i18n_registry;
37
-
38
-    /**
39
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
-     *
41
-     * @var array
42
-     */
43
-    protected $jsdata = array();
44
-
45
-    /**
46
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
-     * page source.
48
-     *
49
-     * @var array
50
-     */
51
-    private $script_handles_with_data = array();
52
-
53
-
54
-    /**
55
-     * Holds the manifest data obtained from registered manifest files.
56
-     * Manifests are maps of asset chunk name to actual built asset file names.
57
-     * Shape of this array is:
58
-     * array(
59
-     *  'some_namespace_slug' => array(
60
-     *      'some_chunk_name' => array(
61
-     *          'js' => 'filename.js'
62
-     *          'css' => 'filename.js'
63
-     *      ),
64
-     *      'url_base' => 'https://baseurl.com/to/assets
65
-     *  )
66
-     * )
67
-     *
68
-     * @var array
69
-     */
70
-    private $manifest_data = array();
71
-
72
-
73
-    /**
74
-     * Registry constructor.
75
-     * Hooking into WP actions for script registry.
76
-     *
77
-     * @param AssetCollection $assets
78
-     * @param I18nRegistry    $i18n_registry
79
-     */
80
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
81
-    {
82
-        $this->assets = $assets;
83
-        $this->i18n_registry = $i18n_registry;
84
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
86
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
88
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
89
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
90
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
91
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
92
-    }
93
-
94
-
95
-    /**
96
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
97
-     * translation handling.
98
-     *
99
-     * @return I18nRegistry
100
-     */
101
-    public function getI18nRegistry()
102
-    {
103
-        return $this->i18n_registry;
104
-    }
105
-
106
-
107
-    /**
108
-     * Callback for the wp_enqueue_scripts actions used to register assets.
109
-     *
110
-     * @since 4.9.62.p
111
-     * @throws Exception
112
-     */
113
-    public function registerScriptsAndStyles()
114
-    {
115
-        try {
116
-            $this->registerScripts($this->assets->getJavascriptAssets());
117
-            $this->registerStyles($this->assets->getStylesheetAssets());
118
-        } catch (Exception $exception) {
119
-            new ExceptionStackTraceDisplay($exception);
120
-        }
121
-    }
122
-
123
-
124
-    /**
125
-     * Registers JS assets with WP core
126
-     *
127
-     * @since 4.9.62.p
128
-     * @param JavascriptAsset[] $scripts
129
-     * @throws AssetRegistrationException
130
-     * @throws InvalidDataTypeException
131
-     */
132
-    public function registerScripts(array $scripts)
133
-    {
134
-        foreach ($scripts as $script) {
135
-            // skip to next script if this has already been done
136
-            if ($script->isRegistered()) {
137
-                continue;
138
-            }
139
-            do_action(
140
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
141
-                $script
142
-            );
143
-            $registered = wp_register_script(
144
-                $script->handle(),
145
-                $script->source(),
146
-                $script->dependencies(),
147
-                $script->version(),
148
-                $script->loadInFooter()
149
-            );
150
-            if (! $registered && $this->debug()) {
151
-                throw new AssetRegistrationException($script->handle());
152
-            }
153
-            $script->setRegistered($registered);
154
-            if ($script->requiresTranslation()) {
155
-                $this->registerTranslation($script->handle());
156
-            }
157
-            do_action(
158
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
159
-                $script
160
-            );
161
-        }
162
-    }
163
-
164
-
165
-    /**
166
-     * Registers CSS assets with WP core
167
-     *
168
-     * @since 4.9.62.p
169
-     * @param StylesheetAsset[] $styles
170
-     * @throws InvalidDataTypeException
171
-     */
172
-    public function registerStyles(array $styles)
173
-    {
174
-        foreach ($styles as $style) {
175
-            // skip to next style if this has already been done
176
-            if ($style->isRegistered()) {
177
-                continue;
178
-            }
179
-            do_action(
180
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
181
-                $style
182
-            );
183
-            wp_register_style(
184
-                $style->handle(),
185
-                $style->source(),
186
-                $style->dependencies(),
187
-                $style->version(),
188
-                $style->media()
189
-            );
190
-            $style->setRegistered();
191
-            do_action(
192
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
193
-                $style
194
-            );
195
-        }
196
-    }
197
-
198
-
199
-    /**
200
-     * Call back for the script print in frontend and backend.
201
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
202
-     *
203
-     * @since 4.9.31.rc.015
204
-     */
205
-    public function enqueueData()
206
-    {
207
-        $this->removeAlreadyRegisteredDataForScriptHandles();
208
-        wp_add_inline_script(
209
-            'eejs-core',
210
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
211
-            'before'
212
-        );
213
-        $scripts = $this->assets->getJavascriptAssetsWithData();
214
-        foreach ($scripts as $script) {
215
-            $this->addRegisteredScriptHandlesWithData($script->handle());
216
-            if ($script->hasInlineDataCallback()) {
217
-                $localize = $script->inlineDataCallback();
218
-                $localize();
219
-            }
220
-        }
221
-    }
222
-
223
-
224
-    /**
225
-     * Used to add data to eejs.data object.
226
-     * Note:  Overriding existing data is not allowed.
227
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
228
-     * If the data you add is something like this:
229
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
230
-     * It will be exposed in the page source as:
231
-     *  eejs.data.my_plugin_data.foo == gar
232
-     *
233
-     * @param string       $key   Key used to access your data
234
-     * @param string|array $value Value to attach to key
235
-     * @throws InvalidArgumentException
236
-     */
237
-    public function addData($key, $value)
238
-    {
239
-        if ($this->verifyDataNotExisting($key)) {
240
-            $this->jsdata[ $key ] = $value;
241
-        }
242
-    }
243
-
244
-
245
-    /**
246
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
247
-     * elements in an array.
248
-     *
249
-     * When you use this method, the value you include will be merged with the array on $key.
250
-     * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
251
-     * object like this, eejs.data.test = [ my_data,
252
-     * ]
253
-     * If there has already been a scalar value attached to the data object given key (via addData for instance), then
254
-     * this will throw an exception.
255
-     *
256
-     * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
257
-     * key potentially overriding the existing data on merge (specifically with associative arrays).
258
-     *
259
-     * @param string       $key   Key to attach data to.
260
-     * @param string|array $value Value being registered.
261
-     * @throws InvalidArgumentException
262
-     */
263
-    public function pushData($key, $value)
264
-    {
265
-        if (isset($this->jsdata[ $key ])
266
-            && ! is_array($this->jsdata[ $key ])
267
-        ) {
268
-            if (! $this->debug()) {
269
-                return;
270
-            }
271
-            throw new InvalidArgumentException(
272
-                sprintf(
273
-                    __(
274
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
26
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
27
+
28
+	/**
29
+	 * @var AssetCollection $assets
30
+	 */
31
+	protected $assets;
32
+
33
+	/**
34
+	 * @var I18nRegistry
35
+	 */
36
+	private $i18n_registry;
37
+
38
+	/**
39
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
40
+	 *
41
+	 * @var array
42
+	 */
43
+	protected $jsdata = array();
44
+
45
+	/**
46
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
47
+	 * page source.
48
+	 *
49
+	 * @var array
50
+	 */
51
+	private $script_handles_with_data = array();
52
+
53
+
54
+	/**
55
+	 * Holds the manifest data obtained from registered manifest files.
56
+	 * Manifests are maps of asset chunk name to actual built asset file names.
57
+	 * Shape of this array is:
58
+	 * array(
59
+	 *  'some_namespace_slug' => array(
60
+	 *      'some_chunk_name' => array(
61
+	 *          'js' => 'filename.js'
62
+	 *          'css' => 'filename.js'
63
+	 *      ),
64
+	 *      'url_base' => 'https://baseurl.com/to/assets
65
+	 *  )
66
+	 * )
67
+	 *
68
+	 * @var array
69
+	 */
70
+	private $manifest_data = array();
71
+
72
+
73
+	/**
74
+	 * Registry constructor.
75
+	 * Hooking into WP actions for script registry.
76
+	 *
77
+	 * @param AssetCollection $assets
78
+	 * @param I18nRegistry    $i18n_registry
79
+	 */
80
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
81
+	{
82
+		$this->assets = $assets;
83
+		$this->i18n_registry = $i18n_registry;
84
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
85
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
86
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
87
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
88
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
89
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
90
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
91
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
92
+	}
93
+
94
+
95
+	/**
96
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
97
+	 * translation handling.
98
+	 *
99
+	 * @return I18nRegistry
100
+	 */
101
+	public function getI18nRegistry()
102
+	{
103
+		return $this->i18n_registry;
104
+	}
105
+
106
+
107
+	/**
108
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
109
+	 *
110
+	 * @since 4.9.62.p
111
+	 * @throws Exception
112
+	 */
113
+	public function registerScriptsAndStyles()
114
+	{
115
+		try {
116
+			$this->registerScripts($this->assets->getJavascriptAssets());
117
+			$this->registerStyles($this->assets->getStylesheetAssets());
118
+		} catch (Exception $exception) {
119
+			new ExceptionStackTraceDisplay($exception);
120
+		}
121
+	}
122
+
123
+
124
+	/**
125
+	 * Registers JS assets with WP core
126
+	 *
127
+	 * @since 4.9.62.p
128
+	 * @param JavascriptAsset[] $scripts
129
+	 * @throws AssetRegistrationException
130
+	 * @throws InvalidDataTypeException
131
+	 */
132
+	public function registerScripts(array $scripts)
133
+	{
134
+		foreach ($scripts as $script) {
135
+			// skip to next script if this has already been done
136
+			if ($script->isRegistered()) {
137
+				continue;
138
+			}
139
+			do_action(
140
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
141
+				$script
142
+			);
143
+			$registered = wp_register_script(
144
+				$script->handle(),
145
+				$script->source(),
146
+				$script->dependencies(),
147
+				$script->version(),
148
+				$script->loadInFooter()
149
+			);
150
+			if (! $registered && $this->debug()) {
151
+				throw new AssetRegistrationException($script->handle());
152
+			}
153
+			$script->setRegistered($registered);
154
+			if ($script->requiresTranslation()) {
155
+				$this->registerTranslation($script->handle());
156
+			}
157
+			do_action(
158
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
159
+				$script
160
+			);
161
+		}
162
+	}
163
+
164
+
165
+	/**
166
+	 * Registers CSS assets with WP core
167
+	 *
168
+	 * @since 4.9.62.p
169
+	 * @param StylesheetAsset[] $styles
170
+	 * @throws InvalidDataTypeException
171
+	 */
172
+	public function registerStyles(array $styles)
173
+	{
174
+		foreach ($styles as $style) {
175
+			// skip to next style if this has already been done
176
+			if ($style->isRegistered()) {
177
+				continue;
178
+			}
179
+			do_action(
180
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
181
+				$style
182
+			);
183
+			wp_register_style(
184
+				$style->handle(),
185
+				$style->source(),
186
+				$style->dependencies(),
187
+				$style->version(),
188
+				$style->media()
189
+			);
190
+			$style->setRegistered();
191
+			do_action(
192
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
193
+				$style
194
+			);
195
+		}
196
+	}
197
+
198
+
199
+	/**
200
+	 * Call back for the script print in frontend and backend.
201
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
202
+	 *
203
+	 * @since 4.9.31.rc.015
204
+	 */
205
+	public function enqueueData()
206
+	{
207
+		$this->removeAlreadyRegisteredDataForScriptHandles();
208
+		wp_add_inline_script(
209
+			'eejs-core',
210
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
211
+			'before'
212
+		);
213
+		$scripts = $this->assets->getJavascriptAssetsWithData();
214
+		foreach ($scripts as $script) {
215
+			$this->addRegisteredScriptHandlesWithData($script->handle());
216
+			if ($script->hasInlineDataCallback()) {
217
+				$localize = $script->inlineDataCallback();
218
+				$localize();
219
+			}
220
+		}
221
+	}
222
+
223
+
224
+	/**
225
+	 * Used to add data to eejs.data object.
226
+	 * Note:  Overriding existing data is not allowed.
227
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
228
+	 * If the data you add is something like this:
229
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
230
+	 * It will be exposed in the page source as:
231
+	 *  eejs.data.my_plugin_data.foo == gar
232
+	 *
233
+	 * @param string       $key   Key used to access your data
234
+	 * @param string|array $value Value to attach to key
235
+	 * @throws InvalidArgumentException
236
+	 */
237
+	public function addData($key, $value)
238
+	{
239
+		if ($this->verifyDataNotExisting($key)) {
240
+			$this->jsdata[ $key ] = $value;
241
+		}
242
+	}
243
+
244
+
245
+	/**
246
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
247
+	 * elements in an array.
248
+	 *
249
+	 * When you use this method, the value you include will be merged with the array on $key.
250
+	 * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
251
+	 * object like this, eejs.data.test = [ my_data,
252
+	 * ]
253
+	 * If there has already been a scalar value attached to the data object given key (via addData for instance), then
254
+	 * this will throw an exception.
255
+	 *
256
+	 * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
257
+	 * key potentially overriding the existing data on merge (specifically with associative arrays).
258
+	 *
259
+	 * @param string       $key   Key to attach data to.
260
+	 * @param string|array $value Value being registered.
261
+	 * @throws InvalidArgumentException
262
+	 */
263
+	public function pushData($key, $value)
264
+	{
265
+		if (isset($this->jsdata[ $key ])
266
+			&& ! is_array($this->jsdata[ $key ])
267
+		) {
268
+			if (! $this->debug()) {
269
+				return;
270
+			}
271
+			throw new InvalidArgumentException(
272
+				sprintf(
273
+					__(
274
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
275 275
                          push values to this data element when it is an array.',
276
-                        'event_espresso'
277
-                    ),
278
-                    $key,
279
-                    __METHOD__
280
-                )
281
-            );
282
-        }
283
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
284
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
285
-        } else {
286
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
287
-        }
288
-    }
289
-
290
-
291
-    /**
292
-     * Used to set content used by javascript for a template.
293
-     * Note: Overrides of existing registered templates are not allowed.
294
-     *
295
-     * @param string $template_reference
296
-     * @param string $template_content
297
-     * @throws InvalidArgumentException
298
-     */
299
-    public function addTemplate($template_reference, $template_content)
300
-    {
301
-        if (! isset($this->jsdata['templates'])) {
302
-            $this->jsdata['templates'] = array();
303
-        }
304
-        //no overrides allowed.
305
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
306
-            if (! $this->debug()) {
307
-                return;
308
-            }
309
-            throw new InvalidArgumentException(
310
-                sprintf(
311
-                    __(
312
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
313
-                        'event_espresso'
314
-                    ),
315
-                    $template_reference
316
-                )
317
-            );
318
-        }
319
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
320
-    }
321
-
322
-
323
-    /**
324
-     * Retrieve the template content already registered for the given reference.
325
-     *
326
-     * @param string $template_reference
327
-     * @return string
328
-     */
329
-    public function getTemplate($template_reference)
330
-    {
331
-        return isset($this->jsdata['templates'][ $template_reference ])
332
-            ? $this->jsdata['templates'][ $template_reference ]
333
-            : '';
334
-    }
335
-
336
-
337
-    /**
338
-     * Retrieve registered data.
339
-     *
340
-     * @param string $key Name of key to attach data to.
341
-     * @return mixed                If there is no for the given key, then false is returned.
342
-     */
343
-    public function getData($key)
344
-    {
345
-        return isset($this->jsdata[ $key ])
346
-            ? $this->jsdata[ $key ]
347
-            : false;
348
-    }
349
-
350
-
351
-    /**
352
-     * Verifies whether the given data exists already on the jsdata array.
353
-     * Overriding data is not allowed.
354
-     *
355
-     * @param string $key Index for data.
356
-     * @return bool        If valid then return true.
357
-     * @throws InvalidArgumentException if data already exists.
358
-     */
359
-    protected function verifyDataNotExisting($key)
360
-    {
361
-        if (isset($this->jsdata[ $key ])) {
362
-            if (! $this->debug()) {
363
-                return false;
364
-            }
365
-            if (is_array($this->jsdata[ $key ])) {
366
-                throw new InvalidArgumentException(
367
-                    sprintf(
368
-                        __(
369
-                            'The value for %1$s already exists in the Registry::eejs object.
276
+						'event_espresso'
277
+					),
278
+					$key,
279
+					__METHOD__
280
+				)
281
+			);
282
+		}
283
+		if ( ! isset( $this->jsdata[ $key ] ) ) {
284
+			$this->jsdata[ $key ] = is_array($value) ? $value : [$value];
285
+		} else {
286
+			$this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
287
+		}
288
+	}
289
+
290
+
291
+	/**
292
+	 * Used to set content used by javascript for a template.
293
+	 * Note: Overrides of existing registered templates are not allowed.
294
+	 *
295
+	 * @param string $template_reference
296
+	 * @param string $template_content
297
+	 * @throws InvalidArgumentException
298
+	 */
299
+	public function addTemplate($template_reference, $template_content)
300
+	{
301
+		if (! isset($this->jsdata['templates'])) {
302
+			$this->jsdata['templates'] = array();
303
+		}
304
+		//no overrides allowed.
305
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
306
+			if (! $this->debug()) {
307
+				return;
308
+			}
309
+			throw new InvalidArgumentException(
310
+				sprintf(
311
+					__(
312
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
313
+						'event_espresso'
314
+					),
315
+					$template_reference
316
+				)
317
+			);
318
+		}
319
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
320
+	}
321
+
322
+
323
+	/**
324
+	 * Retrieve the template content already registered for the given reference.
325
+	 *
326
+	 * @param string $template_reference
327
+	 * @return string
328
+	 */
329
+	public function getTemplate($template_reference)
330
+	{
331
+		return isset($this->jsdata['templates'][ $template_reference ])
332
+			? $this->jsdata['templates'][ $template_reference ]
333
+			: '';
334
+	}
335
+
336
+
337
+	/**
338
+	 * Retrieve registered data.
339
+	 *
340
+	 * @param string $key Name of key to attach data to.
341
+	 * @return mixed                If there is no for the given key, then false is returned.
342
+	 */
343
+	public function getData($key)
344
+	{
345
+		return isset($this->jsdata[ $key ])
346
+			? $this->jsdata[ $key ]
347
+			: false;
348
+	}
349
+
350
+
351
+	/**
352
+	 * Verifies whether the given data exists already on the jsdata array.
353
+	 * Overriding data is not allowed.
354
+	 *
355
+	 * @param string $key Index for data.
356
+	 * @return bool        If valid then return true.
357
+	 * @throws InvalidArgumentException if data already exists.
358
+	 */
359
+	protected function verifyDataNotExisting($key)
360
+	{
361
+		if (isset($this->jsdata[ $key ])) {
362
+			if (! $this->debug()) {
363
+				return false;
364
+			}
365
+			if (is_array($this->jsdata[ $key ])) {
366
+				throw new InvalidArgumentException(
367
+					sprintf(
368
+						__(
369
+							'The value for %1$s already exists in the Registry::eejs object.
370 370
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
371 371
                             %2$s method to push your value to the array.',
372
-                            'event_espresso'
373
-                        ),
374
-                        $key,
375
-                        'pushData()'
376
-                    )
377
-                );
378
-            }
379
-            throw new InvalidArgumentException(
380
-                sprintf(
381
-                    __(
382
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
372
+							'event_espresso'
373
+						),
374
+						$key,
375
+						'pushData()'
376
+					)
377
+				);
378
+			}
379
+			throw new InvalidArgumentException(
380
+				sprintf(
381
+					__(
382
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
383 383
                         allowed.  Consider attaching your value to a different key',
384
-                        'event_espresso'
385
-                    ),
386
-                    $key
387
-                )
388
-            );
389
-        }
390
-        return true;
391
-    }
392
-
393
-
394
-    /**
395
-     * Get the actual asset path for asset manifests.
396
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
397
-     *
398
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
399
-     *                           asset file location.
400
-     * @param string $chunk_name
401
-     * @param string $asset_type
402
-     * @return string
403
-     * @since 4.9.59.p
404
-     */
405
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
406
-    {
407
-        $url = isset(
408
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
409
-            $this->manifest_data[ $namespace ]['url_base']
410
-        )
411
-            ? $this->manifest_data[ $namespace ]['url_base']
412
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
413
-            : $chunk_name;
414
-
415
-        return apply_filters(
416
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
417
-            $url,
418
-            $namespace,
419
-            $chunk_name,
420
-            $asset_type
421
-        );
422
-    }
423
-
424
-
425
-
426
-    /**
427
-     * Return the url to a js file for the given namespace and chunk name.
428
-     *
429
-     * @param string $namespace
430
-     * @param string $chunk_name
431
-     * @return string
432
-     */
433
-    public function getJsUrl($namespace, $chunk_name)
434
-    {
435
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
436
-    }
437
-
438
-
439
-    /**
440
-     * Return the url to a css file for the given namespace and chunk name.
441
-     *
442
-     * @param string $namespace
443
-     * @param string $chunk_name
444
-     * @return string
445
-     */
446
-    public function getCssUrl($namespace, $chunk_name)
447
-    {
448
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
449
-    }
450
-
451
-
452
-    /**
453
-     * @since 4.9.62.p
454
-     * @throws InvalidArgumentException
455
-     * @throws InvalidFilePathException
456
-     */
457
-    public function registerManifestFiles()
458
-    {
459
-        $manifest_files = $this->assets->getManifestFiles();
460
-        foreach ($manifest_files as $manifest_file) {
461
-            $this->registerManifestFile(
462
-                $manifest_file->assetNamespace(),
463
-                $manifest_file->urlBase(),
464
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
465
-            );
466
-        }
467
-    }
468
-
469
-
470
-    /**
471
-     * Used to register a js/css manifest file with the registered_manifest_files property.
472
-     *
473
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
474
-     * @param string $url_base      The url base for the manifest file location.
475
-     * @param string $manifest_file The absolute path to the manifest file.
476
-     * @throws InvalidArgumentException
477
-     * @throws InvalidFilePathException
478
-     * @since 4.9.59.p
479
-     */
480
-    public function registerManifestFile($namespace, $url_base, $manifest_file)
481
-    {
482
-        if (isset($this->manifest_data[ $namespace ])) {
483
-            if (! $this->debug()) {
484
-                return;
485
-            }
486
-            throw new InvalidArgumentException(
487
-                sprintf(
488
-                    esc_html__(
489
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
490
-                        'event_espresso'
491
-                    ),
492
-                    $namespace
493
-                )
494
-            );
495
-        }
496
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
497
-            if (is_admin()) {
498
-                EE_Error::add_error(
499
-                    sprintf(
500
-                        esc_html__(
501
-                            'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
502
-                            'event_espresso'
503
-                        ),
504
-                        'Event Espresso',
505
-                        $url_base,
506
-                        'plugins_url',
507
-                        'WP_PLUGIN_URL'
508
-                    ),
509
-                    __FILE__,
510
-                    __FUNCTION__,
511
-                    __LINE__
512
-                );
513
-            }
514
-            return;
515
-        }
516
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
517
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
518
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
519
-        }
520
-    }
521
-
522
-
523
-    /**
524
-     * Decodes json from the provided manifest file.
525
-     *
526
-     * @since 4.9.59.p
527
-     * @param string $manifest_file Path to manifest file.
528
-     * @return array
529
-     * @throws InvalidFilePathException
530
-     */
531
-    private function decodeManifestFile($manifest_file)
532
-    {
533
-        if (! file_exists($manifest_file)) {
534
-            throw new InvalidFilePathException($manifest_file);
535
-        }
536
-        return json_decode(file_get_contents($manifest_file), true);
537
-    }
538
-
539
-
540
-    /**
541
-     * This is used to set registered script handles that have data.
542
-     *
543
-     * @param string $script_handle
544
-     */
545
-    private function addRegisteredScriptHandlesWithData($script_handle)
546
-    {
547
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
548
-    }
549
-
550
-
551
-    /**i
384
+						'event_espresso'
385
+					),
386
+					$key
387
+				)
388
+			);
389
+		}
390
+		return true;
391
+	}
392
+
393
+
394
+	/**
395
+	 * Get the actual asset path for asset manifests.
396
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
397
+	 *
398
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
399
+	 *                           asset file location.
400
+	 * @param string $chunk_name
401
+	 * @param string $asset_type
402
+	 * @return string
403
+	 * @since 4.9.59.p
404
+	 */
405
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
406
+	{
407
+		$url = isset(
408
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
409
+			$this->manifest_data[ $namespace ]['url_base']
410
+		)
411
+			? $this->manifest_data[ $namespace ]['url_base']
412
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
413
+			: $chunk_name;
414
+
415
+		return apply_filters(
416
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
417
+			$url,
418
+			$namespace,
419
+			$chunk_name,
420
+			$asset_type
421
+		);
422
+	}
423
+
424
+
425
+
426
+	/**
427
+	 * Return the url to a js file for the given namespace and chunk name.
428
+	 *
429
+	 * @param string $namespace
430
+	 * @param string $chunk_name
431
+	 * @return string
432
+	 */
433
+	public function getJsUrl($namespace, $chunk_name)
434
+	{
435
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
436
+	}
437
+
438
+
439
+	/**
440
+	 * Return the url to a css file for the given namespace and chunk name.
441
+	 *
442
+	 * @param string $namespace
443
+	 * @param string $chunk_name
444
+	 * @return string
445
+	 */
446
+	public function getCssUrl($namespace, $chunk_name)
447
+	{
448
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
449
+	}
450
+
451
+
452
+	/**
453
+	 * @since 4.9.62.p
454
+	 * @throws InvalidArgumentException
455
+	 * @throws InvalidFilePathException
456
+	 */
457
+	public function registerManifestFiles()
458
+	{
459
+		$manifest_files = $this->assets->getManifestFiles();
460
+		foreach ($manifest_files as $manifest_file) {
461
+			$this->registerManifestFile(
462
+				$manifest_file->assetNamespace(),
463
+				$manifest_file->urlBase(),
464
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
465
+			);
466
+		}
467
+	}
468
+
469
+
470
+	/**
471
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
472
+	 *
473
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
474
+	 * @param string $url_base      The url base for the manifest file location.
475
+	 * @param string $manifest_file The absolute path to the manifest file.
476
+	 * @throws InvalidArgumentException
477
+	 * @throws InvalidFilePathException
478
+	 * @since 4.9.59.p
479
+	 */
480
+	public function registerManifestFile($namespace, $url_base, $manifest_file)
481
+	{
482
+		if (isset($this->manifest_data[ $namespace ])) {
483
+			if (! $this->debug()) {
484
+				return;
485
+			}
486
+			throw new InvalidArgumentException(
487
+				sprintf(
488
+					esc_html__(
489
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
490
+						'event_espresso'
491
+					),
492
+					$namespace
493
+				)
494
+			);
495
+		}
496
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
497
+			if (is_admin()) {
498
+				EE_Error::add_error(
499
+					sprintf(
500
+						esc_html__(
501
+							'The url given for %1$s assets is invalid.  The url provided was: "%2$s". This usually happens when another plugin or theme on a site is using the "%3$s" filter or has an invalid url set for the "%4$s" constant',
502
+							'event_espresso'
503
+						),
504
+						'Event Espresso',
505
+						$url_base,
506
+						'plugins_url',
507
+						'WP_PLUGIN_URL'
508
+					),
509
+					__FILE__,
510
+					__FUNCTION__,
511
+					__LINE__
512
+				);
513
+			}
514
+			return;
515
+		}
516
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
517
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
518
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
519
+		}
520
+	}
521
+
522
+
523
+	/**
524
+	 * Decodes json from the provided manifest file.
525
+	 *
526
+	 * @since 4.9.59.p
527
+	 * @param string $manifest_file Path to manifest file.
528
+	 * @return array
529
+	 * @throws InvalidFilePathException
530
+	 */
531
+	private function decodeManifestFile($manifest_file)
532
+	{
533
+		if (! file_exists($manifest_file)) {
534
+			throw new InvalidFilePathException($manifest_file);
535
+		}
536
+		return json_decode(file_get_contents($manifest_file), true);
537
+	}
538
+
539
+
540
+	/**
541
+	 * This is used to set registered script handles that have data.
542
+	 *
543
+	 * @param string $script_handle
544
+	 */
545
+	private function addRegisteredScriptHandlesWithData($script_handle)
546
+	{
547
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
548
+	}
549
+
550
+
551
+	/**i
552 552
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
553 553
      * Dependency stored in WP_Scripts if its set.
554 554
      */
555
-    private function removeAlreadyRegisteredDataForScriptHandles()
556
-    {
557
-        if (empty($this->script_handles_with_data)) {
558
-            return;
559
-        }
560
-        foreach ($this->script_handles_with_data as $script_handle) {
561
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
562
-        }
563
-    }
564
-
565
-
566
-    /**
567
-     * Removes any data dependency registered in WP_Scripts if its set.
568
-     *
569
-     * @param string $script_handle
570
-     */
571
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
572
-    {
573
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
574
-            global $wp_scripts;
575
-            $unset_handle = false;
576
-            if ($wp_scripts->get_data($script_handle, 'data')) {
577
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
578
-                $unset_handle = true;
579
-            }
580
-            //deal with inline_scripts
581
-            if ($wp_scripts->get_data($script_handle, 'before')) {
582
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
583
-                $unset_handle = true;
584
-            }
585
-            if ($wp_scripts->get_data($script_handle, 'after')) {
586
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
587
-            }
588
-            if ($unset_handle) {
589
-                unset($this->script_handles_with_data[ $script_handle ]);
590
-            }
591
-        }
592
-    }
593
-
594
-
595
-    /**
596
-     * register translations for a registered script
597
-     *
598
-     * @param string $handle
599
-     */
600
-    public function registerTranslation($handle)
601
-    {
602
-        $this->i18n_registry->registerScriptI18n($handle);
603
-    }
604
-
605
-
606
-    /**
607
-     * @since 4.9.63.p
608
-     * @return bool
609
-     */
610
-    private function debug()
611
-    {
612
-        return apply_filters(
613
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
614
-            defined('EE_DEBUG') && EE_DEBUG
615
-        );
616
-    }
555
+	private function removeAlreadyRegisteredDataForScriptHandles()
556
+	{
557
+		if (empty($this->script_handles_with_data)) {
558
+			return;
559
+		}
560
+		foreach ($this->script_handles_with_data as $script_handle) {
561
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
562
+		}
563
+	}
564
+
565
+
566
+	/**
567
+	 * Removes any data dependency registered in WP_Scripts if its set.
568
+	 *
569
+	 * @param string $script_handle
570
+	 */
571
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
572
+	{
573
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
574
+			global $wp_scripts;
575
+			$unset_handle = false;
576
+			if ($wp_scripts->get_data($script_handle, 'data')) {
577
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
578
+				$unset_handle = true;
579
+			}
580
+			//deal with inline_scripts
581
+			if ($wp_scripts->get_data($script_handle, 'before')) {
582
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
583
+				$unset_handle = true;
584
+			}
585
+			if ($wp_scripts->get_data($script_handle, 'after')) {
586
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
587
+			}
588
+			if ($unset_handle) {
589
+				unset($this->script_handles_with_data[ $script_handle ]);
590
+			}
591
+		}
592
+	}
593
+
594
+
595
+	/**
596
+	 * register translations for a registered script
597
+	 *
598
+	 * @param string $handle
599
+	 */
600
+	public function registerTranslation($handle)
601
+	{
602
+		$this->i18n_registry->registerScriptI18n($handle);
603
+	}
604
+
605
+
606
+	/**
607
+	 * @since 4.9.63.p
608
+	 * @return bool
609
+	 */
610
+	private function debug()
611
+	{
612
+		return apply_filters(
613
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
614
+			defined('EE_DEBUG') && EE_DEBUG
615
+		);
616
+	}
617 617
 }
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
                 $script->version(),
148 148
                 $script->loadInFooter()
149 149
             );
150
-            if (! $registered && $this->debug()) {
150
+            if ( ! $registered && $this->debug()) {
151 151
                 throw new AssetRegistrationException($script->handle());
152 152
             }
153 153
             $script->setRegistered($registered);
@@ -207,7 +207,7 @@  discard block
 block discarded – undo
207 207
         $this->removeAlreadyRegisteredDataForScriptHandles();
208 208
         wp_add_inline_script(
209 209
             'eejs-core',
210
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
210
+            'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)),
211 211
             'before'
212 212
         );
213 213
         $scripts = $this->assets->getJavascriptAssetsWithData();
@@ -237,7 +237,7 @@  discard block
 block discarded – undo
237 237
     public function addData($key, $value)
238 238
     {
239 239
         if ($this->verifyDataNotExisting($key)) {
240
-            $this->jsdata[ $key ] = $value;
240
+            $this->jsdata[$key] = $value;
241 241
         }
242 242
     }
243 243
 
@@ -262,10 +262,10 @@  discard block
 block discarded – undo
262 262
      */
263 263
     public function pushData($key, $value)
264 264
     {
265
-        if (isset($this->jsdata[ $key ])
266
-            && ! is_array($this->jsdata[ $key ])
265
+        if (isset($this->jsdata[$key])
266
+            && ! is_array($this->jsdata[$key])
267 267
         ) {
268
-            if (! $this->debug()) {
268
+            if ( ! $this->debug()) {
269 269
                 return;
270 270
             }
271 271
             throw new InvalidArgumentException(
@@ -280,10 +280,10 @@  discard block
 block discarded – undo
280 280
                 )
281 281
             );
282 282
         }
283
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
284
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
283
+        if ( ! isset($this->jsdata[$key])) {
284
+            $this->jsdata[$key] = is_array($value) ? $value : [$value];
285 285
         } else {
286
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
286
+            $this->jsdata[$key] = array_merge($this->jsdata[$key], (array) $value);
287 287
         }
288 288
     }
289 289
 
@@ -298,12 +298,12 @@  discard block
 block discarded – undo
298 298
      */
299 299
     public function addTemplate($template_reference, $template_content)
300 300
     {
301
-        if (! isset($this->jsdata['templates'])) {
301
+        if ( ! isset($this->jsdata['templates'])) {
302 302
             $this->jsdata['templates'] = array();
303 303
         }
304 304
         //no overrides allowed.
305
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
306
-            if (! $this->debug()) {
305
+        if (isset($this->jsdata['templates'][$template_reference])) {
306
+            if ( ! $this->debug()) {
307 307
                 return;
308 308
             }
309 309
             throw new InvalidArgumentException(
@@ -316,7 +316,7 @@  discard block
 block discarded – undo
316 316
                 )
317 317
             );
318 318
         }
319
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
319
+        $this->jsdata['templates'][$template_reference] = $template_content;
320 320
     }
321 321
 
322 322
 
@@ -328,8 +328,8 @@  discard block
 block discarded – undo
328 328
      */
329 329
     public function getTemplate($template_reference)
330 330
     {
331
-        return isset($this->jsdata['templates'][ $template_reference ])
332
-            ? $this->jsdata['templates'][ $template_reference ]
331
+        return isset($this->jsdata['templates'][$template_reference])
332
+            ? $this->jsdata['templates'][$template_reference]
333 333
             : '';
334 334
     }
335 335
 
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
      */
343 343
     public function getData($key)
344 344
     {
345
-        return isset($this->jsdata[ $key ])
346
-            ? $this->jsdata[ $key ]
345
+        return isset($this->jsdata[$key])
346
+            ? $this->jsdata[$key]
347 347
             : false;
348 348
     }
349 349
 
@@ -358,11 +358,11 @@  discard block
 block discarded – undo
358 358
      */
359 359
     protected function verifyDataNotExisting($key)
360 360
     {
361
-        if (isset($this->jsdata[ $key ])) {
362
-            if (! $this->debug()) {
361
+        if (isset($this->jsdata[$key])) {
362
+            if ( ! $this->debug()) {
363 363
                 return false;
364 364
             }
365
-            if (is_array($this->jsdata[ $key ])) {
365
+            if (is_array($this->jsdata[$key])) {
366 366
                 throw new InvalidArgumentException(
367 367
                     sprintf(
368 368
                         __(
@@ -405,11 +405,11 @@  discard block
 block discarded – undo
405 405
     public function getAssetUrl($namespace, $chunk_name, $asset_type)
406 406
     {
407 407
         $url = isset(
408
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
409
-            $this->manifest_data[ $namespace ]['url_base']
408
+            $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type],
409
+            $this->manifest_data[$namespace]['url_base']
410 410
         )
411
-            ? $this->manifest_data[ $namespace ]['url_base']
412
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
411
+            ? $this->manifest_data[$namespace]['url_base']
412
+              . $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type]
413 413
             : $chunk_name;
414 414
 
415 415
         return apply_filters(
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
             $this->registerManifestFile(
462 462
                 $manifest_file->assetNamespace(),
463 463
                 $manifest_file->urlBase(),
464
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST
464
+                $manifest_file->filepath().Registry::FILE_NAME_BUILD_MANIFEST
465 465
             );
466 466
         }
467 467
     }
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
      */
480 480
     public function registerManifestFile($namespace, $url_base, $manifest_file)
481 481
     {
482
-        if (isset($this->manifest_data[ $namespace ])) {
483
-            if (! $this->debug()) {
482
+        if (isset($this->manifest_data[$namespace])) {
483
+            if ( ! $this->debug()) {
484 484
                 return;
485 485
             }
486 486
             throw new InvalidArgumentException(
@@ -513,9 +513,9 @@  discard block
 block discarded – undo
513 513
             }
514 514
             return;
515 515
         }
516
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
517
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
518
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
516
+        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
517
+        if ( ! isset($this->manifest_data[$namespace]['url_base'])) {
518
+            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
519 519
         }
520 520
     }
521 521
 
@@ -530,7 +530,7 @@  discard block
 block discarded – undo
530 530
      */
531 531
     private function decodeManifestFile($manifest_file)
532 532
     {
533
-        if (! file_exists($manifest_file)) {
533
+        if ( ! file_exists($manifest_file)) {
534 534
             throw new InvalidFilePathException($manifest_file);
535 535
         }
536 536
         return json_decode(file_get_contents($manifest_file), true);
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
      */
545 545
     private function addRegisteredScriptHandlesWithData($script_handle)
546 546
     {
547
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
547
+        $this->script_handles_with_data[$script_handle] = $script_handle;
548 548
     }
549 549
 
550 550
 
@@ -570,23 +570,23 @@  discard block
 block discarded – undo
570 570
      */
571 571
     private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
572 572
     {
573
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
573
+        if (isset($this->script_handles_with_data[$script_handle])) {
574 574
             global $wp_scripts;
575 575
             $unset_handle = false;
576 576
             if ($wp_scripts->get_data($script_handle, 'data')) {
577
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
577
+                unset($wp_scripts->registered[$script_handle]->extra['data']);
578 578
                 $unset_handle = true;
579 579
             }
580 580
             //deal with inline_scripts
581 581
             if ($wp_scripts->get_data($script_handle, 'before')) {
582
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
582
+                unset($wp_scripts->registered[$script_handle]->extra['before']);
583 583
                 $unset_handle = true;
584 584
             }
585 585
             if ($wp_scripts->get_data($script_handle, 'after')) {
586
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
586
+                unset($wp_scripts->registered[$script_handle]->extra['after']);
587 587
             }
588 588
             if ($unset_handle) {
589
-                unset($this->script_handles_with_data[ $script_handle ]);
589
+                unset($this->script_handles_with_data[$script_handle]);
590 590
             }
591 591
         }
592 592
     }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 1 patch
Indentation   +544 added lines, -544 removed lines patch added patch discarded remove patch
@@ -32,570 +32,570 @@
 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
-    // EE JS assets handles
62
-    const JS_HANDLE_MANIFEST = 'ee-manifest';
61
+	// EE JS assets handles
62
+	const JS_HANDLE_MANIFEST = 'ee-manifest';
63 63
 
64
-    const JS_HANDLE_JS_CORE = 'eejs-core';
64
+	const JS_HANDLE_JS_CORE = 'eejs-core';
65 65
 
66
-    const JS_HANDLE_VENDOR = 'eventespresso-vendor';
66
+	const JS_HANDLE_VENDOR = 'eventespresso-vendor';
67 67
 
68
-    const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
68
+	const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
69 69
 
70
-    const JS_HANDLE_HELPERS = 'eventespresso-helpers';
70
+	const JS_HANDLE_HELPERS = 'eventespresso-helpers';
71 71
 
72
-    const JS_HANDLE_MODEL = 'eventespresso-model';
72
+	const JS_HANDLE_MODEL = 'eventespresso-model';
73 73
 
74
-    const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
74
+	const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
75 75
 
76
-    const JS_HANDLE_HOCS = 'eventespresso-hocs';
76
+	const JS_HANDLE_HOCS = 'eventespresso-hocs';
77 77
 
78
-    const JS_HANDLE_COMPONENTS = 'eventespresso-components';
78
+	const JS_HANDLE_COMPONENTS = 'eventespresso-components';
79 79
 
80
-    const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs';
80
+	const JS_HANDLE_EDITOR_HOCS = 'eventespresso-editor-hocs';
81 81
 
82
-    const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
82
+	const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
83 83
 
84
-    const JS_HANDLE_CORE = 'espresso_core';
84
+	const JS_HANDLE_CORE = 'espresso_core';
85 85
 
86
-    const JS_HANDLE_I18N = 'eei18n';
86
+	const JS_HANDLE_I18N = 'eei18n';
87 87
 
88
-    const JS_HANDLE_ACCOUNTING = 'ee-accounting';
88
+	const JS_HANDLE_ACCOUNTING = 'ee-accounting';
89 89
 
90
-    const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
91
-
92
-    // EE CSS assets handles
93
-    const CSS_HANDLE_DEFAULT = 'espresso_default';
94
-
95
-    const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
96
-
97
-    const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
98
-
99
-    const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
100
-
101
-    /**
102
-     * @var EE_Currency_Config $currency_config
103
-     */
104
-    protected $currency_config;
105
-
106
-    /**
107
-     * @var EE_Template_Config $template_config
108
-     */
109
-    protected $template_config;
110
-
111
-
112
-    /**
113
-     * CoreAssetRegister constructor.
114
-     *
115
-     * @param AssetCollection    $assets
116
-     * @param EE_Currency_Config $currency_config
117
-     * @param EE_Template_Config $template_config
118
-     * @param DomainInterface    $domain
119
-     * @param Registry           $registry
120
-     */
121
-    public function __construct(
122
-        AssetCollection $assets,
123
-        EE_Currency_Config $currency_config,
124
-        EE_Template_Config $template_config,
125
-        DomainInterface $domain,
126
-        Registry $registry
127
-    ) {
128
-        $this->currency_config = $currency_config;
129
-        $this->template_config = $template_config;
130
-        parent::__construct($domain, $assets, $registry);
131
-    }
132
-
133
-
134
-    /**
135
-     * @since 4.9.62.p
136
-     * @throws DomainException
137
-     * @throws DuplicateCollectionIdentifierException
138
-     * @throws InvalidArgumentException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidEntityException
141
-     * @throws InvalidInterfaceException
142
-     */
143
-    public function addAssets()
144
-    {
145
-        $this->addJavascriptFiles();
146
-        $this->addStylesheetFiles();
147
-    }
148
-
149
-
150
-    /**
151
-     * @since 4.9.62.p
152
-     * @throws DomainException
153
-     * @throws DuplicateCollectionIdentifierException
154
-     * @throws InvalidArgumentException
155
-     * @throws InvalidDataTypeException
156
-     * @throws InvalidEntityException
157
-     * @throws InvalidInterfaceException
158
-     */
159
-    public function addJavascriptFiles()
160
-    {
161
-        $this->loadCoreJs();
162
-        $this->loadJqueryValidate();
163
-        $this->loadAccountingJs();
164
-        add_action(
165
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
166
-            array($this, 'loadQtipJs')
167
-        );
168
-        $this->registerAdminAssets();
169
-    }
170
-
171
-
172
-    /**
173
-     * @since 4.9.62.p
174
-     * @throws DuplicateCollectionIdentifierException
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidEntityException
177
-     */
178
-    public function addStylesheetFiles()
179
-    {
180
-        $this->loadCoreCss();
181
-    }
182
-
183
-
184
-    /**
185
-     * core default javascript
186
-     *
187
-     * @since 4.9.62.p
188
-     * @throws DomainException
189
-     * @throws DuplicateCollectionIdentifierException
190
-     * @throws InvalidArgumentException
191
-     * @throws InvalidDataTypeException
192
-     * @throws InvalidEntityException
193
-     * @throws InvalidInterfaceException
194
-     */
195
-    private function loadCoreJs()
196
-    {
197
-        // conditionally load third-party libraries that WP core MIGHT have.
198
-        $this->registerWpAssets();
199
-
200
-        $this->addJavascript(
201
-            CoreAssetManager::JS_HANDLE_MANIFEST,
202
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
203
-        );
204
-
205
-        $this->addJavascript(
206
-            CoreAssetManager::JS_HANDLE_JS_CORE,
207
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
208
-            array(CoreAssetManager::JS_HANDLE_MANIFEST)
209
-        )
210
-        ->setHasInlineData();
211
-
212
-        $this->addJavascript(
213
-            CoreAssetManager::JS_HANDLE_VENDOR,
214
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
215
-            array(
216
-                CoreAssetManager::JS_HANDLE_JS_CORE,
217
-                CoreAssetManager::JS_HANDLE_REACT,
218
-                CoreAssetManager::JS_HANDLE_REACT_DOM,
219
-                CoreAssetManager::JS_HANDLE_LODASH,
220
-            )
221
-        );
222
-
223
-        $this->addJavascript(
224
-            CoreAssetManager::JS_HANDLE_VALIDATORS,
225
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'validators')
226
-        )->setRequiresTranslation();
227
-
228
-        $this->addJavascript(
229
-            CoreAssetManager::JS_HANDLE_HELPERS,
230
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers'),
231
-            array(
232
-                CoreAssetManager::JS_HANDLE_VALIDATORS
233
-            )
234
-        )->setRequiresTranslation();
235
-
236
-        $this->addJavascript(
237
-            CoreAssetManager::JS_HANDLE_MODEL,
238
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
239
-            array(
240
-                CoreAssetManager::JS_HANDLE_HELPERS,
241
-                CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
242
-            )
243
-        )->setRequiresTranslation();
244
-
245
-        $this->addJavascript(
246
-            CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
247
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
248
-            array(
249
-                CoreAssetManager::JS_HANDLE_VALIDATORS,
250
-                CoreAssetManager::JS_HANDLE_HELPERS,
251
-            )
252
-        )->setRequiresTranslation();
253
-
254
-        $this->addJavascript(
255
-            CoreAssetManager::JS_HANDLE_DATA_STORES,
256
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
257
-            array(
258
-                CoreAssetManager::JS_HANDLE_VENDOR,
259
-                'wp-data',
260
-                'wp-api-fetch',
261
-                CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
262
-                CoreAssetManager::JS_HANDLE_MODEL,
263
-            )
264
-        )
265
-             ->setRequiresTranslation()
266
-             ->setInlineDataCallback(
267
-                 function() {
268
-                     wp_add_inline_script(
269
-                         CoreAssetManager::JS_HANDLE_DATA_STORES,
270
-                         is_admin()
271
-                             ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
272
-                             : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
273
-                     );
274
-                 }
275
-             );
276
-
277
-        $this->addJavascript(
278
-            CoreAssetManager::JS_HANDLE_HOCS,
279
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'hocs'),
280
-            array(
281
-                CoreAssetManager::JS_HANDLE_DATA_STORES,
282
-                CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
283
-                'wp-components',
284
-            )
285
-        )->setRequiresTranslation();
286
-
287
-        $this->addJavascript(
288
-            CoreAssetManager::JS_HANDLE_COMPONENTS,
289
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
290
-            array(
291
-                CoreAssetManager::JS_HANDLE_DATA_STORES,
292
-                CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
293
-                'wp-components',
294
-            )
295
-        )
296
-        ->setRequiresTranslation();
297
-
298
-        $this->addJavascript(
299
-            CoreAssetManager::JS_HANDLE_EDITOR_HOCS,
300
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'editor-hocs'),
301
-            array(
302
-                CoreAssetManager::JS_HANDLE_COMPONENTS
303
-            )
304
-        )->setRequiresTranslation();
305
-
306
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
307
-        $this->registry->addData(
308
-            'paths',
309
-            array(
310
-                'base_rest_route' => rest_url(),
311
-                'rest_route' => rest_url('ee/v4.8.36/'),
312
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
313
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
314
-                'site_url' => site_url('/'),
315
-                'admin_url' => admin_url('/'),
316
-            )
317
-        );
318
-        // Event Espresso brand name
319
-        $this->registry->addData('brandName', Domain::brandName());
320
-        /** site formatting values **/
321
-        $this->registry->addData(
322
-            'site_formats',
323
-            array(
324
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
325
-            )
326
-        );
327
-        /** currency data **/
328
-        $this->registry->addData(
329
-            'currency_config',
330
-            $this->getCurrencySettings()
331
-        );
332
-        /** site timezone */
333
-        $this->registry->addData(
334
-            'default_timezone',
335
-            array(
336
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
337
-                'string' => get_option('timezone_string'),
338
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
339
-            )
340
-        );
341
-        /** site locale (user locale if user logged in) */
342
-        $this->registry->addData(
343
-            'locale',
344
-            array(
345
-                'user' => get_user_locale(),
346
-                'site' => get_locale()
347
-            )
348
-        );
349
-
350
-        $this->addJavascript(
351
-            CoreAssetManager::JS_HANDLE_CORE,
352
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
353
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
354
-        )
355
-        ->setInlineDataCallback(
356
-            function () {
357
-                wp_localize_script(
358
-                    CoreAssetManager::JS_HANDLE_CORE,
359
-                    CoreAssetManager::JS_HANDLE_I18N,
360
-                    EE_Registry::$i18n_js_strings
361
-                );
362
-            }
363
-        );
364
-    }
365
-
366
-
367
-    /**
368
-     * Registers vendor files that are bundled with a later version WP but might not be for the current version of
369
-     * WordPress in the running environment.
370
-     *
371
-     * @throws DuplicateCollectionIdentifierException
372
-     * @throws InvalidDataTypeException
373
-     * @throws InvalidEntityException
374
-     * @throws DomainException
375
-     * @since 4.9.71.p
376
-     */
377
-    private function registerWpAssets()
378
-    {
379
-        global $wp_version;
380
-        if (version_compare($wp_version, '5.0.beta', '>=')) {
381
-            return;
382
-        }
383
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
384
-            ->setVersion('16.6.0');
385
-        $this->addVendorJavascript(
386
-            CoreAssetManager::JS_HANDLE_REACT_DOM,
387
-            array(CoreAssetManager::JS_HANDLE_REACT)
388
-        )->setVersion('16.6.0');
389
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
390
-            ->setInlineDataCallback(
391
-                function() {
392
-                    wp_add_inline_script(
393
-                        CoreAssetManager::JS_HANDLE_LODASH,
394
-                        'window.lodash = _.noConflict();'
395
-                    );
396
-                }
397
-            )
398
-            ->setVersion('4.17.11');
399
-    }
400
-
401
-
402
-    /**
403
-     * Returns configuration data for the accounting-js library.
404
-     * @since 4.9.71.p
405
-     * @return array
406
-     */
407
-    private function getAccountingSettings() {
408
-        return array(
409
-            'currency' => array(
410
-                'symbol'    => $this->currency_config->sign,
411
-                'format'    => array(
412
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
413
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
414
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
415
-                ),
416
-                'decimal'   => $this->currency_config->dec_mrk,
417
-                'thousand'  => $this->currency_config->thsnds,
418
-                'precision' => $this->currency_config->dec_plc,
419
-            ),
420
-            'number'   => array(
421
-                'precision' => $this->currency_config->dec_plc,
422
-                'thousand'  => $this->currency_config->thsnds,
423
-                'decimal'   => $this->currency_config->dec_mrk,
424
-            ),
425
-        );
426
-    }
427
-
428
-
429
-    /**
430
-     * Returns configuration data for the js Currency VO.
431
-     * @since 4.9.71.p
432
-     * @return array
433
-     */
434
-    private function getCurrencySettings()
435
-    {
436
-        return array(
437
-            'code' => $this->currency_config->code,
438
-            'singularLabel' => $this->currency_config->name,
439
-            'pluralLabel' => $this->currency_config->plural,
440
-            'sign' => $this->currency_config->sign,
441
-            'signB4' => $this->currency_config->sign_b4,
442
-            'decimalPlaces' => $this->currency_config->dec_plc,
443
-            'decimalMark' => $this->currency_config->dec_mrk,
444
-            'thousandsSeparator' => $this->currency_config->thsnds,
445
-        );
446
-    }
447
-
448
-
449
-    /**
450
-     * @since 4.9.62.p
451
-     * @throws DuplicateCollectionIdentifierException
452
-     * @throws InvalidDataTypeException
453
-     * @throws InvalidEntityException
454
-     */
455
-    private function loadCoreCss()
456
-    {
457
-        if ($this->template_config->enable_default_style && ! is_admin()) {
458
-            $this->addStylesheet(
459
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
460
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
461
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
462
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
463
-                array('dashicons')
464
-            );
465
-            //Load custom style sheet if available
466
-            if ($this->template_config->custom_style_sheet !== null) {
467
-                $this->addStylesheet(
468
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
469
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
470
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
471
-                );
472
-            }
473
-        }
474
-        $this->addStylesheet(
475
-            CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT,
476
-            $this->registry->getCssUrl(
477
-                $this->domain->assetNamespace(),
478
-                'core-default-theme'
479
-            ),
480
-            ['dashicons']
481
-        );
482
-        $this->addStylesheet(
483
-            CoreAssetManager::CSS_HANDLE_COMPONENTS,
484
-            $this->registry->getCssUrl(
485
-                $this->domain->assetNamespace(),
486
-                'components'
487
-            ),
488
-            [CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT]
489
-        );
490
-    }
491
-
492
-
493
-    /**
494
-     * jQuery Validate for form validation
495
-     *
496
-     * @since 4.9.62.p
497
-     * @throws DomainException
498
-     * @throws DuplicateCollectionIdentifierException
499
-     * @throws InvalidDataTypeException
500
-     * @throws InvalidEntityException
501
-     */
502
-    private function loadJqueryValidate()
503
-    {
504
-        $this->addJavascript(
505
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
506
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
507
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
508
-        )
509
-        ->setVersion('1.15.0');
510
-
511
-        $this->addJavascript(
512
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
513
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
514
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
515
-        )
516
-        ->setVersion('1.15.0');
517
-    }
518
-
519
-
520
-    /**
521
-     * accounting.js for performing client-side calculations
522
-     *
523
-     * @since 4.9.62.p
524
-     * @throws DomainException
525
-     * @throws DuplicateCollectionIdentifierException
526
-     * @throws InvalidDataTypeException
527
-     * @throws InvalidEntityException
528
-     */
529
-    private function loadAccountingJs()
530
-    {
531
-        //accounting.js library
532
-        // @link http://josscrowcroft.github.io/accounting.js/
533
-        $this->addJavascript(
534
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
535
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
536
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
537
-        )
538
-        ->setVersion('0.3.2');
539
-
540
-        $this->addJavascript(
541
-            CoreAssetManager::JS_HANDLE_ACCOUNTING,
542
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
543
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
544
-        )
545
-        ->setInlineDataCallback(
546
-            function () {
547
-                 wp_localize_script(
548
-                     CoreAssetManager::JS_HANDLE_ACCOUNTING,
549
-                     'EE_ACCOUNTING_CFG',
550
-                     $this->getAccountingSettings()
551
-                 );
552
-            }
553
-        )
554
-        ->setVersion();
555
-    }
556
-
557
-
558
-    /**
559
-     * registers assets for cleaning your ears
560
-     *
561
-     * @param JavascriptAsset $script
562
-     */
563
-    public function loadQtipJs(JavascriptAsset $script)
564
-    {
565
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
566
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
567
-        if (
568
-            $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
569
-            && apply_filters('FHEE_load_qtip', false)
570
-        ) {
571
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
572
-        }
573
-    }
574
-
575
-
576
-    /**
577
-     * assets that are used in the WordPress admin
578
-     *
579
-     * @since 4.9.62.p
580
-     * @throws DuplicateCollectionIdentifierException
581
-     * @throws InvalidDataTypeException
582
-     * @throws InvalidEntityException
583
-     */
584
-    private function registerAdminAssets()
585
-    {
586
-        $this->addJavascript(
587
-            CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
588
-            $this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
589
-            array(
590
-                CoreAssetManager::JS_HANDLE_JQUERY,
591
-                CoreAssetManager::JS_HANDLE_VENDOR,
592
-            )
593
-        )
594
-        ->setRequiresTranslation();
595
-
596
-        $this->addStylesheet(
597
-            CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
598
-            $this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
599
-        );
600
-    }
90
+	const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
91
+
92
+	// EE CSS assets handles
93
+	const CSS_HANDLE_DEFAULT = 'espresso_default';
94
+
95
+	const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
96
+
97
+	const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
98
+
99
+	const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
100
+
101
+	/**
102
+	 * @var EE_Currency_Config $currency_config
103
+	 */
104
+	protected $currency_config;
105
+
106
+	/**
107
+	 * @var EE_Template_Config $template_config
108
+	 */
109
+	protected $template_config;
110
+
111
+
112
+	/**
113
+	 * CoreAssetRegister constructor.
114
+	 *
115
+	 * @param AssetCollection    $assets
116
+	 * @param EE_Currency_Config $currency_config
117
+	 * @param EE_Template_Config $template_config
118
+	 * @param DomainInterface    $domain
119
+	 * @param Registry           $registry
120
+	 */
121
+	public function __construct(
122
+		AssetCollection $assets,
123
+		EE_Currency_Config $currency_config,
124
+		EE_Template_Config $template_config,
125
+		DomainInterface $domain,
126
+		Registry $registry
127
+	) {
128
+		$this->currency_config = $currency_config;
129
+		$this->template_config = $template_config;
130
+		parent::__construct($domain, $assets, $registry);
131
+	}
132
+
133
+
134
+	/**
135
+	 * @since 4.9.62.p
136
+	 * @throws DomainException
137
+	 * @throws DuplicateCollectionIdentifierException
138
+	 * @throws InvalidArgumentException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidEntityException
141
+	 * @throws InvalidInterfaceException
142
+	 */
143
+	public function addAssets()
144
+	{
145
+		$this->addJavascriptFiles();
146
+		$this->addStylesheetFiles();
147
+	}
148
+
149
+
150
+	/**
151
+	 * @since 4.9.62.p
152
+	 * @throws DomainException
153
+	 * @throws DuplicateCollectionIdentifierException
154
+	 * @throws InvalidArgumentException
155
+	 * @throws InvalidDataTypeException
156
+	 * @throws InvalidEntityException
157
+	 * @throws InvalidInterfaceException
158
+	 */
159
+	public function addJavascriptFiles()
160
+	{
161
+		$this->loadCoreJs();
162
+		$this->loadJqueryValidate();
163
+		$this->loadAccountingJs();
164
+		add_action(
165
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
166
+			array($this, 'loadQtipJs')
167
+		);
168
+		$this->registerAdminAssets();
169
+	}
170
+
171
+
172
+	/**
173
+	 * @since 4.9.62.p
174
+	 * @throws DuplicateCollectionIdentifierException
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidEntityException
177
+	 */
178
+	public function addStylesheetFiles()
179
+	{
180
+		$this->loadCoreCss();
181
+	}
182
+
183
+
184
+	/**
185
+	 * core default javascript
186
+	 *
187
+	 * @since 4.9.62.p
188
+	 * @throws DomainException
189
+	 * @throws DuplicateCollectionIdentifierException
190
+	 * @throws InvalidArgumentException
191
+	 * @throws InvalidDataTypeException
192
+	 * @throws InvalidEntityException
193
+	 * @throws InvalidInterfaceException
194
+	 */
195
+	private function loadCoreJs()
196
+	{
197
+		// conditionally load third-party libraries that WP core MIGHT have.
198
+		$this->registerWpAssets();
199
+
200
+		$this->addJavascript(
201
+			CoreAssetManager::JS_HANDLE_MANIFEST,
202
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'manifest')
203
+		);
204
+
205
+		$this->addJavascript(
206
+			CoreAssetManager::JS_HANDLE_JS_CORE,
207
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'eejs'),
208
+			array(CoreAssetManager::JS_HANDLE_MANIFEST)
209
+		)
210
+		->setHasInlineData();
211
+
212
+		$this->addJavascript(
213
+			CoreAssetManager::JS_HANDLE_VENDOR,
214
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'vendor'),
215
+			array(
216
+				CoreAssetManager::JS_HANDLE_JS_CORE,
217
+				CoreAssetManager::JS_HANDLE_REACT,
218
+				CoreAssetManager::JS_HANDLE_REACT_DOM,
219
+				CoreAssetManager::JS_HANDLE_LODASH,
220
+			)
221
+		);
222
+
223
+		$this->addJavascript(
224
+			CoreAssetManager::JS_HANDLE_VALIDATORS,
225
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'validators')
226
+		)->setRequiresTranslation();
227
+
228
+		$this->addJavascript(
229
+			CoreAssetManager::JS_HANDLE_HELPERS,
230
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'helpers'),
231
+			array(
232
+				CoreAssetManager::JS_HANDLE_VALIDATORS
233
+			)
234
+		)->setRequiresTranslation();
235
+
236
+		$this->addJavascript(
237
+			CoreAssetManager::JS_HANDLE_MODEL,
238
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'model'),
239
+			array(
240
+				CoreAssetManager::JS_HANDLE_HELPERS,
241
+				CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
242
+			)
243
+		)->setRequiresTranslation();
244
+
245
+		$this->addJavascript(
246
+			CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
247
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'valueObjects'),
248
+			array(
249
+				CoreAssetManager::JS_HANDLE_VALIDATORS,
250
+				CoreAssetManager::JS_HANDLE_HELPERS,
251
+			)
252
+		)->setRequiresTranslation();
253
+
254
+		$this->addJavascript(
255
+			CoreAssetManager::JS_HANDLE_DATA_STORES,
256
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'data-stores'),
257
+			array(
258
+				CoreAssetManager::JS_HANDLE_VENDOR,
259
+				'wp-data',
260
+				'wp-api-fetch',
261
+				CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
262
+				CoreAssetManager::JS_HANDLE_MODEL,
263
+			)
264
+		)
265
+			 ->setRequiresTranslation()
266
+			 ->setInlineDataCallback(
267
+				 function() {
268
+					 wp_add_inline_script(
269
+						 CoreAssetManager::JS_HANDLE_DATA_STORES,
270
+						 is_admin()
271
+							 ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
272
+							 : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
273
+					 );
274
+				 }
275
+			 );
276
+
277
+		$this->addJavascript(
278
+			CoreAssetManager::JS_HANDLE_HOCS,
279
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'hocs'),
280
+			array(
281
+				CoreAssetManager::JS_HANDLE_DATA_STORES,
282
+				CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
283
+				'wp-components',
284
+			)
285
+		)->setRequiresTranslation();
286
+
287
+		$this->addJavascript(
288
+			CoreAssetManager::JS_HANDLE_COMPONENTS,
289
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'components'),
290
+			array(
291
+				CoreAssetManager::JS_HANDLE_DATA_STORES,
292
+				CoreAssetManager::JS_HANDLE_VALUE_OBJECTS,
293
+				'wp-components',
294
+			)
295
+		)
296
+		->setRequiresTranslation();
297
+
298
+		$this->addJavascript(
299
+			CoreAssetManager::JS_HANDLE_EDITOR_HOCS,
300
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'editor-hocs'),
301
+			array(
302
+				CoreAssetManager::JS_HANDLE_COMPONENTS
303
+			)
304
+		)->setRequiresTranslation();
305
+
306
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
307
+		$this->registry->addData(
308
+			'paths',
309
+			array(
310
+				'base_rest_route' => rest_url(),
311
+				'rest_route' => rest_url('ee/v4.8.36/'),
312
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
313
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
314
+				'site_url' => site_url('/'),
315
+				'admin_url' => admin_url('/'),
316
+			)
317
+		);
318
+		// Event Espresso brand name
319
+		$this->registry->addData('brandName', Domain::brandName());
320
+		/** site formatting values **/
321
+		$this->registry->addData(
322
+			'site_formats',
323
+			array(
324
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
325
+			)
326
+		);
327
+		/** currency data **/
328
+		$this->registry->addData(
329
+			'currency_config',
330
+			$this->getCurrencySettings()
331
+		);
332
+		/** site timezone */
333
+		$this->registry->addData(
334
+			'default_timezone',
335
+			array(
336
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
337
+				'string' => get_option('timezone_string'),
338
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
339
+			)
340
+		);
341
+		/** site locale (user locale if user logged in) */
342
+		$this->registry->addData(
343
+			'locale',
344
+			array(
345
+				'user' => get_user_locale(),
346
+				'site' => get_locale()
347
+			)
348
+		);
349
+
350
+		$this->addJavascript(
351
+			CoreAssetManager::JS_HANDLE_CORE,
352
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
353
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
354
+		)
355
+		->setInlineDataCallback(
356
+			function () {
357
+				wp_localize_script(
358
+					CoreAssetManager::JS_HANDLE_CORE,
359
+					CoreAssetManager::JS_HANDLE_I18N,
360
+					EE_Registry::$i18n_js_strings
361
+				);
362
+			}
363
+		);
364
+	}
365
+
366
+
367
+	/**
368
+	 * Registers vendor files that are bundled with a later version WP but might not be for the current version of
369
+	 * WordPress in the running environment.
370
+	 *
371
+	 * @throws DuplicateCollectionIdentifierException
372
+	 * @throws InvalidDataTypeException
373
+	 * @throws InvalidEntityException
374
+	 * @throws DomainException
375
+	 * @since 4.9.71.p
376
+	 */
377
+	private function registerWpAssets()
378
+	{
379
+		global $wp_version;
380
+		if (version_compare($wp_version, '5.0.beta', '>=')) {
381
+			return;
382
+		}
383
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT)
384
+			->setVersion('16.6.0');
385
+		$this->addVendorJavascript(
386
+			CoreAssetManager::JS_HANDLE_REACT_DOM,
387
+			array(CoreAssetManager::JS_HANDLE_REACT)
388
+		)->setVersion('16.6.0');
389
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH)
390
+			->setInlineDataCallback(
391
+				function() {
392
+					wp_add_inline_script(
393
+						CoreAssetManager::JS_HANDLE_LODASH,
394
+						'window.lodash = _.noConflict();'
395
+					);
396
+				}
397
+			)
398
+			->setVersion('4.17.11');
399
+	}
400
+
401
+
402
+	/**
403
+	 * Returns configuration data for the accounting-js library.
404
+	 * @since 4.9.71.p
405
+	 * @return array
406
+	 */
407
+	private function getAccountingSettings() {
408
+		return array(
409
+			'currency' => array(
410
+				'symbol'    => $this->currency_config->sign,
411
+				'format'    => array(
412
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
413
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
414
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
415
+				),
416
+				'decimal'   => $this->currency_config->dec_mrk,
417
+				'thousand'  => $this->currency_config->thsnds,
418
+				'precision' => $this->currency_config->dec_plc,
419
+			),
420
+			'number'   => array(
421
+				'precision' => $this->currency_config->dec_plc,
422
+				'thousand'  => $this->currency_config->thsnds,
423
+				'decimal'   => $this->currency_config->dec_mrk,
424
+			),
425
+		);
426
+	}
427
+
428
+
429
+	/**
430
+	 * Returns configuration data for the js Currency VO.
431
+	 * @since 4.9.71.p
432
+	 * @return array
433
+	 */
434
+	private function getCurrencySettings()
435
+	{
436
+		return array(
437
+			'code' => $this->currency_config->code,
438
+			'singularLabel' => $this->currency_config->name,
439
+			'pluralLabel' => $this->currency_config->plural,
440
+			'sign' => $this->currency_config->sign,
441
+			'signB4' => $this->currency_config->sign_b4,
442
+			'decimalPlaces' => $this->currency_config->dec_plc,
443
+			'decimalMark' => $this->currency_config->dec_mrk,
444
+			'thousandsSeparator' => $this->currency_config->thsnds,
445
+		);
446
+	}
447
+
448
+
449
+	/**
450
+	 * @since 4.9.62.p
451
+	 * @throws DuplicateCollectionIdentifierException
452
+	 * @throws InvalidDataTypeException
453
+	 * @throws InvalidEntityException
454
+	 */
455
+	private function loadCoreCss()
456
+	{
457
+		if ($this->template_config->enable_default_style && ! is_admin()) {
458
+			$this->addStylesheet(
459
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
460
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
461
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
462
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
463
+				array('dashicons')
464
+			);
465
+			//Load custom style sheet if available
466
+			if ($this->template_config->custom_style_sheet !== null) {
467
+				$this->addStylesheet(
468
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
469
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
470
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
471
+				);
472
+			}
473
+		}
474
+		$this->addStylesheet(
475
+			CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT,
476
+			$this->registry->getCssUrl(
477
+				$this->domain->assetNamespace(),
478
+				'core-default-theme'
479
+			),
480
+			['dashicons']
481
+		);
482
+		$this->addStylesheet(
483
+			CoreAssetManager::CSS_HANDLE_COMPONENTS,
484
+			$this->registry->getCssUrl(
485
+				$this->domain->assetNamespace(),
486
+				'components'
487
+			),
488
+			[CoreAssetManager::CSS_HANDLE_CORE_CSS_DEFAULT]
489
+		);
490
+	}
491
+
492
+
493
+	/**
494
+	 * jQuery Validate for form validation
495
+	 *
496
+	 * @since 4.9.62.p
497
+	 * @throws DomainException
498
+	 * @throws DuplicateCollectionIdentifierException
499
+	 * @throws InvalidDataTypeException
500
+	 * @throws InvalidEntityException
501
+	 */
502
+	private function loadJqueryValidate()
503
+	{
504
+		$this->addJavascript(
505
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
506
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
507
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
508
+		)
509
+		->setVersion('1.15.0');
510
+
511
+		$this->addJavascript(
512
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
513
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
514
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE)
515
+		)
516
+		->setVersion('1.15.0');
517
+	}
518
+
519
+
520
+	/**
521
+	 * accounting.js for performing client-side calculations
522
+	 *
523
+	 * @since 4.9.62.p
524
+	 * @throws DomainException
525
+	 * @throws DuplicateCollectionIdentifierException
526
+	 * @throws InvalidDataTypeException
527
+	 * @throws InvalidEntityException
528
+	 */
529
+	private function loadAccountingJs()
530
+	{
531
+		//accounting.js library
532
+		// @link http://josscrowcroft.github.io/accounting.js/
533
+		$this->addJavascript(
534
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
535
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
536
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE)
537
+		)
538
+		->setVersion('0.3.2');
539
+
540
+		$this->addJavascript(
541
+			CoreAssetManager::JS_HANDLE_ACCOUNTING,
542
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
543
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
544
+		)
545
+		->setInlineDataCallback(
546
+			function () {
547
+				 wp_localize_script(
548
+					 CoreAssetManager::JS_HANDLE_ACCOUNTING,
549
+					 'EE_ACCOUNTING_CFG',
550
+					 $this->getAccountingSettings()
551
+				 );
552
+			}
553
+		)
554
+		->setVersion();
555
+	}
556
+
557
+
558
+	/**
559
+	 * registers assets for cleaning your ears
560
+	 *
561
+	 * @param JavascriptAsset $script
562
+	 */
563
+	public function loadQtipJs(JavascriptAsset $script)
564
+	{
565
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
566
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
567
+		if (
568
+			$script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
569
+			&& apply_filters('FHEE_load_qtip', false)
570
+		) {
571
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
572
+		}
573
+	}
574
+
575
+
576
+	/**
577
+	 * assets that are used in the WordPress admin
578
+	 *
579
+	 * @since 4.9.62.p
580
+	 * @throws DuplicateCollectionIdentifierException
581
+	 * @throws InvalidDataTypeException
582
+	 * @throws InvalidEntityException
583
+	 */
584
+	private function registerAdminAssets()
585
+	{
586
+		$this->addJavascript(
587
+			CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
588
+			$this->registry->getJsUrl($this->domain->assetNamespace(), 'wp-plugins-page'),
589
+			array(
590
+				CoreAssetManager::JS_HANDLE_JQUERY,
591
+				CoreAssetManager::JS_HANDLE_VENDOR,
592
+			)
593
+		)
594
+		->setRequiresTranslation();
595
+
596
+		$this->addStylesheet(
597
+			CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE,
598
+			$this->registry->getCssUrl($this->domain->assetNamespace(), 'wp-plugins-page')
599
+		);
600
+	}
601 601
 }
Please login to merge, or discard this patch.