Completed
Branch EDTR/refactor-master (7df3f4)
by
unknown
26:35 queued 18:25
created
core/services/assets/AssetManager.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -270,7 +270,7 @@
 block discarded – undo
270 270
      * @param string $asset_type
271 271
      * @param string $handle
272 272
      * @param array  $extra_dependencies
273
-     * @return array
273
+     * @return string
274 274
      * @since $VID:$
275 275
      */
276 276
     private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
Please login to merge, or discard this patch.
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -23,284 +23,284 @@
 block discarded – undo
23 23
 abstract class AssetManager implements AssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var AssetCollection $assets
28
-     */
29
-    protected $assets;
26
+	/**
27
+	 * @var AssetCollection $assets
28
+	 */
29
+	protected $assets;
30 30
 
31
-    /**
32
-     * @var DomainInterface
33
-     */
34
-    protected $domain;
31
+	/**
32
+	 * @var DomainInterface
33
+	 */
34
+	protected $domain;
35 35
 
36
-    /**
37
-     * @var Registry $registry
38
-     */
39
-    protected $registry;
36
+	/**
37
+	 * @var Registry $registry
38
+	 */
39
+	protected $registry;
40 40
 
41 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
-    }
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 59
 
60 60
 
61
-    /**
62
-     * @since 4.9.71.p
63
-     * @return string
64
-     */
65
-    public function assetNamespace()
66
-    {
67
-        return $this->domain->assetNamespace();
68
-    }
61
+	/**
62
+	 * @since 4.9.71.p
63
+	 * @return string
64
+	 */
65
+	public function assetNamespace()
66
+	{
67
+		return $this->domain->assetNamespace();
68
+	}
69 69
 
70 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
-    }
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 87
 
88 88
 
89
-    /**
90
-     * @return ManifestFile[]
91
-     * @since 4.9.62.p
92
-     */
93
-    public function getManifestFile()
94
-    {
95
-        return $this->assets->getManifestFiles();
96
-    }
89
+	/**
90
+	 * @return ManifestFile[]
91
+	 * @since 4.9.62.p
92
+	 */
93
+	public function getManifestFile()
94
+	{
95
+		return $this->assets->getManifestFiles();
96
+	}
97 97
 
98 98
 
99
-    /**
100
-     * @param string $handle
101
-     * @param string $source
102
-     * @param array  $dependencies
103
-     * @param bool   $load_in_footer
104
-     * @param string $version
105
-     * @return JavascriptAsset
106
-     * @throws DuplicateCollectionIdentifierException
107
-     * @throws InvalidDataTypeException
108
-     * @throws InvalidEntityException
109
-     * @throws DomainException
110
-     * @since 4.9.62.p
111
-     */
112
-    public function addJavascript(
113
-        $handle,
114
-        $source,
115
-        array $dependencies = array(),
116
-        $load_in_footer = true,
117
-        $version = ''
118
-    ) {
119
-        $asset = new JavascriptAsset(
120
-            $handle,
121
-            $source,
122
-            array_unique($dependencies),
123
-            $load_in_footer,
124
-            $this->domain,
125
-            $version
126
-        );
127
-        $this->assets->add($asset, $handle);
128
-        return $asset;
129
-    }
99
+	/**
100
+	 * @param string $handle
101
+	 * @param string $source
102
+	 * @param array  $dependencies
103
+	 * @param bool   $load_in_footer
104
+	 * @param string $version
105
+	 * @return JavascriptAsset
106
+	 * @throws DuplicateCollectionIdentifierException
107
+	 * @throws InvalidDataTypeException
108
+	 * @throws InvalidEntityException
109
+	 * @throws DomainException
110
+	 * @since 4.9.62.p
111
+	 */
112
+	public function addJavascript(
113
+		$handle,
114
+		$source,
115
+		array $dependencies = array(),
116
+		$load_in_footer = true,
117
+		$version = ''
118
+	) {
119
+		$asset = new JavascriptAsset(
120
+			$handle,
121
+			$source,
122
+			array_unique($dependencies),
123
+			$load_in_footer,
124
+			$this->domain,
125
+			$version
126
+		);
127
+		$this->assets->add($asset, $handle);
128
+		return $asset;
129
+	}
130 130
 
131 131
 
132
-    /**
133
-     * Used to register a javascript asset where everything is dynamically derived from the given handle.
134
-     *
135
-     * @param string       $handle
136
-     * @param string|array $extra_dependencies
137
-     * @return JavascriptAsset
138
-     * @throws DuplicateCollectionIdentifierException
139
-     * @throws InvalidDataTypeException
140
-     * @throws InvalidEntityException
141
-     * @throws DomainException
142
-     */
143
-    public function addJs($handle, $extra_dependencies = [])
144
-    {
145
-        $details = $this->getAssetDetails(
146
-            Asset::TYPE_JS,
147
-            $handle,
148
-            $extra_dependencies
149
-        );
150
-        return $this->addJavascript(
151
-            $handle,
152
-            $this->registry->getJsUrl($this->domain->assetNamespace(), $handle),
153
-            $details['dependencies'],
154
-            true,
155
-            $details['version']
156
-        );
157
-    }
132
+	/**
133
+	 * Used to register a javascript asset where everything is dynamically derived from the given handle.
134
+	 *
135
+	 * @param string       $handle
136
+	 * @param string|array $extra_dependencies
137
+	 * @return JavascriptAsset
138
+	 * @throws DuplicateCollectionIdentifierException
139
+	 * @throws InvalidDataTypeException
140
+	 * @throws InvalidEntityException
141
+	 * @throws DomainException
142
+	 */
143
+	public function addJs($handle, $extra_dependencies = [])
144
+	{
145
+		$details = $this->getAssetDetails(
146
+			Asset::TYPE_JS,
147
+			$handle,
148
+			$extra_dependencies
149
+		);
150
+		return $this->addJavascript(
151
+			$handle,
152
+			$this->registry->getJsUrl($this->domain->assetNamespace(), $handle),
153
+			$details['dependencies'],
154
+			true,
155
+			$details['version']
156
+		);
157
+	}
158 158
 
159 159
 
160
-    /**
161
-     * @param string $handle
162
-     * @param array  $dependencies
163
-     * @param bool   $load_in_footer
164
-     * @param string $version
165
-     * @return JavascriptAsset
166
-     * @throws DomainException
167
-     * @throws DuplicateCollectionIdentifierException
168
-     * @throws InvalidDataTypeException
169
-     * @throws InvalidEntityException
170
-     * @since 4.9.71.p
171
-     */
172
-    public function addVendorJavascript(
173
-        $handle,
174
-        array $dependencies = array(),
175
-        $load_in_footer = true,
176
-        $version = ''
177
-    ) {
178
-        $dev_suffix = wp_scripts_get_suffix('dev');
179
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
180
-        return $this->addJavascript(
181
-            $handle,
182
-            "{$vendor_path}{$handle}{$dev_suffix}.js",
183
-            $dependencies,
184
-            $load_in_footer,
185
-            $version
186
-        );
187
-    }
160
+	/**
161
+	 * @param string $handle
162
+	 * @param array  $dependencies
163
+	 * @param bool   $load_in_footer
164
+	 * @param string $version
165
+	 * @return JavascriptAsset
166
+	 * @throws DomainException
167
+	 * @throws DuplicateCollectionIdentifierException
168
+	 * @throws InvalidDataTypeException
169
+	 * @throws InvalidEntityException
170
+	 * @since 4.9.71.p
171
+	 */
172
+	public function addVendorJavascript(
173
+		$handle,
174
+		array $dependencies = array(),
175
+		$load_in_footer = true,
176
+		$version = ''
177
+	) {
178
+		$dev_suffix = wp_scripts_get_suffix('dev');
179
+		$vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
180
+		return $this->addJavascript(
181
+			$handle,
182
+			"{$vendor_path}{$handle}{$dev_suffix}.js",
183
+			$dependencies,
184
+			$load_in_footer,
185
+			$version
186
+		);
187
+	}
188 188
 
189 189
 
190
-    /**
191
-     * @param string $handle
192
-     * @param string $source
193
-     * @param array  $dependencies
194
-     * @param string $media
195
-     * @param string $version
196
-     * @return StylesheetAsset
197
-     * @throws DomainException
198
-     * @throws DuplicateCollectionIdentifierException
199
-     * @throws InvalidDataTypeException
200
-     * @throws InvalidEntityException
201
-     * @since 4.9.62.p
202
-     */
203
-    public function addStylesheet(
204
-        $handle,
205
-        $source,
206
-        array $dependencies = array(),
207
-        $media = 'all',
208
-        $version = ''
209
-    ) {
210
-        $asset = new StylesheetAsset(
211
-            $handle,
212
-            $source,
213
-            array_unique($dependencies),
214
-            $this->domain,
215
-            $media,
216
-            $version
217
-        );
218
-        $this->assets->add($asset, $handle);
219
-        return $asset;
220
-    }
190
+	/**
191
+	 * @param string $handle
192
+	 * @param string $source
193
+	 * @param array  $dependencies
194
+	 * @param string $media
195
+	 * @param string $version
196
+	 * @return StylesheetAsset
197
+	 * @throws DomainException
198
+	 * @throws DuplicateCollectionIdentifierException
199
+	 * @throws InvalidDataTypeException
200
+	 * @throws InvalidEntityException
201
+	 * @since 4.9.62.p
202
+	 */
203
+	public function addStylesheet(
204
+		$handle,
205
+		$source,
206
+		array $dependencies = array(),
207
+		$media = 'all',
208
+		$version = ''
209
+	) {
210
+		$asset = new StylesheetAsset(
211
+			$handle,
212
+			$source,
213
+			array_unique($dependencies),
214
+			$this->domain,
215
+			$media,
216
+			$version
217
+		);
218
+		$this->assets->add($asset, $handle);
219
+		return $asset;
220
+	}
221 221
 
222 222
 
223
-    /**
224
-     * Used to register a css asset where everything is dynamically derived from the given handle.
225
-     *
226
-     * @param string       $handle
227
-     * @param string|array $extra_dependencies
228
-     * @return StylesheetAsset
229
-     * @throws DuplicateCollectionIdentifierException
230
-     * @throws InvalidDataTypeException
231
-     * @throws InvalidEntityException
232
-     * @throws DomainException
233
-     */
234
-    public function addCss($handle, $extra_dependencies = [])
235
-    {
236
-        $details = $this->getAssetDetails(
237
-            Asset::TYPE_CSS,
238
-            $handle,
239
-            $extra_dependencies
240
-        );
241
-        return $this->addStylesheet(
242
-            $handle,
243
-            $this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
244
-            $details['dependencies'],
245
-            'all',
246
-            $details['version']
247
-        );
248
-    }
223
+	/**
224
+	 * Used to register a css asset where everything is dynamically derived from the given handle.
225
+	 *
226
+	 * @param string       $handle
227
+	 * @param string|array $extra_dependencies
228
+	 * @return StylesheetAsset
229
+	 * @throws DuplicateCollectionIdentifierException
230
+	 * @throws InvalidDataTypeException
231
+	 * @throws InvalidEntityException
232
+	 * @throws DomainException
233
+	 */
234
+	public function addCss($handle, $extra_dependencies = [])
235
+	{
236
+		$details = $this->getAssetDetails(
237
+			Asset::TYPE_CSS,
238
+			$handle,
239
+			$extra_dependencies
240
+		);
241
+		return $this->addStylesheet(
242
+			$handle,
243
+			$this->registry->getCssUrl($this->domain->assetNamespace(), $handle),
244
+			$details['dependencies'],
245
+			'all',
246
+			$details['version']
247
+		);
248
+	}
249 249
 
250 250
 
251
-    /**
252
-     * @param string $handle
253
-     * @return bool
254
-     * @since 4.9.62.p
255
-     */
256
-    public function enqueueAsset($handle)
257
-    {
258
-        if ($this->assets->has($handle)) {
259
-            $asset = $this->assets->get($handle);
260
-            if ($asset->isRegistered()) {
261
-                $asset->enqueueAsset();
262
-                return true;
263
-            }
264
-        }
265
-        return false;
266
-    }
251
+	/**
252
+	 * @param string $handle
253
+	 * @return bool
254
+	 * @since 4.9.62.p
255
+	 */
256
+	public function enqueueAsset($handle)
257
+	{
258
+		if ($this->assets->has($handle)) {
259
+			$asset = $this->assets->get($handle);
260
+			if ($asset->isRegistered()) {
261
+				$asset->enqueueAsset();
262
+				return true;
263
+			}
264
+		}
265
+		return false;
266
+	}
267 267
 
268 268
 
269
-    /**
270
-     * @param string $asset_type
271
-     * @param string $handle
272
-     * @param array  $extra_dependencies
273
-     * @return array
274
-     * @since $VID:$
275
-     */
276
-    private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
277
-    {
278
-        $getAssetDetails = '';
279
-        switch ($asset_type) {
280
-            case Asset::TYPE_JS :
281
-                $getAssetDetails = 'getJsAssetDetails';
282
-                break;
283
-            case Asset::TYPE_CSS :
284
-                $getAssetDetails = 'getCssAssetDetails';
285
-                break;
286
-        }
287
-        if ($getAssetDetails === '') {
288
-            return ['dependencies' => [], 'version' => ''];
289
-        }
290
-        $details = $this->registry->$getAssetDetails(
291
-            $this->domain->assetNamespace(),
292
-            $handle
293
-        );
294
-        $details['dependencies'] = isset($details['dependencies'])
295
-            ? $details['dependencies']
296
-            : [];
297
-        $details['version'] = isset($details['version'])
298
-            ? $details['version']
299
-            : '';
300
-        $details['dependencies'] = ! empty($extra_dependencies)
301
-            ? array_merge($details['dependencies'], (array) $extra_dependencies)
302
-            : $details['dependencies'];
303
-        return $details;
269
+	/**
270
+	 * @param string $asset_type
271
+	 * @param string $handle
272
+	 * @param array  $extra_dependencies
273
+	 * @return array
274
+	 * @since $VID:$
275
+	 */
276
+	private function getAssetDetails($asset_type, $handle, $extra_dependencies = [])
277
+	{
278
+		$getAssetDetails = '';
279
+		switch ($asset_type) {
280
+			case Asset::TYPE_JS :
281
+				$getAssetDetails = 'getJsAssetDetails';
282
+				break;
283
+			case Asset::TYPE_CSS :
284
+				$getAssetDetails = 'getCssAssetDetails';
285
+				break;
286
+		}
287
+		if ($getAssetDetails === '') {
288
+			return ['dependencies' => [], 'version' => ''];
289
+		}
290
+		$details = $this->registry->$getAssetDetails(
291
+			$this->domain->assetNamespace(),
292
+			$handle
293
+		);
294
+		$details['dependencies'] = isset($details['dependencies'])
295
+			? $details['dependencies']
296
+			: [];
297
+		$details['version'] = isset($details['version'])
298
+			? $details['version']
299
+			: '';
300
+		$details['dependencies'] = ! empty($extra_dependencies)
301
+			? array_merge($details['dependencies'], (array) $extra_dependencies)
302
+			: $details['dependencies'];
303
+		return $details;
304 304
 
305
-    }
305
+	}
306 306
 }
Please login to merge, or discard this patch.
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -176,7 +176,7 @@
 block discarded – undo
176 176
         $version = ''
177 177
     ) {
178 178
         $dev_suffix = wp_scripts_get_suffix('dev');
179
-        $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/';
179
+        $vendor_path = $this->domain->pluginUrl().'assets/vendor/';
180 180
         return $this->addJavascript(
181 181
             $handle,
182 182
             "{$vendor_path}{$handle}{$dev_suffix}.js",
Please login to merge, or discard this patch.
core/services/assets/Registry.php 2 patches
Spacing   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
                 $script->version(),
185 185
                 $script->loadInFooter()
186 186
             );
187
-            if (! $registered && $this->debug()) {
187
+            if ( ! $registered && $this->debug()) {
188 188
                 throw new AssetRegistrationException($script->handle());
189 189
             }
190 190
             $script->setRegistered($registered);
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
         $this->removeAlreadyRegisteredDataForScriptHandles();
246 246
         wp_add_inline_script(
247 247
             'eejs-core',
248
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
248
+            'var eejsdata='.wp_json_encode(array('data' => $this->jsdata)),
249 249
             'before'
250 250
         );
251 251
         $scripts = $this->assets->getJavascriptAssetsWithData();
@@ -275,7 +275,7 @@  discard block
 block discarded – undo
275 275
     public function addData($key, $value)
276 276
     {
277 277
         if ($this->verifyDataNotExisting($key)) {
278
-            $this->jsdata[ $key ] = $value;
278
+            $this->jsdata[$key] = $value;
279 279
         }
280 280
     }
281 281
 
@@ -300,10 +300,10 @@  discard block
 block discarded – undo
300 300
      */
301 301
     public function pushData($key, $value)
302 302
     {
303
-        if (isset($this->jsdata[ $key ])
304
-            && ! is_array($this->jsdata[ $key ])
303
+        if (isset($this->jsdata[$key])
304
+            && ! is_array($this->jsdata[$key])
305 305
         ) {
306
-            if (! $this->debug()) {
306
+            if ( ! $this->debug()) {
307 307
                 return;
308 308
             }
309 309
             throw new InvalidArgumentException(
@@ -318,10 +318,10 @@  discard block
 block discarded – undo
318 318
                 )
319 319
             );
320 320
         }
321
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
322
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
321
+        if ( ! isset($this->jsdata[$key])) {
322
+            $this->jsdata[$key] = is_array($value) ? $value : [$value];
323 323
         } else {
324
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
324
+            $this->jsdata[$key] = array_merge($this->jsdata[$key], (array) $value);
325 325
         }
326 326
     }
327 327
 
@@ -336,12 +336,12 @@  discard block
 block discarded – undo
336 336
      */
337 337
     public function addTemplate($template_reference, $template_content)
338 338
     {
339
-        if (! isset($this->jsdata['templates'])) {
339
+        if ( ! isset($this->jsdata['templates'])) {
340 340
             $this->jsdata['templates'] = array();
341 341
         }
342 342
         //no overrides allowed.
343
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
344
-            if (! $this->debug()) {
343
+        if (isset($this->jsdata['templates'][$template_reference])) {
344
+            if ( ! $this->debug()) {
345 345
                 return;
346 346
             }
347 347
             throw new InvalidArgumentException(
@@ -354,7 +354,7 @@  discard block
 block discarded – undo
354 354
                 )
355 355
             );
356 356
         }
357
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
357
+        $this->jsdata['templates'][$template_reference] = $template_content;
358 358
     }
359 359
 
360 360
 
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
      */
367 367
     public function getTemplate($template_reference)
368 368
     {
369
-        return isset($this->jsdata['templates'][ $template_reference ])
370
-            ? $this->jsdata['templates'][ $template_reference ]
369
+        return isset($this->jsdata['templates'][$template_reference])
370
+            ? $this->jsdata['templates'][$template_reference]
371 371
             : '';
372 372
     }
373 373
 
@@ -380,8 +380,8 @@  discard block
 block discarded – undo
380 380
      */
381 381
     public function getData($key)
382 382
     {
383
-        return isset($this->jsdata[ $key ])
384
-            ? $this->jsdata[ $key ]
383
+        return isset($this->jsdata[$key])
384
+            ? $this->jsdata[$key]
385 385
             : false;
386 386
     }
387 387
 
@@ -396,11 +396,11 @@  discard block
 block discarded – undo
396 396
      */
397 397
     protected function verifyDataNotExisting($key)
398 398
     {
399
-        if (isset($this->jsdata[ $key ])) {
400
-            if (! $this->debug()) {
399
+        if (isset($this->jsdata[$key])) {
400
+            if ( ! $this->debug()) {
401 401
                 return false;
402 402
             }
403
-            if (is_array($this->jsdata[ $key ])) {
403
+            if (is_array($this->jsdata[$key])) {
404 404
                 throw new InvalidArgumentException(
405 405
                     sprintf(
406 406
                         __(
@@ -443,11 +443,11 @@  discard block
 block discarded – undo
443 443
     public function getAssetUrl($namespace, $chunk_name, $asset_type)
444 444
     {
445 445
         $url = isset(
446
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
447
-            $this->manifest_data[ $namespace ]['url_base']
446
+            $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type],
447
+            $this->manifest_data[$namespace]['url_base']
448 448
         )
449
-            ? $this->manifest_data[ $namespace ]['url_base']
450
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
449
+            ? $this->manifest_data[$namespace]['url_base']
450
+              . $this->manifest_data[$namespace][$chunk_name.'.'.$asset_type]
451 451
             : $chunk_name;
452 452
 
453 453
         return apply_filters(
@@ -498,21 +498,21 @@  discard block
 block discarded – undo
498 498
      */
499 499
     private function getDetailsForAsset($namespace, $chunk_name, $asset_type)
500 500
     {
501
-        $asset_index = $chunk_name . '.' . $asset_type;
502
-        if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
503
-            $path = isset($this->manifest_data[ $namespace ]['path'])
504
-                ? $this->manifest_data[ $namespace ]['path']
501
+        $asset_index = $chunk_name.'.'.$asset_type;
502
+        if ( ! isset($this->dependencies_data[$namespace][$asset_index])) {
503
+            $path = isset($this->manifest_data[$namespace]['path'])
504
+                ? $this->manifest_data[$namespace]['path']
505 505
                 : '';
506
-            $dependencies_index = $chunk_name . '.' . Asset::TYPE_PHP;
507
-            $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
508
-                ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
506
+            $dependencies_index = $chunk_name.'.'.Asset::TYPE_PHP;
507
+            $file_path = isset($this->manifest_data[$namespace][$dependencies_index])
508
+                ? $path.$this->manifest_data[$namespace][$dependencies_index]
509 509
                 :
510 510
                 '';
511
-            $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
511
+            $this->dependencies_data[$namespace][$asset_index] = $file_path !== '' && file_exists($file_path)
512 512
                 ? $this->getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
513 513
                 : [];
514 514
         }
515
-        $details = $this->dependencies_data[ $namespace ][ $asset_index ];
515
+        $details = $this->dependencies_data[$namespace][$asset_index];
516 516
         return $details;
517 517
     }
518 518
 
@@ -539,34 +539,34 @@  discard block
 block discarded – undo
539 539
             ? $asset_details['version']
540 540
             : '';
541 541
         if ($asset_type === Asset::TYPE_JS) {
542
-            $asset_details['dependencies'] =  $chunk_name === 'eejs-core'
542
+            $asset_details['dependencies'] = $chunk_name === 'eejs-core'
543 543
                 ? $asset_details['dependencies']
544
-                : $asset_details['dependencies'] + [ CoreAssetManager::JS_HANDLE_JS_CORE ];
544
+                : $asset_details['dependencies'] + [CoreAssetManager::JS_HANDLE_JS_CORE];
545 545
             return $asset_details;
546 546
         }
547 547
         // for css we need to make sure there is actually a css file related to this chunk.
548
-        if (isset($this->manifest_data[ $namespace ])) {
548
+        if (isset($this->manifest_data[$namespace])) {
549 549
             // array of css chunk files for ee.
550 550
             $css_chunks = array_map(
551
-                static function ($value) {
551
+                static function($value) {
552 552
                     return str_replace('.css', '', $value);
553 553
                 },
554 554
                 array_filter(
555
-                    array_keys($this->manifest_data[ $namespace ]),
556
-                    static function ($value) {
555
+                    array_keys($this->manifest_data[$namespace]),
556
+                    static function($value) {
557 557
                         return strpos($value, '.css') !== false;
558 558
                     }
559 559
                 )
560 560
             );
561 561
             // add known wp chunks with css
562
-            $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
562
+            $css_chunks = array_merge($css_chunks, $this->wp_css_handle_dependencies);
563 563
             // flip for easier search
564 564
             $css_chunks = array_flip($css_chunks);
565 565
             // now let's filter the dependencies for the incoming chunk to actual chunks that have styles
566 566
             $asset_details['dependencies'] = array_filter(
567 567
                 $asset_details['dependencies'],
568
-                static function ($chunk_name) use ($css_chunks) {
569
-                    return isset($css_chunks[ $chunk_name ]);
568
+                static function($chunk_name) use ($css_chunks) {
569
+                    return isset($css_chunks[$chunk_name]);
570 570
                 }
571 571
             );
572 572
             return $asset_details;
@@ -615,7 +615,7 @@  discard block
 block discarded – undo
615 615
             $this->registerManifestFile(
616 616
                 $manifest_file->assetNamespace(),
617 617
                 $manifest_file->urlBase(),
618
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
618
+                $manifest_file->filepath().Registry::FILE_NAME_BUILD_MANIFEST,
619 619
                 $manifest_file->filepath()
620 620
             );
621 621
         }
@@ -636,8 +636,8 @@  discard block
 block discarded – undo
636 636
      */
637 637
     public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
638 638
     {
639
-        if (isset($this->manifest_data[ $namespace ])) {
640
-            if (! $this->debug()) {
639
+        if (isset($this->manifest_data[$namespace])) {
640
+            if ( ! $this->debug()) {
641 641
                 return;
642 642
             }
643 643
             throw new InvalidArgumentException(
@@ -670,12 +670,12 @@  discard block
 block discarded – undo
670 670
             }
671 671
             return;
672 672
         }
673
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
674
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
675
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
673
+        $this->manifest_data[$namespace] = $this->decodeManifestFile($manifest_file);
674
+        if ( ! isset($this->manifest_data[$namespace]['url_base'])) {
675
+            $this->manifest_data[$namespace]['url_base'] = trailingslashit($url_base);
676 676
         }
677
-        if (! isset($this->manifest_data[ $namespace ]['path'])) {
678
-            $this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
677
+        if ( ! isset($this->manifest_data[$namespace]['path'])) {
678
+            $this->manifest_data[$namespace]['path'] = $manifest_file_path;
679 679
         }
680 680
     }
681 681
 
@@ -690,7 +690,7 @@  discard block
 block discarded – undo
690 690
      */
691 691
     private function decodeManifestFile($manifest_file)
692 692
     {
693
-        if (! file_exists($manifest_file)) {
693
+        if ( ! file_exists($manifest_file)) {
694 694
             throw new InvalidFilePathException($manifest_file);
695 695
         }
696 696
         return json_decode(file_get_contents($manifest_file), true);
@@ -704,7 +704,7 @@  discard block
 block discarded – undo
704 704
      */
705 705
     private function addRegisteredScriptHandlesWithData($script_handle)
706 706
     {
707
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
707
+        $this->script_handles_with_data[$script_handle] = $script_handle;
708 708
     }
709 709
 
710 710
 
@@ -730,23 +730,23 @@  discard block
 block discarded – undo
730 730
      */
731 731
     private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
732 732
     {
733
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
733
+        if (isset($this->script_handles_with_data[$script_handle])) {
734 734
             global $wp_scripts;
735 735
             $unset_handle = false;
736 736
             if ($wp_scripts->get_data($script_handle, 'data')) {
737
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
737
+                unset($wp_scripts->registered[$script_handle]->extra['data']);
738 738
                 $unset_handle = true;
739 739
             }
740 740
             //deal with inline_scripts
741 741
             if ($wp_scripts->get_data($script_handle, 'before')) {
742
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
742
+                unset($wp_scripts->registered[$script_handle]->extra['before']);
743 743
                 $unset_handle = true;
744 744
             }
745 745
             if ($wp_scripts->get_data($script_handle, 'after')) {
746
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
746
+                unset($wp_scripts->registered[$script_handle]->extra['after']);
747 747
             }
748 748
             if ($unset_handle) {
749
-                unset($this->script_handles_with_data[ $script_handle ]);
749
+                unset($this->script_handles_with_data[$script_handle]);
750 750
             }
751 751
         }
752 752
     }
Please login to merge, or discard this patch.
Indentation   +774 added lines, -774 removed lines patch added patch discarded remove patch
@@ -26,785 +26,785 @@
 block discarded – undo
26 26
 class Registry
27 27
 {
28 28
 
29
-    const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
30
-
31
-    /**
32
-     * @var AssetCollection $assets
33
-     */
34
-    protected $assets;
35
-
36
-    /**
37
-     * @var I18nRegistry
38
-     */
39
-    private $i18n_registry;
40
-
41
-    /**
42
-     * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
43
-     *
44
-     * @var array
45
-     */
46
-    protected $jsdata = array();
47
-
48
-    /**
49
-     * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
50
-     * page source.
51
-     *
52
-     * @var array
53
-     */
54
-    private $script_handles_with_data = array();
55
-
56
-
57
-    /**
58
-     * Holds the manifest data obtained from registered manifest files.
59
-     * Manifests are maps of asset chunk name to actual built asset file names.
60
-     * Shape of this array is:
61
-     * array(
62
-     *  'some_namespace_slug' => array(
63
-     *      'some_chunk_name' => array(
64
-     *          'js' => 'filename.js'
65
-     *          'css' => 'filename.js'
66
-     *      ),
67
-     *      'url_base' => 'https://baseurl.com/to/assets
68
-     *  )
69
-     * )
70
-     *
71
-     * @var array
72
-     */
73
-    private $manifest_data = array();
74
-
75
-
76
-    /**
77
-     * Holds any dependency data obtained from registered dependency map json.
78
-     * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
79
-     * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
80
-     *
81
-     * @var array
82
-     */
83
-    private $dependencies_data = [];
84
-
85
-
86
-    /**
87
-     * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
88
-     * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
89
-     * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
90
-     * are used for both js and css.
91
-     * @var array
92
-     */
93
-    private $wp_css_handle_dependencies = [
94
-        'wp-components',
95
-        'wp-block-editor',
96
-        'wp-block-library',
97
-        'wp-edit-post',
98
-        'wp-edit-widgets',
99
-        'wp-editor',
100
-        'wp-format-library',
101
-        'wp-list-reusable-blocks',
102
-        'wp-nux',
103
-    ];
104
-
105
-
106
-    /**
107
-     * Registry constructor.
108
-     * Hooking into WP actions for script registry.
109
-     *
110
-     * @param AssetCollection      $assets
111
-     * @param I18nRegistry         $i18n_registry
112
-     * @throws InvalidArgumentException
113
-     * @throws InvalidDataTypeException
114
-     * @throws InvalidInterfaceException
115
-     */
116
-    public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
117
-    {
118
-        $this->assets = $assets;
119
-        $this->i18n_registry = $i18n_registry;
120
-        add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
121
-        add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
122
-        add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
123
-        add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
124
-        add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
125
-        add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
126
-        add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
127
-        add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
128
-    }
129
-
130
-
131
-    /**
132
-     * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
133
-     * translation handling.
134
-     *
135
-     * @return I18nRegistry
136
-     */
137
-    public function getI18nRegistry()
138
-    {
139
-        return $this->i18n_registry;
140
-    }
141
-
142
-
143
-    /**
144
-     * Callback for the wp_enqueue_scripts actions used to register assets.
145
-     *
146
-     * @since 4.9.62.p
147
-     * @throws Exception
148
-     */
149
-    public function registerScriptsAndStyles()
150
-    {
151
-        try {
152
-            $this->registerScripts($this->assets->getJavascriptAssets());
153
-            $this->registerStyles($this->assets->getStylesheetAssets());
154
-        } catch (Exception $exception) {
155
-            new ExceptionStackTraceDisplay($exception);
156
-        }
157
-    }
158
-
159
-
160
-    /**
161
-     * Registers JS assets with WP core
162
-     *
163
-     * @param JavascriptAsset[] $scripts
164
-     * @throws AssetRegistrationException
165
-     * @throws InvalidDataTypeException
166
-     * @throws DomainException
167
-     * @since 4.9.62.p
168
-     */
169
-    public function registerScripts(array $scripts)
170
-    {
171
-        foreach ($scripts as $script) {
172
-            // skip to next script if this has already been done
173
-            if ($script->isRegistered()) {
174
-                continue;
175
-            }
176
-            do_action(
177
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
178
-                $script
179
-            );
180
-            $registered = wp_register_script(
181
-                $script->handle(),
182
-                $script->source(),
183
-                $script->dependencies(),
184
-                $script->version(),
185
-                $script->loadInFooter()
186
-            );
187
-            if (! $registered && $this->debug()) {
188
-                throw new AssetRegistrationException($script->handle());
189
-            }
190
-            $script->setRegistered($registered);
191
-            if ($script->requiresTranslation()) {
192
-                $this->registerTranslation($script->handle());
193
-            }
194
-            do_action(
195
-                'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
196
-                $script
197
-            );
198
-        }
199
-    }
200
-
201
-
202
-    /**
203
-     * Registers CSS assets with WP core
204
-     *
205
-     * @param StylesheetAsset[] $styles
206
-     * @throws InvalidDataTypeException
207
-     * @throws DomainException
208
-     * @since 4.9.62.p
209
-     */
210
-    public function registerStyles(array $styles)
211
-    {
212
-        foreach ($styles as $style) {
213
-            // skip to next style if this has already been done
214
-            if ($style->isRegistered()) {
215
-                continue;
216
-            }
217
-            do_action(
218
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
219
-                $style
220
-            );
221
-            wp_register_style(
222
-                $style->handle(),
223
-                $style->source(),
224
-                $style->dependencies(),
225
-                $style->version(),
226
-                $style->media()
227
-            );
228
-            $style->setRegistered();
229
-            do_action(
230
-                'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
231
-                $style
232
-            );
233
-        }
234
-    }
235
-
236
-
237
-    /**
238
-     * Call back for the script print in frontend and backend.
239
-     * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
240
-     *
241
-     * @since 4.9.31.rc.015
242
-     */
243
-    public function enqueueData()
244
-    {
245
-        $this->removeAlreadyRegisteredDataForScriptHandles();
246
-        wp_add_inline_script(
247
-            'eejs-core',
248
-            'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
249
-            'before'
250
-        );
251
-        $scripts = $this->assets->getJavascriptAssetsWithData();
252
-        foreach ($scripts as $script) {
253
-            $this->addRegisteredScriptHandlesWithData($script->handle());
254
-            if ($script->hasInlineDataCallback()) {
255
-                $localize = $script->inlineDataCallback();
256
-                $localize();
257
-            }
258
-        }
259
-    }
260
-
261
-
262
-    /**
263
-     * Used to add data to eejs.data object.
264
-     * Note:  Overriding existing data is not allowed.
265
-     * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
266
-     * If the data you add is something like this:
267
-     *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
268
-     * It will be exposed in the page source as:
269
-     *  eejs.data.my_plugin_data.foo == gar
270
-     *
271
-     * @param string       $key   Key used to access your data
272
-     * @param string|array $value Value to attach to key
273
-     * @throws InvalidArgumentException
274
-     */
275
-    public function addData($key, $value)
276
-    {
277
-        if ($this->verifyDataNotExisting($key)) {
278
-            $this->jsdata[ $key ] = $value;
279
-        }
280
-    }
281
-
282
-
283
-    /**
284
-     * Similar to addData except this allows for users to push values to an existing key where the values on key are
285
-     * elements in an array.
286
-     *
287
-     * When you use this method, the value you include will be merged with the array on $key.
288
-     * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
289
-     * object like this, eejs.data.test = [ my_data,
290
-     * ]
291
-     * If there has already been a scalar value attached to the data object given key (via addData for instance), then
292
-     * this will throw an exception.
293
-     *
294
-     * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
295
-     * key potentially overriding the existing data on merge (specifically with associative arrays).
296
-     *
297
-     * @param string       $key   Key to attach data to.
298
-     * @param string|array $value Value being registered.
299
-     * @throws InvalidArgumentException
300
-     */
301
-    public function pushData($key, $value)
302
-    {
303
-        if (isset($this->jsdata[ $key ])
304
-            && ! is_array($this->jsdata[ $key ])
305
-        ) {
306
-            if (! $this->debug()) {
307
-                return;
308
-            }
309
-            throw new InvalidArgumentException(
310
-                sprintf(
311
-                    __(
312
-                        'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
29
+	const FILE_NAME_BUILD_MANIFEST = 'build-manifest.json';
30
+
31
+	/**
32
+	 * @var AssetCollection $assets
33
+	 */
34
+	protected $assets;
35
+
36
+	/**
37
+	 * @var I18nRegistry
38
+	 */
39
+	private $i18n_registry;
40
+
41
+	/**
42
+	 * This holds the jsdata data object that will be exposed on pages that enqueue the `eejs-core` script.
43
+	 *
44
+	 * @var array
45
+	 */
46
+	protected $jsdata = array();
47
+
48
+	/**
49
+	 * This keeps track of all scripts with registered data.  It is used to prevent duplicate data objects setup in the
50
+	 * page source.
51
+	 *
52
+	 * @var array
53
+	 */
54
+	private $script_handles_with_data = array();
55
+
56
+
57
+	/**
58
+	 * Holds the manifest data obtained from registered manifest files.
59
+	 * Manifests are maps of asset chunk name to actual built asset file names.
60
+	 * Shape of this array is:
61
+	 * array(
62
+	 *  'some_namespace_slug' => array(
63
+	 *      'some_chunk_name' => array(
64
+	 *          'js' => 'filename.js'
65
+	 *          'css' => 'filename.js'
66
+	 *      ),
67
+	 *      'url_base' => 'https://baseurl.com/to/assets
68
+	 *  )
69
+	 * )
70
+	 *
71
+	 * @var array
72
+	 */
73
+	private $manifest_data = array();
74
+
75
+
76
+	/**
77
+	 * Holds any dependency data obtained from registered dependency map json.
78
+	 * Dependency map json is generated via the @wordpress/dependency-extraction-webpack-plugin via the webpack config.
79
+	 * @see https://github.com/WordPress/gutenberg/tree/master/packages/dependency-extraction-webpack-plugin
80
+	 *
81
+	 * @var array
82
+	 */
83
+	private $dependencies_data = [];
84
+
85
+
86
+	/**
87
+	 * This is a known array of possible wp css handles that correspond to what may be exposed as dependencies in our
88
+	 * build process.  Currently the dependency export process in webpack does not consider css imports, so we derive
89
+	 * them via the js dependencies (WP uses the same handle for both js and css). This is a list of known handles that
90
+	 * are used for both js and css.
91
+	 * @var array
92
+	 */
93
+	private $wp_css_handle_dependencies = [
94
+		'wp-components',
95
+		'wp-block-editor',
96
+		'wp-block-library',
97
+		'wp-edit-post',
98
+		'wp-edit-widgets',
99
+		'wp-editor',
100
+		'wp-format-library',
101
+		'wp-list-reusable-blocks',
102
+		'wp-nux',
103
+	];
104
+
105
+
106
+	/**
107
+	 * Registry constructor.
108
+	 * Hooking into WP actions for script registry.
109
+	 *
110
+	 * @param AssetCollection      $assets
111
+	 * @param I18nRegistry         $i18n_registry
112
+	 * @throws InvalidArgumentException
113
+	 * @throws InvalidDataTypeException
114
+	 * @throws InvalidInterfaceException
115
+	 */
116
+	public function __construct(AssetCollection $assets, I18nRegistry $i18n_registry)
117
+	{
118
+		$this->assets = $assets;
119
+		$this->i18n_registry = $i18n_registry;
120
+		add_action('wp_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
121
+		add_action('admin_enqueue_scripts', array($this, 'registerManifestFiles'), 1);
122
+		add_action('wp_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
123
+		add_action('admin_enqueue_scripts', array($this, 'registerScriptsAndStyles'), 3);
124
+		add_action('wp_enqueue_scripts', array($this, 'enqueueData'), 4);
125
+		add_action('admin_enqueue_scripts', array($this, 'enqueueData'), 4);
126
+		add_action('wp_print_footer_scripts', array($this, 'enqueueData'), 1);
127
+		add_action('admin_print_footer_scripts', array($this, 'enqueueData'), 1);
128
+	}
129
+
130
+
131
+	/**
132
+	 * For classes that have Registry as a dependency, this provides a handy way to register script handles for i18n
133
+	 * translation handling.
134
+	 *
135
+	 * @return I18nRegistry
136
+	 */
137
+	public function getI18nRegistry()
138
+	{
139
+		return $this->i18n_registry;
140
+	}
141
+
142
+
143
+	/**
144
+	 * Callback for the wp_enqueue_scripts actions used to register assets.
145
+	 *
146
+	 * @since 4.9.62.p
147
+	 * @throws Exception
148
+	 */
149
+	public function registerScriptsAndStyles()
150
+	{
151
+		try {
152
+			$this->registerScripts($this->assets->getJavascriptAssets());
153
+			$this->registerStyles($this->assets->getStylesheetAssets());
154
+		} catch (Exception $exception) {
155
+			new ExceptionStackTraceDisplay($exception);
156
+		}
157
+	}
158
+
159
+
160
+	/**
161
+	 * Registers JS assets with WP core
162
+	 *
163
+	 * @param JavascriptAsset[] $scripts
164
+	 * @throws AssetRegistrationException
165
+	 * @throws InvalidDataTypeException
166
+	 * @throws DomainException
167
+	 * @since 4.9.62.p
168
+	 */
169
+	public function registerScripts(array $scripts)
170
+	{
171
+		foreach ($scripts as $script) {
172
+			// skip to next script if this has already been done
173
+			if ($script->isRegistered()) {
174
+				continue;
175
+			}
176
+			do_action(
177
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
178
+				$script
179
+			);
180
+			$registered = wp_register_script(
181
+				$script->handle(),
182
+				$script->source(),
183
+				$script->dependencies(),
184
+				$script->version(),
185
+				$script->loadInFooter()
186
+			);
187
+			if (! $registered && $this->debug()) {
188
+				throw new AssetRegistrationException($script->handle());
189
+			}
190
+			$script->setRegistered($registered);
191
+			if ($script->requiresTranslation()) {
192
+				$this->registerTranslation($script->handle());
193
+			}
194
+			do_action(
195
+				'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__after_script',
196
+				$script
197
+			);
198
+		}
199
+	}
200
+
201
+
202
+	/**
203
+	 * Registers CSS assets with WP core
204
+	 *
205
+	 * @param StylesheetAsset[] $styles
206
+	 * @throws InvalidDataTypeException
207
+	 * @throws DomainException
208
+	 * @since 4.9.62.p
209
+	 */
210
+	public function registerStyles(array $styles)
211
+	{
212
+		foreach ($styles as $style) {
213
+			// skip to next style if this has already been done
214
+			if ($style->isRegistered()) {
215
+				continue;
216
+			}
217
+			do_action(
218
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__before_style',
219
+				$style
220
+			);
221
+			wp_register_style(
222
+				$style->handle(),
223
+				$style->source(),
224
+				$style->dependencies(),
225
+				$style->version(),
226
+				$style->media()
227
+			);
228
+			$style->setRegistered();
229
+			do_action(
230
+				'AHEE__EventEspresso_core_services_assets_Registry__registerStyles__after_style',
231
+				$style
232
+			);
233
+		}
234
+	}
235
+
236
+
237
+	/**
238
+	 * Call back for the script print in frontend and backend.
239
+	 * Used to call wp_localize_scripts so that data can be added throughout the runtime until this later hook point.
240
+	 *
241
+	 * @since 4.9.31.rc.015
242
+	 */
243
+	public function enqueueData()
244
+	{
245
+		$this->removeAlreadyRegisteredDataForScriptHandles();
246
+		wp_add_inline_script(
247
+			'eejs-core',
248
+			'var eejsdata=' . wp_json_encode(array('data' => $this->jsdata)),
249
+			'before'
250
+		);
251
+		$scripts = $this->assets->getJavascriptAssetsWithData();
252
+		foreach ($scripts as $script) {
253
+			$this->addRegisteredScriptHandlesWithData($script->handle());
254
+			if ($script->hasInlineDataCallback()) {
255
+				$localize = $script->inlineDataCallback();
256
+				$localize();
257
+			}
258
+		}
259
+	}
260
+
261
+
262
+	/**
263
+	 * Used to add data to eejs.data object.
264
+	 * Note:  Overriding existing data is not allowed.
265
+	 * Data will be accessible as a javascript object when you list `eejs-core` as a dependency for your javascript.
266
+	 * If the data you add is something like this:
267
+	 *  $this->addData( 'my_plugin_data', array( 'foo' => 'gar' ) );
268
+	 * It will be exposed in the page source as:
269
+	 *  eejs.data.my_plugin_data.foo == gar
270
+	 *
271
+	 * @param string       $key   Key used to access your data
272
+	 * @param string|array $value Value to attach to key
273
+	 * @throws InvalidArgumentException
274
+	 */
275
+	public function addData($key, $value)
276
+	{
277
+		if ($this->verifyDataNotExisting($key)) {
278
+			$this->jsdata[ $key ] = $value;
279
+		}
280
+	}
281
+
282
+
283
+	/**
284
+	 * Similar to addData except this allows for users to push values to an existing key where the values on key are
285
+	 * elements in an array.
286
+	 *
287
+	 * When you use this method, the value you include will be merged with the array on $key.
288
+	 * So if the $key was 'test' and you added a value of ['my_data'] then it would be represented in the javascript
289
+	 * object like this, eejs.data.test = [ my_data,
290
+	 * ]
291
+	 * If there has already been a scalar value attached to the data object given key (via addData for instance), then
292
+	 * this will throw an exception.
293
+	 *
294
+	 * Caution: Only add data using this method if you are okay with the potential for additional data added on the same
295
+	 * key potentially overriding the existing data on merge (specifically with associative arrays).
296
+	 *
297
+	 * @param string       $key   Key to attach data to.
298
+	 * @param string|array $value Value being registered.
299
+	 * @throws InvalidArgumentException
300
+	 */
301
+	public function pushData($key, $value)
302
+	{
303
+		if (isset($this->jsdata[ $key ])
304
+			&& ! is_array($this->jsdata[ $key ])
305
+		) {
306
+			if (! $this->debug()) {
307
+				return;
308
+			}
309
+			throw new InvalidArgumentException(
310
+				sprintf(
311
+					__(
312
+						'The value for %1$s is already set and it is not an array. The %2$s method can only be used to
313 313
                          push values to this data element when it is an array.',
314
-                        'event_espresso'
315
-                    ),
316
-                    $key,
317
-                    __METHOD__
318
-                )
319
-            );
320
-        }
321
-        if ( ! isset( $this->jsdata[ $key ] ) ) {
322
-            $this->jsdata[ $key ] = is_array($value) ? $value : [$value];
323
-        } else {
324
-            $this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
325
-        }
326
-    }
327
-
328
-
329
-    /**
330
-     * Used to set content used by javascript for a template.
331
-     * Note: Overrides of existing registered templates are not allowed.
332
-     *
333
-     * @param string $template_reference
334
-     * @param string $template_content
335
-     * @throws InvalidArgumentException
336
-     */
337
-    public function addTemplate($template_reference, $template_content)
338
-    {
339
-        if (! isset($this->jsdata['templates'])) {
340
-            $this->jsdata['templates'] = array();
341
-        }
342
-        //no overrides allowed.
343
-        if (isset($this->jsdata['templates'][ $template_reference ])) {
344
-            if (! $this->debug()) {
345
-                return;
346
-            }
347
-            throw new InvalidArgumentException(
348
-                sprintf(
349
-                    __(
350
-                        'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
351
-                        'event_espresso'
352
-                    ),
353
-                    $template_reference
354
-                )
355
-            );
356
-        }
357
-        $this->jsdata['templates'][ $template_reference ] = $template_content;
358
-    }
359
-
360
-
361
-    /**
362
-     * Retrieve the template content already registered for the given reference.
363
-     *
364
-     * @param string $template_reference
365
-     * @return string
366
-     */
367
-    public function getTemplate($template_reference)
368
-    {
369
-        return isset($this->jsdata['templates'][ $template_reference ])
370
-            ? $this->jsdata['templates'][ $template_reference ]
371
-            : '';
372
-    }
373
-
374
-
375
-    /**
376
-     * Retrieve registered data.
377
-     *
378
-     * @param string $key Name of key to attach data to.
379
-     * @return mixed                If there is no for the given key, then false is returned.
380
-     */
381
-    public function getData($key)
382
-    {
383
-        return isset($this->jsdata[ $key ])
384
-            ? $this->jsdata[ $key ]
385
-            : false;
386
-    }
387
-
388
-
389
-    /**
390
-     * Verifies whether the given data exists already on the jsdata array.
391
-     * Overriding data is not allowed.
392
-     *
393
-     * @param string $key Index for data.
394
-     * @return bool        If valid then return true.
395
-     * @throws InvalidArgumentException if data already exists.
396
-     */
397
-    protected function verifyDataNotExisting($key)
398
-    {
399
-        if (isset($this->jsdata[ $key ])) {
400
-            if (! $this->debug()) {
401
-                return false;
402
-            }
403
-            if (is_array($this->jsdata[ $key ])) {
404
-                throw new InvalidArgumentException(
405
-                    sprintf(
406
-                        __(
407
-                            'The value for %1$s already exists in the Registry::eejs object.
314
+						'event_espresso'
315
+					),
316
+					$key,
317
+					__METHOD__
318
+				)
319
+			);
320
+		}
321
+		if ( ! isset( $this->jsdata[ $key ] ) ) {
322
+			$this->jsdata[ $key ] = is_array($value) ? $value : [$value];
323
+		} else {
324
+			$this->jsdata[ $key ] = array_merge( $this->jsdata[$key], (array) $value);
325
+		}
326
+	}
327
+
328
+
329
+	/**
330
+	 * Used to set content used by javascript for a template.
331
+	 * Note: Overrides of existing registered templates are not allowed.
332
+	 *
333
+	 * @param string $template_reference
334
+	 * @param string $template_content
335
+	 * @throws InvalidArgumentException
336
+	 */
337
+	public function addTemplate($template_reference, $template_content)
338
+	{
339
+		if (! isset($this->jsdata['templates'])) {
340
+			$this->jsdata['templates'] = array();
341
+		}
342
+		//no overrides allowed.
343
+		if (isset($this->jsdata['templates'][ $template_reference ])) {
344
+			if (! $this->debug()) {
345
+				return;
346
+			}
347
+			throw new InvalidArgumentException(
348
+				sprintf(
349
+					__(
350
+						'The %1$s key already exists for the templates array in the js data array.  No overrides are allowed.',
351
+						'event_espresso'
352
+					),
353
+					$template_reference
354
+				)
355
+			);
356
+		}
357
+		$this->jsdata['templates'][ $template_reference ] = $template_content;
358
+	}
359
+
360
+
361
+	/**
362
+	 * Retrieve the template content already registered for the given reference.
363
+	 *
364
+	 * @param string $template_reference
365
+	 * @return string
366
+	 */
367
+	public function getTemplate($template_reference)
368
+	{
369
+		return isset($this->jsdata['templates'][ $template_reference ])
370
+			? $this->jsdata['templates'][ $template_reference ]
371
+			: '';
372
+	}
373
+
374
+
375
+	/**
376
+	 * Retrieve registered data.
377
+	 *
378
+	 * @param string $key Name of key to attach data to.
379
+	 * @return mixed                If there is no for the given key, then false is returned.
380
+	 */
381
+	public function getData($key)
382
+	{
383
+		return isset($this->jsdata[ $key ])
384
+			? $this->jsdata[ $key ]
385
+			: false;
386
+	}
387
+
388
+
389
+	/**
390
+	 * Verifies whether the given data exists already on the jsdata array.
391
+	 * Overriding data is not allowed.
392
+	 *
393
+	 * @param string $key Index for data.
394
+	 * @return bool        If valid then return true.
395
+	 * @throws InvalidArgumentException if data already exists.
396
+	 */
397
+	protected function verifyDataNotExisting($key)
398
+	{
399
+		if (isset($this->jsdata[ $key ])) {
400
+			if (! $this->debug()) {
401
+				return false;
402
+			}
403
+			if (is_array($this->jsdata[ $key ])) {
404
+				throw new InvalidArgumentException(
405
+					sprintf(
406
+						__(
407
+							'The value for %1$s already exists in the Registry::eejs object.
408 408
                             Overrides are not allowed. Since the value of this data is an array, you may want to use the
409 409
                             %2$s method to push your value to the array.',
410
-                            'event_espresso'
411
-                        ),
412
-                        $key,
413
-                        'pushData()'
414
-                    )
415
-                );
416
-            }
417
-            throw new InvalidArgumentException(
418
-                sprintf(
419
-                    __(
420
-                        'The value for %1$s already exists in the Registry::eejs object. Overrides are not
410
+							'event_espresso'
411
+						),
412
+						$key,
413
+						'pushData()'
414
+					)
415
+				);
416
+			}
417
+			throw new InvalidArgumentException(
418
+				sprintf(
419
+					__(
420
+						'The value for %1$s already exists in the Registry::eejs object. Overrides are not
421 421
                         allowed.  Consider attaching your value to a different key',
422
-                        'event_espresso'
423
-                    ),
424
-                    $key
425
-                )
426
-            );
427
-        }
428
-        return true;
429
-    }
430
-
431
-
432
-    /**
433
-     * Get the actual asset path for asset manifests.
434
-     * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
435
-     *
436
-     * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
437
-     *                           asset file location.
438
-     * @param string $chunk_name
439
-     * @param string $asset_type
440
-     * @return string
441
-     * @since 4.9.59.p
442
-     */
443
-    public function getAssetUrl($namespace, $chunk_name, $asset_type)
444
-    {
445
-        $url = isset(
446
-            $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
447
-            $this->manifest_data[ $namespace ]['url_base']
448
-        )
449
-            ? $this->manifest_data[ $namespace ]['url_base']
450
-              . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
451
-            : $chunk_name;
452
-
453
-        return apply_filters(
454
-            'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
455
-            $url,
456
-            $namespace,
457
-            $chunk_name,
458
-            $asset_type
459
-        );
460
-    }
461
-
462
-
463
-
464
-    /**
465
-     * Return the url to a js file for the given namespace and chunk name.
466
-     *
467
-     * @param string $namespace
468
-     * @param string $chunk_name
469
-     * @return string
470
-     */
471
-    public function getJsUrl($namespace, $chunk_name)
472
-    {
473
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
474
-    }
475
-
476
-
477
-    /**
478
-     * Return the url to a css file for the given namespace and chunk name.
479
-     *
480
-     * @param string $namespace
481
-     * @param string $chunk_name
482
-     * @return string
483
-     */
484
-    public function getCssUrl($namespace, $chunk_name)
485
-    {
486
-        return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
487
-    }
488
-
489
-
490
-    /**
491
-     * Return the dependencies array and version string for a given asset $chunk_name
492
-     *
493
-     * @param string $namespace
494
-     * @param string $chunk_name
495
-     * @param string $asset_type
496
-     * @return array
497
-     * @since 4.9.82.p
498
-     */
499
-    private function getDetailsForAsset($namespace, $chunk_name, $asset_type)
500
-    {
501
-        $asset_index = $chunk_name . '.' . $asset_type;
502
-        if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
503
-            $path = isset($this->manifest_data[ $namespace ]['path'])
504
-                ? $this->manifest_data[ $namespace ]['path']
505
-                : '';
506
-            $dependencies_index = $chunk_name . '.' . Asset::TYPE_PHP;
507
-            $file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
508
-                ? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
509
-                :
510
-                '';
511
-            $this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
512
-                ? $this->getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
513
-                : [];
514
-        }
515
-        $details = $this->dependencies_data[ $namespace ][ $asset_index ];
516
-        return $details;
517
-    }
518
-
519
-
520
-    /**
521
-     * Return dependencies array and version string according to asset type.
522
-     * For css assets, this filters the auto generated dependencies by css type.
523
-     *
524
-     * @param string $namespace
525
-     * @param string $asset_type
526
-     * @param string $file_path
527
-     * @param string $chunk_name
528
-     * @return array
529
-     * @since 4.9.82.p
530
-     */
531
-    private function getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
532
-    {
533
-        // $asset_dependencies = json_decode(file_get_contents($file_path), true);
534
-        $asset_details = require($file_path);
535
-        $asset_details['dependencies'] = isset($asset_details['dependencies'])
536
-            ? $asset_details['dependencies']
537
-            : [];
538
-        $asset_details['version'] = isset($asset_details['version'])
539
-            ? $asset_details['version']
540
-            : '';
541
-        if ($asset_type === Asset::TYPE_JS) {
542
-            $asset_details['dependencies'] =  $chunk_name === 'eejs-core'
543
-                ? $asset_details['dependencies']
544
-                : $asset_details['dependencies'] + [ CoreAssetManager::JS_HANDLE_JS_CORE ];
545
-            return $asset_details;
546
-        }
547
-        // for css we need to make sure there is actually a css file related to this chunk.
548
-        if (isset($this->manifest_data[ $namespace ])) {
549
-            // array of css chunk files for ee.
550
-            $css_chunks = array_map(
551
-                static function ($value) {
552
-                    return str_replace('.css', '', $value);
553
-                },
554
-                array_filter(
555
-                    array_keys($this->manifest_data[ $namespace ]),
556
-                    static function ($value) {
557
-                        return strpos($value, '.css') !== false;
558
-                    }
559
-                )
560
-            );
561
-            // add known wp chunks with css
562
-            $css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
563
-            // flip for easier search
564
-            $css_chunks = array_flip($css_chunks);
565
-
566
-            // now let's filter the dependencies for the incoming chunk to actual chunks that have styles
567
-            $asset_details['dependencies'] = array_filter(
568
-                $asset_details['dependencies'],
569
-                static function ($chunk_name) use ($css_chunks) {
570
-                    return isset($css_chunks[ $chunk_name ]);
571
-                }
572
-            );
573
-            return $asset_details;
574
-        }
575
-        return ['dependencies' => [], 'version' => ''];
576
-    }
577
-
578
-
579
-    /**
580
-     * Get the dependencies array and version string for the given js asset chunk name
581
-     *
582
-     * @param string $namespace
583
-     * @param string $chunk_name
584
-     * @return array
585
-     * @since $VID:$
586
-     */
587
-    public function getJsAssetDetails($namespace, $chunk_name)
588
-    {
589
-        return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_JS);
590
-    }
591
-
592
-
593
-    /**
594
-     * Get the dependencies array and version string for the given css asset chunk name
595
-     *
596
-     * @param string $namespace
597
-     * @param string $chunk_name
598
-     * @return array
599
-     * @since $VID:$
600
-     */
601
-    public function getCssAssetDetails($namespace, $chunk_name)
602
-    {
603
-        return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
604
-    }
605
-
606
-
607
-    /**
608
-     * @since 4.9.62.p
609
-     * @throws InvalidArgumentException
610
-     * @throws InvalidFilePathException
611
-     */
612
-    public function registerManifestFiles()
613
-    {
614
-        $manifest_files = $this->assets->getManifestFiles();
615
-        foreach ($manifest_files as $manifest_file) {
616
-            $this->registerManifestFile(
617
-                $manifest_file->assetNamespace(),
618
-                $manifest_file->urlBase(),
619
-                $manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
620
-                $manifest_file->filepath()
621
-            );
622
-        }
623
-    }
624
-
625
-
626
-    /**
627
-     * Used to register a js/css manifest file with the registered_manifest_files property.
628
-     *
629
-     * @param string $namespace     Provided to associate the manifest file with a specific namespace.
630
-     * @param string $url_base      The url base for the manifest file location.
631
-     * @param string $manifest_file The absolute path to the manifest file.
632
-     * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
633
-     *                                    default to `plugin_root/assets/dist`.
634
-     * @throws InvalidArgumentException
635
-     * @throws InvalidFilePathException
636
-     * @since 4.9.59.p
637
-     */
638
-    public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
639
-    {
640
-        if (isset($this->manifest_data[ $namespace ])) {
641
-            if (! $this->debug()) {
642
-                return;
643
-            }
644
-            throw new InvalidArgumentException(
645
-                sprintf(
646
-                    esc_html__(
647
-                        'The namespace for this manifest file has already been registered, choose a namespace other than %s',
648
-                        'event_espresso'
649
-                    ),
650
-                    $namespace
651
-                )
652
-            );
653
-        }
654
-        if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
655
-            if (is_admin()) {
656
-                EE_Error::add_error(
657
-                    sprintf(
658
-                        esc_html__(
659
-                            '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',
660
-                            'event_espresso'
661
-                        ),
662
-                        'Event Espresso',
663
-                        $url_base,
664
-                        'plugins_url',
665
-                        'WP_PLUGIN_URL'
666
-                    ),
667
-                    __FILE__,
668
-                    __FUNCTION__,
669
-                    __LINE__
670
-                );
671
-            }
672
-            return;
673
-        }
674
-        $this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
675
-        if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
676
-            $this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
677
-        }
678
-        if (! isset($this->manifest_data[ $namespace ]['path'])) {
679
-            $this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
680
-        }
681
-    }
682
-
683
-
684
-    /**
685
-     * Decodes json from the provided manifest file.
686
-     *
687
-     * @since 4.9.59.p
688
-     * @param string $manifest_file Path to manifest file.
689
-     * @return array
690
-     * @throws InvalidFilePathException
691
-     */
692
-    private function decodeManifestFile($manifest_file)
693
-    {
694
-        if (! file_exists($manifest_file)) {
695
-            throw new InvalidFilePathException($manifest_file);
696
-        }
697
-        return json_decode(file_get_contents($manifest_file), true);
698
-    }
699
-
700
-
701
-    /**
702
-     * This is used to set registered script handles that have data.
703
-     *
704
-     * @param string $script_handle
705
-     */
706
-    private function addRegisteredScriptHandlesWithData($script_handle)
707
-    {
708
-        $this->script_handles_with_data[ $script_handle ] = $script_handle;
709
-    }
710
-
711
-
712
-    /**i
422
+						'event_espresso'
423
+					),
424
+					$key
425
+				)
426
+			);
427
+		}
428
+		return true;
429
+	}
430
+
431
+
432
+	/**
433
+	 * Get the actual asset path for asset manifests.
434
+	 * If there is no asset path found for the given $chunk_name, then the $chunk_name is returned.
435
+	 *
436
+	 * @param string $namespace  The namespace associated with the manifest file hosting the map of chunk_name to actual
437
+	 *                           asset file location.
438
+	 * @param string $chunk_name
439
+	 * @param string $asset_type
440
+	 * @return string
441
+	 * @since 4.9.59.p
442
+	 */
443
+	public function getAssetUrl($namespace, $chunk_name, $asset_type)
444
+	{
445
+		$url = isset(
446
+			$this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ],
447
+			$this->manifest_data[ $namespace ]['url_base']
448
+		)
449
+			? $this->manifest_data[ $namespace ]['url_base']
450
+			  . $this->manifest_data[ $namespace ][ $chunk_name . '.' . $asset_type ]
451
+			: $chunk_name;
452
+
453
+		return apply_filters(
454
+			'FHEE__EventEspresso_core_services_assets_Registry__getAssetUrl',
455
+			$url,
456
+			$namespace,
457
+			$chunk_name,
458
+			$asset_type
459
+		);
460
+	}
461
+
462
+
463
+
464
+	/**
465
+	 * Return the url to a js file for the given namespace and chunk name.
466
+	 *
467
+	 * @param string $namespace
468
+	 * @param string $chunk_name
469
+	 * @return string
470
+	 */
471
+	public function getJsUrl($namespace, $chunk_name)
472
+	{
473
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_JS);
474
+	}
475
+
476
+
477
+	/**
478
+	 * Return the url to a css file for the given namespace and chunk name.
479
+	 *
480
+	 * @param string $namespace
481
+	 * @param string $chunk_name
482
+	 * @return string
483
+	 */
484
+	public function getCssUrl($namespace, $chunk_name)
485
+	{
486
+		return $this->getAssetUrl($namespace, $chunk_name, Asset::TYPE_CSS);
487
+	}
488
+
489
+
490
+	/**
491
+	 * Return the dependencies array and version string for a given asset $chunk_name
492
+	 *
493
+	 * @param string $namespace
494
+	 * @param string $chunk_name
495
+	 * @param string $asset_type
496
+	 * @return array
497
+	 * @since 4.9.82.p
498
+	 */
499
+	private function getDetailsForAsset($namespace, $chunk_name, $asset_type)
500
+	{
501
+		$asset_index = $chunk_name . '.' . $asset_type;
502
+		if (! isset( $this->dependencies_data[ $namespace ][ $asset_index ])) {
503
+			$path = isset($this->manifest_data[ $namespace ]['path'])
504
+				? $this->manifest_data[ $namespace ]['path']
505
+				: '';
506
+			$dependencies_index = $chunk_name . '.' . Asset::TYPE_PHP;
507
+			$file_path = isset($this->manifest_data[ $namespace ][ $dependencies_index ])
508
+				? $path . $this->manifest_data[ $namespace ][ $dependencies_index ]
509
+				:
510
+				'';
511
+			$this->dependencies_data[ $namespace ][ $asset_index ] = $file_path !== '' && file_exists($file_path)
512
+				? $this->getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
513
+				: [];
514
+		}
515
+		$details = $this->dependencies_data[ $namespace ][ $asset_index ];
516
+		return $details;
517
+	}
518
+
519
+
520
+	/**
521
+	 * Return dependencies array and version string according to asset type.
522
+	 * For css assets, this filters the auto generated dependencies by css type.
523
+	 *
524
+	 * @param string $namespace
525
+	 * @param string $asset_type
526
+	 * @param string $file_path
527
+	 * @param string $chunk_name
528
+	 * @return array
529
+	 * @since 4.9.82.p
530
+	 */
531
+	private function getDetailsForAssetType($namespace, $asset_type, $file_path, $chunk_name)
532
+	{
533
+		// $asset_dependencies = json_decode(file_get_contents($file_path), true);
534
+		$asset_details = require($file_path);
535
+		$asset_details['dependencies'] = isset($asset_details['dependencies'])
536
+			? $asset_details['dependencies']
537
+			: [];
538
+		$asset_details['version'] = isset($asset_details['version'])
539
+			? $asset_details['version']
540
+			: '';
541
+		if ($asset_type === Asset::TYPE_JS) {
542
+			$asset_details['dependencies'] =  $chunk_name === 'eejs-core'
543
+				? $asset_details['dependencies']
544
+				: $asset_details['dependencies'] + [ CoreAssetManager::JS_HANDLE_JS_CORE ];
545
+			return $asset_details;
546
+		}
547
+		// for css we need to make sure there is actually a css file related to this chunk.
548
+		if (isset($this->manifest_data[ $namespace ])) {
549
+			// array of css chunk files for ee.
550
+			$css_chunks = array_map(
551
+				static function ($value) {
552
+					return str_replace('.css', '', $value);
553
+				},
554
+				array_filter(
555
+					array_keys($this->manifest_data[ $namespace ]),
556
+					static function ($value) {
557
+						return strpos($value, '.css') !== false;
558
+					}
559
+				)
560
+			);
561
+			// add known wp chunks with css
562
+			$css_chunks = array_merge( $css_chunks, $this->wp_css_handle_dependencies);
563
+			// flip for easier search
564
+			$css_chunks = array_flip($css_chunks);
565
+
566
+			// now let's filter the dependencies for the incoming chunk to actual chunks that have styles
567
+			$asset_details['dependencies'] = array_filter(
568
+				$asset_details['dependencies'],
569
+				static function ($chunk_name) use ($css_chunks) {
570
+					return isset($css_chunks[ $chunk_name ]);
571
+				}
572
+			);
573
+			return $asset_details;
574
+		}
575
+		return ['dependencies' => [], 'version' => ''];
576
+	}
577
+
578
+
579
+	/**
580
+	 * Get the dependencies array and version string for the given js asset chunk name
581
+	 *
582
+	 * @param string $namespace
583
+	 * @param string $chunk_name
584
+	 * @return array
585
+	 * @since $VID:$
586
+	 */
587
+	public function getJsAssetDetails($namespace, $chunk_name)
588
+	{
589
+		return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_JS);
590
+	}
591
+
592
+
593
+	/**
594
+	 * Get the dependencies array and version string for the given css asset chunk name
595
+	 *
596
+	 * @param string $namespace
597
+	 * @param string $chunk_name
598
+	 * @return array
599
+	 * @since $VID:$
600
+	 */
601
+	public function getCssAssetDetails($namespace, $chunk_name)
602
+	{
603
+		return $this->getDetailsForAsset($namespace, $chunk_name, Asset::TYPE_CSS);
604
+	}
605
+
606
+
607
+	/**
608
+	 * @since 4.9.62.p
609
+	 * @throws InvalidArgumentException
610
+	 * @throws InvalidFilePathException
611
+	 */
612
+	public function registerManifestFiles()
613
+	{
614
+		$manifest_files = $this->assets->getManifestFiles();
615
+		foreach ($manifest_files as $manifest_file) {
616
+			$this->registerManifestFile(
617
+				$manifest_file->assetNamespace(),
618
+				$manifest_file->urlBase(),
619
+				$manifest_file->filepath() . Registry::FILE_NAME_BUILD_MANIFEST,
620
+				$manifest_file->filepath()
621
+			);
622
+		}
623
+	}
624
+
625
+
626
+	/**
627
+	 * Used to register a js/css manifest file with the registered_manifest_files property.
628
+	 *
629
+	 * @param string $namespace     Provided to associate the manifest file with a specific namespace.
630
+	 * @param string $url_base      The url base for the manifest file location.
631
+	 * @param string $manifest_file The absolute path to the manifest file.
632
+	 * @param string $manifest_file_path  The path to the folder containing the manifest file. If not provided will be
633
+	 *                                    default to `plugin_root/assets/dist`.
634
+	 * @throws InvalidArgumentException
635
+	 * @throws InvalidFilePathException
636
+	 * @since 4.9.59.p
637
+	 */
638
+	public function registerManifestFile($namespace, $url_base, $manifest_file, $manifest_file_path = '')
639
+	{
640
+		if (isset($this->manifest_data[ $namespace ])) {
641
+			if (! $this->debug()) {
642
+				return;
643
+			}
644
+			throw new InvalidArgumentException(
645
+				sprintf(
646
+					esc_html__(
647
+						'The namespace for this manifest file has already been registered, choose a namespace other than %s',
648
+						'event_espresso'
649
+					),
650
+					$namespace
651
+				)
652
+			);
653
+		}
654
+		if (filter_var($url_base, FILTER_VALIDATE_URL) === false) {
655
+			if (is_admin()) {
656
+				EE_Error::add_error(
657
+					sprintf(
658
+						esc_html__(
659
+							'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',
660
+							'event_espresso'
661
+						),
662
+						'Event Espresso',
663
+						$url_base,
664
+						'plugins_url',
665
+						'WP_PLUGIN_URL'
666
+					),
667
+					__FILE__,
668
+					__FUNCTION__,
669
+					__LINE__
670
+				);
671
+			}
672
+			return;
673
+		}
674
+		$this->manifest_data[ $namespace ] = $this->decodeManifestFile($manifest_file);
675
+		if (! isset($this->manifest_data[ $namespace ]['url_base'])) {
676
+			$this->manifest_data[ $namespace ]['url_base'] = trailingslashit($url_base);
677
+		}
678
+		if (! isset($this->manifest_data[ $namespace ]['path'])) {
679
+			$this->manifest_data[ $namespace ]['path'] = $manifest_file_path;
680
+		}
681
+	}
682
+
683
+
684
+	/**
685
+	 * Decodes json from the provided manifest file.
686
+	 *
687
+	 * @since 4.9.59.p
688
+	 * @param string $manifest_file Path to manifest file.
689
+	 * @return array
690
+	 * @throws InvalidFilePathException
691
+	 */
692
+	private function decodeManifestFile($manifest_file)
693
+	{
694
+		if (! file_exists($manifest_file)) {
695
+			throw new InvalidFilePathException($manifest_file);
696
+		}
697
+		return json_decode(file_get_contents($manifest_file), true);
698
+	}
699
+
700
+
701
+	/**
702
+	 * This is used to set registered script handles that have data.
703
+	 *
704
+	 * @param string $script_handle
705
+	 */
706
+	private function addRegisteredScriptHandlesWithData($script_handle)
707
+	{
708
+		$this->script_handles_with_data[ $script_handle ] = $script_handle;
709
+	}
710
+
711
+
712
+	/**i
713 713
      * Checks WP_Scripts for all of each script handle registered internally as having data and unsets from the
714 714
      * Dependency stored in WP_Scripts if its set.
715 715
      */
716
-    private function removeAlreadyRegisteredDataForScriptHandles()
717
-    {
718
-        if (empty($this->script_handles_with_data)) {
719
-            return;
720
-        }
721
-        foreach ($this->script_handles_with_data as $script_handle) {
722
-            $this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
723
-        }
724
-    }
725
-
726
-
727
-    /**
728
-     * Removes any data dependency registered in WP_Scripts if its set.
729
-     *
730
-     * @param string $script_handle
731
-     */
732
-    private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
733
-    {
734
-        if (isset($this->script_handles_with_data[ $script_handle ])) {
735
-            global $wp_scripts;
736
-            $unset_handle = false;
737
-            if ($wp_scripts->get_data($script_handle, 'data')) {
738
-                unset($wp_scripts->registered[ $script_handle ]->extra['data']);
739
-                $unset_handle = true;
740
-            }
741
-            //deal with inline_scripts
742
-            if ($wp_scripts->get_data($script_handle, 'before')) {
743
-                unset($wp_scripts->registered[ $script_handle ]->extra['before']);
744
-                $unset_handle = true;
745
-            }
746
-            if ($wp_scripts->get_data($script_handle, 'after')) {
747
-                unset($wp_scripts->registered[ $script_handle ]->extra['after']);
748
-            }
749
-            if ($unset_handle) {
750
-                unset($this->script_handles_with_data[ $script_handle ]);
751
-            }
752
-        }
753
-    }
754
-
755
-
756
-    /**
757
-     * register translations for a registered script
758
-     *
759
-     * @param string $handle
760
-     */
761
-    public function registerTranslation($handle)
762
-    {
763
-        $this->i18n_registry->registerScriptI18n($handle);
764
-    }
765
-
766
-
767
-    /**
768
-     * @since 4.9.63.p
769
-     * @return bool
770
-     */
771
-    private function debug()
772
-    {
773
-        return apply_filters(
774
-            'FHEE__EventEspresso_core_services_assets_Registry__debug',
775
-            defined('EE_DEBUG') && EE_DEBUG
776
-        );
777
-    }
778
-
779
-
780
-    /**
781
-     * Get the dependencies array for the given js asset chunk name
782
-     *
783
-     * @param string $namespace
784
-     * @param string $chunk_name
785
-     * @return array
786
-     * @deprecated $VID:$
787
-     * @since 4.9.82.p
788
-     */
789
-    public function getJsDependencies($namespace, $chunk_name)
790
-    {
791
-        $details = $this->getJsAssetDetails($namespace, $chunk_name);
792
-        return isset($details['dependencies']) ? $details['dependencies'] : [];
793
-    }
794
-
795
-
796
-    /**
797
-     * Get the dependencies array for the given css asset chunk name
798
-     *
799
-     * @param string $namespace
800
-     * @param string $chunk_name
801
-     * @return array
802
-     * @deprecated $VID:$
803
-     * @since      4.9.82.p
804
-     */
805
-    public function getCssDependencies($namespace, $chunk_name)
806
-    {
807
-        $details = $this->getCssAssetDetails($namespace, $chunk_name);
808
-        return isset($details['dependencies']) ? $details['dependencies'] : [];
809
-    }
716
+	private function removeAlreadyRegisteredDataForScriptHandles()
717
+	{
718
+		if (empty($this->script_handles_with_data)) {
719
+			return;
720
+		}
721
+		foreach ($this->script_handles_with_data as $script_handle) {
722
+			$this->removeAlreadyRegisteredDataForScriptHandle($script_handle);
723
+		}
724
+	}
725
+
726
+
727
+	/**
728
+	 * Removes any data dependency registered in WP_Scripts if its set.
729
+	 *
730
+	 * @param string $script_handle
731
+	 */
732
+	private function removeAlreadyRegisteredDataForScriptHandle($script_handle)
733
+	{
734
+		if (isset($this->script_handles_with_data[ $script_handle ])) {
735
+			global $wp_scripts;
736
+			$unset_handle = false;
737
+			if ($wp_scripts->get_data($script_handle, 'data')) {
738
+				unset($wp_scripts->registered[ $script_handle ]->extra['data']);
739
+				$unset_handle = true;
740
+			}
741
+			//deal with inline_scripts
742
+			if ($wp_scripts->get_data($script_handle, 'before')) {
743
+				unset($wp_scripts->registered[ $script_handle ]->extra['before']);
744
+				$unset_handle = true;
745
+			}
746
+			if ($wp_scripts->get_data($script_handle, 'after')) {
747
+				unset($wp_scripts->registered[ $script_handle ]->extra['after']);
748
+			}
749
+			if ($unset_handle) {
750
+				unset($this->script_handles_with_data[ $script_handle ]);
751
+			}
752
+		}
753
+	}
754
+
755
+
756
+	/**
757
+	 * register translations for a registered script
758
+	 *
759
+	 * @param string $handle
760
+	 */
761
+	public function registerTranslation($handle)
762
+	{
763
+		$this->i18n_registry->registerScriptI18n($handle);
764
+	}
765
+
766
+
767
+	/**
768
+	 * @since 4.9.63.p
769
+	 * @return bool
770
+	 */
771
+	private function debug()
772
+	{
773
+		return apply_filters(
774
+			'FHEE__EventEspresso_core_services_assets_Registry__debug',
775
+			defined('EE_DEBUG') && EE_DEBUG
776
+		);
777
+	}
778
+
779
+
780
+	/**
781
+	 * Get the dependencies array for the given js asset chunk name
782
+	 *
783
+	 * @param string $namespace
784
+	 * @param string $chunk_name
785
+	 * @return array
786
+	 * @deprecated $VID:$
787
+	 * @since 4.9.82.p
788
+	 */
789
+	public function getJsDependencies($namespace, $chunk_name)
790
+	{
791
+		$details = $this->getJsAssetDetails($namespace, $chunk_name);
792
+		return isset($details['dependencies']) ? $details['dependencies'] : [];
793
+	}
794
+
795
+
796
+	/**
797
+	 * Get the dependencies array for the given css asset chunk name
798
+	 *
799
+	 * @param string $namespace
800
+	 * @param string $chunk_name
801
+	 * @return array
802
+	 * @deprecated $VID:$
803
+	 * @since      4.9.82.p
804
+	 */
805
+	public function getCssDependencies($namespace, $chunk_name)
806
+	{
807
+		$details = $this->getCssAssetDetails($namespace, $chunk_name);
808
+		return isset($details['dependencies']) ? $details['dependencies'] : [];
809
+	}
810 810
 }
Please login to merge, or discard this patch.
core/domain/values/assets/Asset.php 1 patch
Indentation   +164 added lines, -164 removed lines patch added patch discarded remove patch
@@ -16,168 +16,168 @@
 block discarded – undo
16 16
 abstract class Asset
17 17
 {
18 18
 
19
-    /**
20
-     * indicates the file extension for a build distribution CSS file
21
-     */
22
-    const FILE_EXTENSION_DISTRIBUTION_CSS = '.dist.css';
23
-
24
-    /**
25
-     * indicates the file extension for a build distribution JS file
26
-     */
27
-    const FILE_EXTENSION_DISTRIBUTION_JS = '.dist.js';
28
-
29
-    /**
30
-     * Indicates the file extension for a build distribution dependencies json file.
31
-     */
32
-    const FILE_EXTENSION_DISTRIBUTION_DEPS = '.dist.deps.php';
33
-
34
-    /**
35
-     * indicates a Cascading Style Sheet asset
36
-     */
37
-    const TYPE_CSS = 'css';
38
-
39
-    /**
40
-     * indicates a Javascript asset
41
-     */
42
-    const TYPE_JS = 'js';
43
-
44
-    /**
45
-     * indicates a JSON asset
46
-     */
47
-    CONST TYPE_JSON = 'json';
48
-    /**
49
-     * indicates a PHP asset
50
-     */
51
-    CONST TYPE_PHP = 'php';
52
-
53
-    /**
54
-     * indicates a Javascript manifest file
55
-     */
56
-    const TYPE_MANIFEST = 'manifest';
57
-
58
-    /**
59
-     * @var DomainInterface $domain
60
-     */
61
-    protected $domain;
62
-
63
-    /**
64
-     * @var string $type
65
-     */
66
-    private $type;
67
-
68
-    /**
69
-     * @var string $handle
70
-     */
71
-    private $handle;
72
-
73
-    /**
74
-     * @var bool $registered
75
-     */
76
-    private $registered = false;
77
-
78
-
79
-    /**
80
-     * Asset constructor.
81
-     *
82
-     * @param                 $type
83
-     * @param string          $handle
84
-     * @param DomainInterface $domain
85
-     * @throws InvalidDataTypeException
86
-     */
87
-    public function __construct($type, $handle, DomainInterface $domain)
88
-    {
89
-        $this->domain = $domain;
90
-        $this->setType($type);
91
-        $this->setHandle($handle);
92
-    }
93
-
94
-
95
-    /**
96
-     * @return array
97
-     */
98
-    public function validAssetTypes()
99
-    {
100
-        return array(
101
-            Asset::TYPE_CSS,
102
-            Asset::TYPE_JS,
103
-            Asset::TYPE_MANIFEST,
104
-        );
105
-    }
106
-
107
-
108
-    /**
109
-     * @param string $type
110
-     * @throws InvalidDataTypeException
111
-     */
112
-    private function setType($type)
113
-    {
114
-        if (! in_array($type, $this->validAssetTypes(), true)) {
115
-            throw new InvalidDataTypeException(
116
-                'Asset::$type',
117
-                $type,
118
-                'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required'
119
-            );
120
-        }
121
-        $this->type = $type;
122
-    }
123
-
124
-
125
-    /**
126
-     * @param string $handle
127
-     * @throws InvalidDataTypeException
128
-     */
129
-    private function setHandle($handle)
130
-    {
131
-        if (! is_string($handle)) {
132
-            throw new InvalidDataTypeException(
133
-                '$handle',
134
-                $handle,
135
-                'string'
136
-            );
137
-        }
138
-        $this->handle = $handle;
139
-    }
140
-
141
-
142
-    /**
143
-     * @return string
144
-     */
145
-    public function assetNamespace()
146
-    {
147
-        return $this->domain->assetNamespace();
148
-    }
149
-
150
-
151
-    /**
152
-     * @return string
153
-     */
154
-    public function type()
155
-    {
156
-        return $this->type;
157
-    }
158
-
159
-
160
-    /**
161
-     * @return string
162
-     */
163
-    public function handle()
164
-    {
165
-        return $this->handle;
166
-    }
167
-
168
-    /**
169
-     * @return bool
170
-     */
171
-    public function isRegistered()
172
-    {
173
-        return $this->registered;
174
-    }
175
-
176
-    /**
177
-     * @param bool $registered
178
-     */
179
-    public function setRegistered($registered = true)
180
-    {
181
-        $this->registered = filter_var($registered, FILTER_VALIDATE_BOOLEAN);
182
-    }
19
+	/**
20
+	 * indicates the file extension for a build distribution CSS file
21
+	 */
22
+	const FILE_EXTENSION_DISTRIBUTION_CSS = '.dist.css';
23
+
24
+	/**
25
+	 * indicates the file extension for a build distribution JS file
26
+	 */
27
+	const FILE_EXTENSION_DISTRIBUTION_JS = '.dist.js';
28
+
29
+	/**
30
+	 * Indicates the file extension for a build distribution dependencies json file.
31
+	 */
32
+	const FILE_EXTENSION_DISTRIBUTION_DEPS = '.dist.deps.php';
33
+
34
+	/**
35
+	 * indicates a Cascading Style Sheet asset
36
+	 */
37
+	const TYPE_CSS = 'css';
38
+
39
+	/**
40
+	 * indicates a Javascript asset
41
+	 */
42
+	const TYPE_JS = 'js';
43
+
44
+	/**
45
+	 * indicates a JSON asset
46
+	 */
47
+	CONST TYPE_JSON = 'json';
48
+	/**
49
+	 * indicates a PHP asset
50
+	 */
51
+	CONST TYPE_PHP = 'php';
52
+
53
+	/**
54
+	 * indicates a Javascript manifest file
55
+	 */
56
+	const TYPE_MANIFEST = 'manifest';
57
+
58
+	/**
59
+	 * @var DomainInterface $domain
60
+	 */
61
+	protected $domain;
62
+
63
+	/**
64
+	 * @var string $type
65
+	 */
66
+	private $type;
67
+
68
+	/**
69
+	 * @var string $handle
70
+	 */
71
+	private $handle;
72
+
73
+	/**
74
+	 * @var bool $registered
75
+	 */
76
+	private $registered = false;
77
+
78
+
79
+	/**
80
+	 * Asset constructor.
81
+	 *
82
+	 * @param                 $type
83
+	 * @param string          $handle
84
+	 * @param DomainInterface $domain
85
+	 * @throws InvalidDataTypeException
86
+	 */
87
+	public function __construct($type, $handle, DomainInterface $domain)
88
+	{
89
+		$this->domain = $domain;
90
+		$this->setType($type);
91
+		$this->setHandle($handle);
92
+	}
93
+
94
+
95
+	/**
96
+	 * @return array
97
+	 */
98
+	public function validAssetTypes()
99
+	{
100
+		return array(
101
+			Asset::TYPE_CSS,
102
+			Asset::TYPE_JS,
103
+			Asset::TYPE_MANIFEST,
104
+		);
105
+	}
106
+
107
+
108
+	/**
109
+	 * @param string $type
110
+	 * @throws InvalidDataTypeException
111
+	 */
112
+	private function setType($type)
113
+	{
114
+		if (! in_array($type, $this->validAssetTypes(), true)) {
115
+			throw new InvalidDataTypeException(
116
+				'Asset::$type',
117
+				$type,
118
+				'one of the TYPE_* class constants on \EventEspresso\core\domain\values\Asset is required'
119
+			);
120
+		}
121
+		$this->type = $type;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @param string $handle
127
+	 * @throws InvalidDataTypeException
128
+	 */
129
+	private function setHandle($handle)
130
+	{
131
+		if (! is_string($handle)) {
132
+			throw new InvalidDataTypeException(
133
+				'$handle',
134
+				$handle,
135
+				'string'
136
+			);
137
+		}
138
+		$this->handle = $handle;
139
+	}
140
+
141
+
142
+	/**
143
+	 * @return string
144
+	 */
145
+	public function assetNamespace()
146
+	{
147
+		return $this->domain->assetNamespace();
148
+	}
149
+
150
+
151
+	/**
152
+	 * @return string
153
+	 */
154
+	public function type()
155
+	{
156
+		return $this->type;
157
+	}
158
+
159
+
160
+	/**
161
+	 * @return string
162
+	 */
163
+	public function handle()
164
+	{
165
+		return $this->handle;
166
+	}
167
+
168
+	/**
169
+	 * @return bool
170
+	 */
171
+	public function isRegistered()
172
+	{
173
+		return $this->registered;
174
+	}
175
+
176
+	/**
177
+	 * @param bool $registered
178
+	 */
179
+	public function setRegistered($registered = true)
180
+	{
181
+		$this->registered = filter_var($registered, FILTER_VALIDATE_BOOLEAN);
182
+	}
183 183
 }
Please login to merge, or discard this patch.
core/domain/values/assets/BrowserAsset.php 2 patches
Indentation   +144 added lines, -144 removed lines patch added patch discarded remove patch
@@ -17,148 +17,148 @@
 block discarded – undo
17 17
 abstract class BrowserAsset extends Asset
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $source
22
-     */
23
-    private $source;
24
-
25
-    /**
26
-     * @var array $dependencies
27
-     */
28
-    private $dependencies;
29
-
30
-    /**
31
-     * @var string $version
32
-     */
33
-    private $version;
34
-
35
-
36
-    /**
37
-     * Asset constructor.
38
-     *
39
-     * @param string          $type
40
-     * @param string          $handle
41
-     * @param string          $source
42
-     * @param array           $dependencies
43
-     * @param DomainInterface $domain
44
-     * @param string          $version
45
-     * @throws DomainException
46
-     * @throws InvalidDataTypeException
47
-     */
48
-    public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain, $version = '')
49
-    {
50
-        parent::__construct($type, $handle, $domain);
51
-        $this->setSource($source);
52
-        $this->setDependencies($dependencies);
53
-        $this->setVersion($version, false);
54
-    }
55
-
56
-
57
-    /**
58
-     * @since 4.9.62.p
59
-     */
60
-    abstract public function enqueueAsset();
61
-
62
-
63
-    /**
64
-     * @return array
65
-     */
66
-    public function dependencies()
67
-    {
68
-        return $this->dependencies;
69
-    }
70
-
71
-
72
-    /**
73
-     * @param array $dependencies
74
-     */
75
-    private function setDependencies(array $dependencies)
76
-    {
77
-        $this->dependencies = $dependencies;
78
-    }
79
-
80
-
81
-    /**
82
-     * @since 4.9.62.p
83
-     * @return bool
84
-     */
85
-    public function hasDependencies()
86
-    {
87
-        return count($this->dependencies) > 0;
88
-    }
89
-
90
-
91
-    /**
92
-     * @return string
93
-     */
94
-    public function source()
95
-    {
96
-        return $this->source;
97
-    }
98
-
99
-
100
-    /**
101
-     * @param string $source
102
-     * @throws InvalidDataTypeException
103
-     */
104
-    private function setSource($source)
105
-    {
106
-        if (! is_string($source)) {
107
-            throw new InvalidDataTypeException(
108
-                '$source',
109
-                $source,
110
-                'string'
111
-            );
112
-        }
113
-        $this->source = $source;
114
-    }
115
-
116
-
117
-    /**
118
-     * @return string
119
-     * @throws InvalidDataTypeException
120
-     * @throws DomainException
121
-     */
122
-    public function version()
123
-    {
124
-        return $this->version;
125
-    }
126
-
127
-
128
-    /**
129
-     * @param string $version
130
-     * @param bool   $fluent
131
-     * @return BrowserAsset|null
132
-     * @throws DomainException
133
-     * @throws InvalidDataTypeException
134
-     */
135
-    public function setVersion($version, $fluent = true)
136
-    {
137
-        // if version is NOT set and this asset was NOT built for distribution,
138
-        // then set the version equal to the EE core plugin version
139
-        if (empty($version) && ! $this->isBuiltDistributionSource()) {
140
-            $version = $this->domain->version();
141
-        }
142
-        if (! is_string($version)) {
143
-            throw new InvalidDataTypeException(
144
-                '$version',
145
-                $version,
146
-                'string'
147
-            );
148
-        }
149
-        $this->version = $version;
150
-        if ($fluent) {
151
-            return $this;
152
-        }
153
-        return null;
154
-    }
155
-
156
-
157
-    /**
158
-     * @return bool
159
-     */
160
-    public function isBuiltDistributionSource() {
161
-        return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS
162
-               || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS;
163
-    }
20
+	/**
21
+	 * @var string $source
22
+	 */
23
+	private $source;
24
+
25
+	/**
26
+	 * @var array $dependencies
27
+	 */
28
+	private $dependencies;
29
+
30
+	/**
31
+	 * @var string $version
32
+	 */
33
+	private $version;
34
+
35
+
36
+	/**
37
+	 * Asset constructor.
38
+	 *
39
+	 * @param string          $type
40
+	 * @param string          $handle
41
+	 * @param string          $source
42
+	 * @param array           $dependencies
43
+	 * @param DomainInterface $domain
44
+	 * @param string          $version
45
+	 * @throws DomainException
46
+	 * @throws InvalidDataTypeException
47
+	 */
48
+	public function __construct($type, $handle, $source, array $dependencies, DomainInterface $domain, $version = '')
49
+	{
50
+		parent::__construct($type, $handle, $domain);
51
+		$this->setSource($source);
52
+		$this->setDependencies($dependencies);
53
+		$this->setVersion($version, false);
54
+	}
55
+
56
+
57
+	/**
58
+	 * @since 4.9.62.p
59
+	 */
60
+	abstract public function enqueueAsset();
61
+
62
+
63
+	/**
64
+	 * @return array
65
+	 */
66
+	public function dependencies()
67
+	{
68
+		return $this->dependencies;
69
+	}
70
+
71
+
72
+	/**
73
+	 * @param array $dependencies
74
+	 */
75
+	private function setDependencies(array $dependencies)
76
+	{
77
+		$this->dependencies = $dependencies;
78
+	}
79
+
80
+
81
+	/**
82
+	 * @since 4.9.62.p
83
+	 * @return bool
84
+	 */
85
+	public function hasDependencies()
86
+	{
87
+		return count($this->dependencies) > 0;
88
+	}
89
+
90
+
91
+	/**
92
+	 * @return string
93
+	 */
94
+	public function source()
95
+	{
96
+		return $this->source;
97
+	}
98
+
99
+
100
+	/**
101
+	 * @param string $source
102
+	 * @throws InvalidDataTypeException
103
+	 */
104
+	private function setSource($source)
105
+	{
106
+		if (! is_string($source)) {
107
+			throw new InvalidDataTypeException(
108
+				'$source',
109
+				$source,
110
+				'string'
111
+			);
112
+		}
113
+		$this->source = $source;
114
+	}
115
+
116
+
117
+	/**
118
+	 * @return string
119
+	 * @throws InvalidDataTypeException
120
+	 * @throws DomainException
121
+	 */
122
+	public function version()
123
+	{
124
+		return $this->version;
125
+	}
126
+
127
+
128
+	/**
129
+	 * @param string $version
130
+	 * @param bool   $fluent
131
+	 * @return BrowserAsset|null
132
+	 * @throws DomainException
133
+	 * @throws InvalidDataTypeException
134
+	 */
135
+	public function setVersion($version, $fluent = true)
136
+	{
137
+		// if version is NOT set and this asset was NOT built for distribution,
138
+		// then set the version equal to the EE core plugin version
139
+		if (empty($version) && ! $this->isBuiltDistributionSource()) {
140
+			$version = $this->domain->version();
141
+		}
142
+		if (! is_string($version)) {
143
+			throw new InvalidDataTypeException(
144
+				'$version',
145
+				$version,
146
+				'string'
147
+			);
148
+		}
149
+		$this->version = $version;
150
+		if ($fluent) {
151
+			return $this;
152
+		}
153
+		return null;
154
+	}
155
+
156
+
157
+	/**
158
+	 * @return bool
159
+	 */
160
+	public function isBuiltDistributionSource() {
161
+		return substr($this->source, -8) === Asset::FILE_EXTENSION_DISTRIBUTION_JS
162
+			   || substr($this->source, -9) === Asset::FILE_EXTENSION_DISTRIBUTION_CSS;
163
+	}
164 164
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -103,7 +103,7 @@  discard block
 block discarded – undo
103 103
      */
104 104
     private function setSource($source)
105 105
     {
106
-        if (! is_string($source)) {
106
+        if ( ! is_string($source)) {
107 107
             throw new InvalidDataTypeException(
108 108
                 '$source',
109 109
                 $source,
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
         if (empty($version) && ! $this->isBuiltDistributionSource()) {
140 140
             $version = $this->domain->version();
141 141
         }
142
-        if (! is_string($version)) {
142
+        if ( ! is_string($version)) {
143 143
             throw new InvalidDataTypeException(
144 144
                 '$version',
145 145
                 $version,
Please login to merge, or discard this patch.
core/domain/values/assets/StylesheetAsset.php 1 patch
Indentation   +56 added lines, -56 removed lines patch added patch discarded remove patch
@@ -17,68 +17,68 @@
 block discarded – undo
17 17
 class StylesheetAsset extends BrowserAsset
18 18
 {
19 19
 
20
-    /**
21
-     * @var string $media
22
-     */
23
-    private $media;
20
+	/**
21
+	 * @var string $media
22
+	 */
23
+	private $media;
24 24
 
25 25
 
26
-    /**
27
-     * CssFile constructor.
28
-     *
29
-     * @param                 $handle
30
-     * @param string          $source
31
-     * @param array           $dependencies
32
-     * @param DomainInterface $domain
33
-     * @param string          $media
34
-     * @param string          $version
35
-     * @throws InvalidDataTypeException
36
-     * @throws DomainException
37
-     */
38
-    public function __construct(
39
-        $handle,
40
-        $source,
41
-        array $dependencies,
42
-        DomainInterface $domain,
43
-        $media = 'all',
44
-        $version = ''
45
-    ) {
46
-        parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain, $version);
47
-        $this->setMedia($media);
48
-    }
26
+	/**
27
+	 * CssFile constructor.
28
+	 *
29
+	 * @param                 $handle
30
+	 * @param string          $source
31
+	 * @param array           $dependencies
32
+	 * @param DomainInterface $domain
33
+	 * @param string          $media
34
+	 * @param string          $version
35
+	 * @throws InvalidDataTypeException
36
+	 * @throws DomainException
37
+	 */
38
+	public function __construct(
39
+		$handle,
40
+		$source,
41
+		array $dependencies,
42
+		DomainInterface $domain,
43
+		$media = 'all',
44
+		$version = ''
45
+	) {
46
+		parent::__construct(Asset::TYPE_CSS, $handle, $source, $dependencies, $domain, $version);
47
+		$this->setMedia($media);
48
+	}
49 49
 
50 50
 
51
-    /**
52
-     * @return string
53
-     */
54
-    public function media()
55
-    {
56
-        return $this->media;
57
-    }
51
+	/**
52
+	 * @return string
53
+	 */
54
+	public function media()
55
+	{
56
+		return $this->media;
57
+	}
58 58
 
59 59
 
60
-    /**
61
-     * @param string $media
62
-     * @throws InvalidDataTypeException
63
-     */
64
-    private function setMedia($media)
65
-    {
66
-        if (! is_string($media)) {
67
-            throw new InvalidDataTypeException(
68
-                '$media',
69
-                $media,
70
-                'string'
71
-            );
72
-        }
73
-        $this->media = $media;
74
-    }
60
+	/**
61
+	 * @param string $media
62
+	 * @throws InvalidDataTypeException
63
+	 */
64
+	private function setMedia($media)
65
+	{
66
+		if (! is_string($media)) {
67
+			throw new InvalidDataTypeException(
68
+				'$media',
69
+				$media,
70
+				'string'
71
+			);
72
+		}
73
+		$this->media = $media;
74
+	}
75 75
 
76 76
 
77
-    /**
78
-     * @since 4.9.62.p
79
-     */
80
-    public function enqueueAsset()
81
-    {
82
-        wp_enqueue_style($this->handle());
83
-    }
77
+	/**
78
+	 * @since 4.9.62.p
79
+	 */
80
+	public function enqueueAsset()
81
+	{
82
+		wp_enqueue_style($this->handle());
83
+	}
84 84
 }
Please login to merge, or discard this patch.
core/domain/values/assets/JavascriptAsset.php 1 patch
Indentation   +141 added lines, -141 removed lines patch added patch discarded remove patch
@@ -18,145 +18,145 @@
 block discarded – undo
18 18
 class JavascriptAsset extends BrowserAsset
19 19
 {
20 20
 
21
-    /**
22
-     * @var boolean $load_in_footer
23
-     */
24
-    private $load_in_footer = false;
25
-
26
-    /**
27
-     * @var boolean $requires_translation
28
-     */
29
-    private $requires_translation = false;
30
-
31
-    /**
32
-     * @var boolean $has_inline_data
33
-     */
34
-    private $has_inline_data = false;
35
-
36
-    /**
37
-     * @var Closure $inline_data_callback
38
-     */
39
-    private $inline_data_callback;
40
-
41
-
42
-    /**
43
-     * Asset constructor.
44
-     *
45
-     * @param string          $handle
46
-     * @param string          $source
47
-     * @param array           $dependencies
48
-     * @param bool            $load_in_footer
49
-     * @param DomainInterface $domain
50
-     * @param string          $version
51
-     * @throws InvalidDataTypeException
52
-     * @throws DomainException
53
-     */
54
-    public function __construct(
55
-        $handle,
56
-        $source,
57
-        array $dependencies,
58
-        $load_in_footer,
59
-        DomainInterface $domain,
60
-        $version = ''
61
-    ) {
62
-        parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version);
63
-        $this->setLoadInFooter($load_in_footer);
64
-    }
65
-
66
-
67
-    /**
68
-     * @return bool
69
-     */
70
-    public function loadInFooter()
71
-    {
72
-        return $this->load_in_footer;
73
-    }
74
-
75
-
76
-    /**
77
-     * @param bool $load_in_footer
78
-     */
79
-    private function setLoadInFooter($load_in_footer = true)
80
-    {
81
-        $this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN);
82
-    }
83
-
84
-
85
-    /**
86
-     * @return bool
87
-     */
88
-    public function requiresTranslation()
89
-    {
90
-        return $this->requires_translation;
91
-    }
92
-
93
-
94
-    /**
95
-     * @param bool $requires_translation
96
-     * @return JavascriptAsset
97
-     */
98
-    public function setRequiresTranslation($requires_translation = true)
99
-    {
100
-        $this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN);
101
-        return $this;
102
-    }
103
-
104
-
105
-    /**
106
-     * @return bool
107
-     */
108
-    public function hasInlineData()
109
-    {
110
-        return $this->has_inline_data;
111
-    }
112
-
113
-
114
-    /**
115
-     * @param bool $has_inline_data
116
-     * @return JavascriptAsset
117
-     */
118
-    public function setHasInlineData($has_inline_data = true)
119
-    {
120
-        $this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN);
121
-        return $this;
122
-    }
123
-
124
-
125
-    /**
126
-     * @return Closure
127
-     */
128
-    public function inlineDataCallback()
129
-    {
130
-        return $this->inline_data_callback;
131
-    }
132
-
133
-
134
-    /**
135
-     * @return bool
136
-     */
137
-    public function hasInlineDataCallback()
138
-    {
139
-        return $this->inline_data_callback instanceof Closure;
140
-    }
141
-
142
-
143
-    /**
144
-     * @param Closure $inline_data_callback
145
-     * @return JavascriptAsset
146
-     */
147
-    public function setInlineDataCallback(Closure $inline_data_callback)
148
-    {
149
-        $this->inline_data_callback = $inline_data_callback;
150
-        $this->setHasInlineData();
151
-        return $this;
152
-    }
153
-
154
-
155
-    /**
156
-     * @since 4.9.62.p
157
-     */
158
-    public function enqueueAsset()
159
-    {
160
-        wp_enqueue_script($this->handle());
161
-    }
21
+	/**
22
+	 * @var boolean $load_in_footer
23
+	 */
24
+	private $load_in_footer = false;
25
+
26
+	/**
27
+	 * @var boolean $requires_translation
28
+	 */
29
+	private $requires_translation = false;
30
+
31
+	/**
32
+	 * @var boolean $has_inline_data
33
+	 */
34
+	private $has_inline_data = false;
35
+
36
+	/**
37
+	 * @var Closure $inline_data_callback
38
+	 */
39
+	private $inline_data_callback;
40
+
41
+
42
+	/**
43
+	 * Asset constructor.
44
+	 *
45
+	 * @param string          $handle
46
+	 * @param string          $source
47
+	 * @param array           $dependencies
48
+	 * @param bool            $load_in_footer
49
+	 * @param DomainInterface $domain
50
+	 * @param string          $version
51
+	 * @throws InvalidDataTypeException
52
+	 * @throws DomainException
53
+	 */
54
+	public function __construct(
55
+		$handle,
56
+		$source,
57
+		array $dependencies,
58
+		$load_in_footer,
59
+		DomainInterface $domain,
60
+		$version = ''
61
+	) {
62
+		parent::__construct(Asset::TYPE_JS, $handle, $source, $dependencies, $domain, $version);
63
+		$this->setLoadInFooter($load_in_footer);
64
+	}
65
+
66
+
67
+	/**
68
+	 * @return bool
69
+	 */
70
+	public function loadInFooter()
71
+	{
72
+		return $this->load_in_footer;
73
+	}
74
+
75
+
76
+	/**
77
+	 * @param bool $load_in_footer
78
+	 */
79
+	private function setLoadInFooter($load_in_footer = true)
80
+	{
81
+		$this->load_in_footer = filter_var($load_in_footer, FILTER_VALIDATE_BOOLEAN);
82
+	}
83
+
84
+
85
+	/**
86
+	 * @return bool
87
+	 */
88
+	public function requiresTranslation()
89
+	{
90
+		return $this->requires_translation;
91
+	}
92
+
93
+
94
+	/**
95
+	 * @param bool $requires_translation
96
+	 * @return JavascriptAsset
97
+	 */
98
+	public function setRequiresTranslation($requires_translation = true)
99
+	{
100
+		$this->requires_translation = filter_var($requires_translation, FILTER_VALIDATE_BOOLEAN);
101
+		return $this;
102
+	}
103
+
104
+
105
+	/**
106
+	 * @return bool
107
+	 */
108
+	public function hasInlineData()
109
+	{
110
+		return $this->has_inline_data;
111
+	}
112
+
113
+
114
+	/**
115
+	 * @param bool $has_inline_data
116
+	 * @return JavascriptAsset
117
+	 */
118
+	public function setHasInlineData($has_inline_data = true)
119
+	{
120
+		$this->has_inline_data = filter_var($has_inline_data, FILTER_VALIDATE_BOOLEAN);
121
+		return $this;
122
+	}
123
+
124
+
125
+	/**
126
+	 * @return Closure
127
+	 */
128
+	public function inlineDataCallback()
129
+	{
130
+		return $this->inline_data_callback;
131
+	}
132
+
133
+
134
+	/**
135
+	 * @return bool
136
+	 */
137
+	public function hasInlineDataCallback()
138
+	{
139
+		return $this->inline_data_callback instanceof Closure;
140
+	}
141
+
142
+
143
+	/**
144
+	 * @param Closure $inline_data_callback
145
+	 * @return JavascriptAsset
146
+	 */
147
+	public function setInlineDataCallback(Closure $inline_data_callback)
148
+	{
149
+		$this->inline_data_callback = $inline_data_callback;
150
+		$this->setHasInlineData();
151
+		return $this;
152
+	}
153
+
154
+
155
+	/**
156
+	 * @since 4.9.62.p
157
+	 */
158
+	public function enqueueAsset()
159
+	{
160
+		wp_enqueue_script($this->handle());
161
+	}
162 162
 }
Please login to merge, or discard this patch.
core/domain/services/assets/CoreAssetManager.php 2 patches
Indentation   +439 added lines, -439 removed lines patch added patch discarded remove patch
@@ -32,467 +32,467 @@
 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_UTILS = 'eventespresso-utils';
65
+	const JS_HANDLE_UTILS = 'eventespresso-utils';
66 66
 
67
-    const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
67
+	const JS_HANDLE_DATA_STORES = 'eventespresso-data-stores';
68 68
 
69
-    const JS_HANDLE_HELPERS = 'eventespresso-helpers';
69
+	const JS_HANDLE_HELPERS = 'eventespresso-helpers';
70 70
 
71
-    const JS_HANDLE_MODEL = 'eventespresso-model';
71
+	const JS_HANDLE_MODEL = 'eventespresso-model';
72 72
 
73
-    const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
73
+	const JS_HANDLE_VALUE_OBJECTS = 'eventespresso-value-objects';
74 74
 
75
-    const JS_HANDLE_HOCS = 'eventespresso-hocs';
75
+	const JS_HANDLE_HOCS = 'eventespresso-hocs';
76 76
 
77
-    const JS_HANDLE_COMPONENTS = 'eventespresso-components';
77
+	const JS_HANDLE_COMPONENTS = 'eventespresso-components';
78 78
 
79
-    const JS_HANDLE_HOOKS = 'eventespresso-hooks';
79
+	const JS_HANDLE_HOOKS = 'eventespresso-hooks';
80 80
 
81
-    const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
81
+	const JS_HANDLE_VALIDATORS = 'eventespresso-validators';
82 82
 
83
-    const JS_HANDLE_CORE = 'espresso_core';
83
+	const JS_HANDLE_CORE = 'espresso_core';
84 84
 
85
-    const JS_HANDLE_I18N = 'eei18n';
85
+	const JS_HANDLE_I18N = 'eei18n';
86 86
 
87
-    const JS_HANDLE_ACCOUNTING = 'ee-accounting';
87
+	const JS_HANDLE_ACCOUNTING = 'ee-accounting';
88 88
 
89
-    const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
89
+	const JS_HANDLE_WP_PLUGINS_PAGE = 'ee-wp-plugins-page';
90 90
 
91
-    // EE CSS assets handles
92
-    const CSS_HANDLE_DEFAULT = 'espresso_default';
91
+	// EE CSS assets handles
92
+	const CSS_HANDLE_DEFAULT = 'espresso_default';
93 93
 
94
-    const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
95
-
96
-    const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
97
-
98
-    const CSS_HANDLE_HOCS = 'eventespresso-hocs';
99
-
100
-    const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
101
-
102
-    /**
103
-     * @var EE_Currency_Config $currency_config
104
-     */
105
-    protected $currency_config;
106
-
107
-    /**
108
-     * @var EE_Template_Config $template_config
109
-     */
110
-    protected $template_config;
111
-
112
-
113
-    /**
114
-     * CoreAssetRegister constructor.
115
-     *
116
-     * @param AssetCollection    $assets
117
-     * @param EE_Currency_Config $currency_config
118
-     * @param EE_Template_Config $template_config
119
-     * @param DomainInterface    $domain
120
-     * @param Registry           $registry
121
-     */
122
-    public function __construct(
123
-        AssetCollection $assets,
124
-        EE_Currency_Config $currency_config,
125
-        EE_Template_Config $template_config,
126
-        DomainInterface $domain,
127
-        Registry $registry
128
-    ) {
129
-        $this->currency_config = $currency_config;
130
-        $this->template_config = $template_config;
131
-        parent::__construct($domain, $assets, $registry);
132
-    }
133
-
134
-
135
-    /**
136
-     * @since 4.9.62.p
137
-     * @throws DomainException
138
-     * @throws DuplicateCollectionIdentifierException
139
-     * @throws InvalidArgumentException
140
-     * @throws InvalidDataTypeException
141
-     * @throws InvalidEntityException
142
-     * @throws InvalidInterfaceException
143
-     */
144
-    public function addAssets()
145
-    {
146
-        $this->addJavascriptFiles();
147
-        $this->addStylesheetFiles();
148
-    }
149
-
150
-
151
-    /**
152
-     * @since 4.9.62.p
153
-     * @throws DomainException
154
-     * @throws DuplicateCollectionIdentifierException
155
-     * @throws InvalidArgumentException
156
-     * @throws InvalidDataTypeException
157
-     * @throws InvalidEntityException
158
-     * @throws InvalidInterfaceException
159
-     */
160
-    public function addJavascriptFiles()
161
-    {
162
-        $this->loadCoreJs();
163
-        $this->loadJqueryValidate();
164
-        $this->loadAccountingJs();
165
-        add_action(
166
-            'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
167
-            array($this, 'loadQtipJs')
168
-        );
169
-        $this->registerAdminAssets();
170
-    }
171
-
172
-
173
-    /**
174
-     * @throws DuplicateCollectionIdentifierException
175
-     * @throws InvalidDataTypeException
176
-     * @throws InvalidEntityException
177
-     * @throws DomainException
178
-     * @since 4.9.62.p
179
-     */
180
-    public function addStylesheetFiles()
181
-    {
182
-        $this->loadCoreCss();
183
-    }
184
-
185
-
186
-    /**
187
-     * core default javascript
188
-     *
189
-     * @since 4.9.62.p
190
-     * @throws DomainException
191
-     * @throws DuplicateCollectionIdentifierException
192
-     * @throws InvalidArgumentException
193
-     * @throws InvalidDataTypeException
194
-     * @throws InvalidEntityException
195
-     * @throws InvalidInterfaceException
196
-     */
197
-    private function loadCoreJs()
198
-    {
199
-        // conditionally load third-party libraries that WP core MIGHT have.
200
-        $this->registerWpAssets();
201
-
202
-        $this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
203
-        $this->addJs(self::JS_HANDLE_VENDOR);
204
-        $this->addJs(self::JS_HANDLE_UTILS)->setRequiresTranslation();
205
-        $this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
206
-        $this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
207
-        $this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
208
-        $this->addJs(self::JS_HANDLE_HOOKS);
209
-        $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
210
-        $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
211
-            static function () {
212
-                wp_add_inline_script(
213
-                    CoreAssetManager::JS_HANDLE_DATA_STORES,
214
-                    is_admin()
215
-                        ? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
216
-                        : 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
217
-                );
218
-            }
219
-        );
220
-        $this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
221
-        $this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
222
-
223
-        $this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
224
-        $this->registry->addData(
225
-            'paths',
226
-            array(
227
-                'base_rest_route' => rest_url(),
228
-                'rest_route' => rest_url('ee/v4.8.36/'),
229
-                'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
230
-                'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
231
-                'site_url' => site_url('/'),
232
-                'admin_url' => admin_url('/'),
233
-            )
234
-        );
235
-        // Event Espresso brand name
236
-        $this->registry->addData('brandName', Domain::brandName());
237
-        /** site formatting values **/
238
-        $this->registry->addData(
239
-            'site_formats',
240
-            array(
241
-                'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
242
-            )
243
-        );
244
-        /** currency data **/
245
-        $this->registry->addData(
246
-            'currency_config',
247
-            $this->getCurrencySettings()
248
-        );
249
-        /** site timezone */
250
-        $this->registry->addData(
251
-            'default_timezone',
252
-            array(
253
-                'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
254
-                'string' => get_option('timezone_string'),
255
-                'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
256
-            )
257
-        );
258
-        /** site locale (user locale if user logged in) */
259
-        $this->registry->addData(
260
-            'locale',
261
-            array(
262
-                'user' => get_user_locale(),
263
-                'site' => get_locale()
264
-            )
265
-        );
266
-
267
-        $this->addJavascript(
268
-            CoreAssetManager::JS_HANDLE_CORE,
269
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
270
-            array(CoreAssetManager::JS_HANDLE_JQUERY)
271
-        )
272
-        ->setInlineDataCallback(
273
-            static function () {
274
-                wp_localize_script(
275
-                    CoreAssetManager::JS_HANDLE_CORE,
276
-                    CoreAssetManager::JS_HANDLE_I18N,
277
-                    EE_Registry::$i18n_js_strings
278
-                );
279
-            }
280
-        );
281
-    }
282
-
283
-
284
-    /**
285
-     * Registers vendor files that are bundled with a later version WP but might not be for the current version of
286
-     * WordPress in the running environment.
287
-     *
288
-     * @throws DuplicateCollectionIdentifierException
289
-     * @throws InvalidDataTypeException
290
-     * @throws InvalidEntityException
291
-     * @throws DomainException
292
-     * @since 4.9.71.p
293
-     */
294
-    private function registerWpAssets()
295
-    {
296
-        global $wp_version;
297
-        if (version_compare($wp_version, '5.0.beta', '>=')) {
298
-            return;
299
-        }
300
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0');
301
-        $this->addVendorJavascript(
302
-            CoreAssetManager::JS_HANDLE_REACT_DOM,
303
-            array(CoreAssetManager::JS_HANDLE_REACT),
304
-            true,
305
-            '16.6.0'
306
-        );
307
-        $this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11')
308
-            ->setInlineDataCallback(
309
-                static function() {
310
-                    wp_add_inline_script(
311
-                        CoreAssetManager::JS_HANDLE_LODASH,
312
-                        'window.lodash = _.noConflict();'
313
-                    );
314
-                }
315
-            );
316
-    }
317
-
318
-
319
-    /**
320
-     * Returns configuration data for the accounting-js library.
321
-     * @since 4.9.71.p
322
-     * @return array
323
-     */
324
-    private function getAccountingSettings() {
325
-        return array(
326
-            'currency' => array(
327
-                'symbol'    => $this->currency_config->sign,
328
-                'format'    => array(
329
-                    'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
330
-                    'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
331
-                    'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
332
-                ),
333
-                'decimal'   => $this->currency_config->dec_mrk,
334
-                'thousand'  => $this->currency_config->thsnds,
335
-                'precision' => $this->currency_config->dec_plc,
336
-            ),
337
-            'number'   => array(
338
-                'precision' => $this->currency_config->dec_plc,
339
-                'thousand'  => $this->currency_config->thsnds,
340
-                'decimal'   => $this->currency_config->dec_mrk,
341
-            ),
342
-        );
343
-    }
344
-
345
-
346
-    /**
347
-     * Returns configuration data for the js Currency VO.
348
-     * @since 4.9.71.p
349
-     * @return array
350
-     */
351
-    private function getCurrencySettings()
352
-    {
353
-        return array(
354
-            'code' => $this->currency_config->code,
355
-            'singularLabel' => $this->currency_config->name,
356
-            'pluralLabel' => $this->currency_config->plural,
357
-            'sign' => $this->currency_config->sign,
358
-            'signB4' => $this->currency_config->sign_b4,
359
-            'decimalPlaces' => $this->currency_config->dec_plc,
360
-            'decimalMark' => $this->currency_config->dec_mrk,
361
-            'thousandsSeparator' => $this->currency_config->thsnds,
362
-        );
363
-    }
364
-
365
-
366
-    /**
367
-     * @throws DuplicateCollectionIdentifierException
368
-     * @throws InvalidDataTypeException
369
-     * @throws InvalidEntityException
370
-     * @throws DomainException
371
-     * @since 4.9.62.p
372
-     */
373
-    private function loadCoreCss()
374
-    {
375
-        if ($this->template_config->enable_default_style && ! is_admin()) {
376
-            $this->addStylesheet(
377
-                CoreAssetManager::CSS_HANDLE_DEFAULT,
378
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
379
-                    ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
380
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
381
-                array('dashicons')
382
-            );
383
-            //Load custom style sheet if available
384
-            if ($this->template_config->custom_style_sheet !== null) {
385
-                $this->addStylesheet(
386
-                    CoreAssetManager::CSS_HANDLE_CUSTOM,
387
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
388
-                    array(CoreAssetManager::CSS_HANDLE_DEFAULT)
389
-                );
390
-            }
391
-        }
392
-        $this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']);
393
-        $this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]);
394
-        $this->addCss(self::CSS_HANDLE_HOCS);
395
-    }
396
-
397
-
398
-    /**
399
-     * jQuery Validate for form validation
400
-     *
401
-     * @since 4.9.62.p
402
-     * @throws DomainException
403
-     * @throws DuplicateCollectionIdentifierException
404
-     * @throws InvalidDataTypeException
405
-     * @throws InvalidEntityException
406
-     */
407
-    private function loadJqueryValidate()
408
-    {
409
-        $this->addJavascript(
410
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
411
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
412
-            array(CoreAssetManager::JS_HANDLE_JQUERY),
413
-            true,
414
-            '1.15.0'
415
-        );
416
-
417
-        $this->addJavascript(
418
-            CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
419
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
420
-            array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
421
-            true,
422
-            '1.15.0'
423
-        );
424
-    }
425
-
426
-
427
-    /**
428
-     * accounting.js for performing client-side calculations
429
-     *
430
-     * @since 4.9.62.p
431
-     * @throws DomainException
432
-     * @throws DuplicateCollectionIdentifierException
433
-     * @throws InvalidDataTypeException
434
-     * @throws InvalidEntityException
435
-     */
436
-    private function loadAccountingJs()
437
-    {
438
-        //accounting.js library
439
-        // @link http://josscrowcroft.github.io/accounting.js/
440
-        $this->addJavascript(
441
-            CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
442
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
443
-            array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
444
-            true,
445
-            '0.3.2'
446
-        );
447
-
448
-        $this->addJavascript(
449
-            CoreAssetManager::JS_HANDLE_ACCOUNTING,
450
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
451
-            array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
452
-        )
453
-        ->setInlineDataCallback(
454
-            function () {
455
-                 wp_localize_script(
456
-                     CoreAssetManager::JS_HANDLE_ACCOUNTING,
457
-                     'EE_ACCOUNTING_CFG',
458
-                     $this->getAccountingSettings()
459
-                 );
460
-            }
461
-        );
462
-    }
463
-
464
-
465
-    /**
466
-     * registers assets for cleaning your ears
467
-     *
468
-     * @param JavascriptAsset $script
469
-     */
470
-    public function loadQtipJs(JavascriptAsset $script)
471
-    {
472
-        // qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
473
-        // can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
474
-        if (
475
-            $script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
476
-            && apply_filters('FHEE_load_qtip', false)
477
-        ) {
478
-            EEH_Qtip_Loader::instance()->register_and_enqueue();
479
-        }
480
-    }
481
-
482
-
483
-    /**
484
-     * assets that are used in the WordPress admin
485
-     *
486
-     * @throws DuplicateCollectionIdentifierException
487
-     * @throws InvalidDataTypeException
488
-     * @throws InvalidEntityException
489
-     * @throws DomainException
490
-     * @since 4.9.62.p
491
-     */
492
-    private function registerAdminAssets()
493
-    {
494
-        $this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation();
495
-        // note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle.
496
-        $this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE);
497
-    }
94
+	const CSS_HANDLE_CUSTOM = 'espresso_custom_css';
95
+
96
+	const CSS_HANDLE_COMPONENTS = 'eventespresso-components';
97
+
98
+	const CSS_HANDLE_HOCS = 'eventespresso-hocs';
99
+
100
+	const CSS_HANDLE_CORE_CSS_DEFAULT = 'eventespresso-core-css-default';
101
+
102
+	/**
103
+	 * @var EE_Currency_Config $currency_config
104
+	 */
105
+	protected $currency_config;
106
+
107
+	/**
108
+	 * @var EE_Template_Config $template_config
109
+	 */
110
+	protected $template_config;
111
+
112
+
113
+	/**
114
+	 * CoreAssetRegister constructor.
115
+	 *
116
+	 * @param AssetCollection    $assets
117
+	 * @param EE_Currency_Config $currency_config
118
+	 * @param EE_Template_Config $template_config
119
+	 * @param DomainInterface    $domain
120
+	 * @param Registry           $registry
121
+	 */
122
+	public function __construct(
123
+		AssetCollection $assets,
124
+		EE_Currency_Config $currency_config,
125
+		EE_Template_Config $template_config,
126
+		DomainInterface $domain,
127
+		Registry $registry
128
+	) {
129
+		$this->currency_config = $currency_config;
130
+		$this->template_config = $template_config;
131
+		parent::__construct($domain, $assets, $registry);
132
+	}
133
+
134
+
135
+	/**
136
+	 * @since 4.9.62.p
137
+	 * @throws DomainException
138
+	 * @throws DuplicateCollectionIdentifierException
139
+	 * @throws InvalidArgumentException
140
+	 * @throws InvalidDataTypeException
141
+	 * @throws InvalidEntityException
142
+	 * @throws InvalidInterfaceException
143
+	 */
144
+	public function addAssets()
145
+	{
146
+		$this->addJavascriptFiles();
147
+		$this->addStylesheetFiles();
148
+	}
149
+
150
+
151
+	/**
152
+	 * @since 4.9.62.p
153
+	 * @throws DomainException
154
+	 * @throws DuplicateCollectionIdentifierException
155
+	 * @throws InvalidArgumentException
156
+	 * @throws InvalidDataTypeException
157
+	 * @throws InvalidEntityException
158
+	 * @throws InvalidInterfaceException
159
+	 */
160
+	public function addJavascriptFiles()
161
+	{
162
+		$this->loadCoreJs();
163
+		$this->loadJqueryValidate();
164
+		$this->loadAccountingJs();
165
+		add_action(
166
+			'AHEE__EventEspresso_core_services_assets_Registry__registerScripts__before_script',
167
+			array($this, 'loadQtipJs')
168
+		);
169
+		$this->registerAdminAssets();
170
+	}
171
+
172
+
173
+	/**
174
+	 * @throws DuplicateCollectionIdentifierException
175
+	 * @throws InvalidDataTypeException
176
+	 * @throws InvalidEntityException
177
+	 * @throws DomainException
178
+	 * @since 4.9.62.p
179
+	 */
180
+	public function addStylesheetFiles()
181
+	{
182
+		$this->loadCoreCss();
183
+	}
184
+
185
+
186
+	/**
187
+	 * core default javascript
188
+	 *
189
+	 * @since 4.9.62.p
190
+	 * @throws DomainException
191
+	 * @throws DuplicateCollectionIdentifierException
192
+	 * @throws InvalidArgumentException
193
+	 * @throws InvalidDataTypeException
194
+	 * @throws InvalidEntityException
195
+	 * @throws InvalidInterfaceException
196
+	 */
197
+	private function loadCoreJs()
198
+	{
199
+		// conditionally load third-party libraries that WP core MIGHT have.
200
+		$this->registerWpAssets();
201
+
202
+		$this->addJs(self::JS_HANDLE_JS_CORE)->setHasInlineData();
203
+		$this->addJs(self::JS_HANDLE_VENDOR);
204
+		$this->addJs(self::JS_HANDLE_UTILS)->setRequiresTranslation();
205
+		$this->addJs(self::JS_HANDLE_VALIDATORS)->setRequiresTranslation();
206
+		$this->addJs(self::JS_HANDLE_HELPERS)->setRequiresTranslation();
207
+		$this->addJs(self::JS_HANDLE_MODEL)->setRequiresTranslation();
208
+		$this->addJs(self::JS_HANDLE_HOOKS);
209
+		$this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
210
+		$this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
211
+			static function () {
212
+				wp_add_inline_script(
213
+					CoreAssetManager::JS_HANDLE_DATA_STORES,
214
+					is_admin()
215
+						? 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware( eejs.middleWares.apiFetch.CONTEXT_CAPS_EDIT ) )'
216
+						: 'wp.apiFetch.use( eejs.middleWares.apiFetch.capsMiddleware )'
217
+				);
218
+			}
219
+		);
220
+		$this->addJs(self::JS_HANDLE_HOCS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
221
+		$this->addJs(self::JS_HANDLE_COMPONENTS, [self::JS_HANDLE_DATA_STORES])->setRequiresTranslation();
222
+
223
+		$this->registry->addData('eejs_api_nonce', wp_create_nonce('wp_rest'));
224
+		$this->registry->addData(
225
+			'paths',
226
+			array(
227
+				'base_rest_route' => rest_url(),
228
+				'rest_route' => rest_url('ee/v4.8.36/'),
229
+				'collection_endpoints' => EED_Core_Rest_Api::getCollectionRoutesIndexedByModelName(),
230
+				'primary_keys' => EED_Core_Rest_Api::getPrimaryKeyNamesIndexedByModelName(),
231
+				'site_url' => site_url('/'),
232
+				'admin_url' => admin_url('/'),
233
+			)
234
+		);
235
+		// Event Espresso brand name
236
+		$this->registry->addData('brandName', Domain::brandName());
237
+		/** site formatting values **/
238
+		$this->registry->addData(
239
+			'site_formats',
240
+			array(
241
+				'date_formats' => EEH_DTT_Helper::convert_php_to_js_and_moment_date_formats()
242
+			)
243
+		);
244
+		/** currency data **/
245
+		$this->registry->addData(
246
+			'currency_config',
247
+			$this->getCurrencySettings()
248
+		);
249
+		/** site timezone */
250
+		$this->registry->addData(
251
+			'default_timezone',
252
+			array(
253
+				'pretty' => EEH_DTT_Helper::get_timezone_string_for_display(),
254
+				'string' => get_option('timezone_string'),
255
+				'offset' => EEH_DTT_Helper::get_site_timezone_gmt_offset(),
256
+			)
257
+		);
258
+		/** site locale (user locale if user logged in) */
259
+		$this->registry->addData(
260
+			'locale',
261
+			array(
262
+				'user' => get_user_locale(),
263
+				'site' => get_locale()
264
+			)
265
+		);
266
+
267
+		$this->addJavascript(
268
+			CoreAssetManager::JS_HANDLE_CORE,
269
+			EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
270
+			array(CoreAssetManager::JS_HANDLE_JQUERY)
271
+		)
272
+		->setInlineDataCallback(
273
+			static function () {
274
+				wp_localize_script(
275
+					CoreAssetManager::JS_HANDLE_CORE,
276
+					CoreAssetManager::JS_HANDLE_I18N,
277
+					EE_Registry::$i18n_js_strings
278
+				);
279
+			}
280
+		);
281
+	}
282
+
283
+
284
+	/**
285
+	 * Registers vendor files that are bundled with a later version WP but might not be for the current version of
286
+	 * WordPress in the running environment.
287
+	 *
288
+	 * @throws DuplicateCollectionIdentifierException
289
+	 * @throws InvalidDataTypeException
290
+	 * @throws InvalidEntityException
291
+	 * @throws DomainException
292
+	 * @since 4.9.71.p
293
+	 */
294
+	private function registerWpAssets()
295
+	{
296
+		global $wp_version;
297
+		if (version_compare($wp_version, '5.0.beta', '>=')) {
298
+			return;
299
+		}
300
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_REACT, [], true, '16.6.0');
301
+		$this->addVendorJavascript(
302
+			CoreAssetManager::JS_HANDLE_REACT_DOM,
303
+			array(CoreAssetManager::JS_HANDLE_REACT),
304
+			true,
305
+			'16.6.0'
306
+		);
307
+		$this->addVendorJavascript(CoreAssetManager::JS_HANDLE_LODASH, [], true, '4.17.11')
308
+			->setInlineDataCallback(
309
+				static function() {
310
+					wp_add_inline_script(
311
+						CoreAssetManager::JS_HANDLE_LODASH,
312
+						'window.lodash = _.noConflict();'
313
+					);
314
+				}
315
+			);
316
+	}
317
+
318
+
319
+	/**
320
+	 * Returns configuration data for the accounting-js library.
321
+	 * @since 4.9.71.p
322
+	 * @return array
323
+	 */
324
+	private function getAccountingSettings() {
325
+		return array(
326
+			'currency' => array(
327
+				'symbol'    => $this->currency_config->sign,
328
+				'format'    => array(
329
+					'pos'  => $this->currency_config->sign_b4 ? '%s%v' : '%v%s',
330
+					'neg'  => $this->currency_config->sign_b4 ? '- %s%v' : '- %v%s',
331
+					'zero' => $this->currency_config->sign_b4 ? '%s--' : '--%s',
332
+				),
333
+				'decimal'   => $this->currency_config->dec_mrk,
334
+				'thousand'  => $this->currency_config->thsnds,
335
+				'precision' => $this->currency_config->dec_plc,
336
+			),
337
+			'number'   => array(
338
+				'precision' => $this->currency_config->dec_plc,
339
+				'thousand'  => $this->currency_config->thsnds,
340
+				'decimal'   => $this->currency_config->dec_mrk,
341
+			),
342
+		);
343
+	}
344
+
345
+
346
+	/**
347
+	 * Returns configuration data for the js Currency VO.
348
+	 * @since 4.9.71.p
349
+	 * @return array
350
+	 */
351
+	private function getCurrencySettings()
352
+	{
353
+		return array(
354
+			'code' => $this->currency_config->code,
355
+			'singularLabel' => $this->currency_config->name,
356
+			'pluralLabel' => $this->currency_config->plural,
357
+			'sign' => $this->currency_config->sign,
358
+			'signB4' => $this->currency_config->sign_b4,
359
+			'decimalPlaces' => $this->currency_config->dec_plc,
360
+			'decimalMark' => $this->currency_config->dec_mrk,
361
+			'thousandsSeparator' => $this->currency_config->thsnds,
362
+		);
363
+	}
364
+
365
+
366
+	/**
367
+	 * @throws DuplicateCollectionIdentifierException
368
+	 * @throws InvalidDataTypeException
369
+	 * @throws InvalidEntityException
370
+	 * @throws DomainException
371
+	 * @since 4.9.62.p
372
+	 */
373
+	private function loadCoreCss()
374
+	{
375
+		if ($this->template_config->enable_default_style && ! is_admin()) {
376
+			$this->addStylesheet(
377
+				CoreAssetManager::CSS_HANDLE_DEFAULT,
378
+				is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
379
+					? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
380
+					: EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
381
+				array('dashicons')
382
+			);
383
+			//Load custom style sheet if available
384
+			if ($this->template_config->custom_style_sheet !== null) {
385
+				$this->addStylesheet(
386
+					CoreAssetManager::CSS_HANDLE_CUSTOM,
387
+					EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
388
+					array(CoreAssetManager::CSS_HANDLE_DEFAULT)
389
+				);
390
+			}
391
+		}
392
+		$this->addCss(self::CSS_HANDLE_CORE_CSS_DEFAULT, ['dashicons']);
393
+		$this->addCss(self::CSS_HANDLE_COMPONENTS, [self::CSS_HANDLE_CORE_CSS_DEFAULT]);
394
+		$this->addCss(self::CSS_HANDLE_HOCS);
395
+	}
396
+
397
+
398
+	/**
399
+	 * jQuery Validate for form validation
400
+	 *
401
+	 * @since 4.9.62.p
402
+	 * @throws DomainException
403
+	 * @throws DuplicateCollectionIdentifierException
404
+	 * @throws InvalidDataTypeException
405
+	 * @throws InvalidEntityException
406
+	 */
407
+	private function loadJqueryValidate()
408
+	{
409
+		$this->addJavascript(
410
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
411
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
412
+			array(CoreAssetManager::JS_HANDLE_JQUERY),
413
+			true,
414
+			'1.15.0'
415
+		);
416
+
417
+		$this->addJavascript(
418
+			CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
419
+			EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
420
+			array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
421
+			true,
422
+			'1.15.0'
423
+		);
424
+	}
425
+
426
+
427
+	/**
428
+	 * accounting.js for performing client-side calculations
429
+	 *
430
+	 * @since 4.9.62.p
431
+	 * @throws DomainException
432
+	 * @throws DuplicateCollectionIdentifierException
433
+	 * @throws InvalidDataTypeException
434
+	 * @throws InvalidEntityException
435
+	 */
436
+	private function loadAccountingJs()
437
+	{
438
+		//accounting.js library
439
+		// @link http://josscrowcroft.github.io/accounting.js/
440
+		$this->addJavascript(
441
+			CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
442
+			EE_THIRD_PARTY_URL . 'accounting/accounting.js',
443
+			array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
444
+			true,
445
+			'0.3.2'
446
+		);
447
+
448
+		$this->addJavascript(
449
+			CoreAssetManager::JS_HANDLE_ACCOUNTING,
450
+			EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
451
+			array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
452
+		)
453
+		->setInlineDataCallback(
454
+			function () {
455
+				 wp_localize_script(
456
+					 CoreAssetManager::JS_HANDLE_ACCOUNTING,
457
+					 'EE_ACCOUNTING_CFG',
458
+					 $this->getAccountingSettings()
459
+				 );
460
+			}
461
+		);
462
+	}
463
+
464
+
465
+	/**
466
+	 * registers assets for cleaning your ears
467
+	 *
468
+	 * @param JavascriptAsset $script
469
+	 */
470
+	public function loadQtipJs(JavascriptAsset $script)
471
+	{
472
+		// qtip is turned OFF by default, but prior to the wp_enqueue_scripts hook,
473
+		// can be turned back on again via: add_filter('FHEE_load_qtip', '__return_true' );
474
+		if (
475
+			$script->handle() === CoreAssetManager::JS_HANDLE_WP_PLUGINS_PAGE
476
+			&& apply_filters('FHEE_load_qtip', false)
477
+		) {
478
+			EEH_Qtip_Loader::instance()->register_and_enqueue();
479
+		}
480
+	}
481
+
482
+
483
+	/**
484
+	 * assets that are used in the WordPress admin
485
+	 *
486
+	 * @throws DuplicateCollectionIdentifierException
487
+	 * @throws InvalidDataTypeException
488
+	 * @throws InvalidEntityException
489
+	 * @throws DomainException
490
+	 * @since 4.9.62.p
491
+	 */
492
+	private function registerAdminAssets()
493
+	{
494
+		$this->addJs(self::JS_HANDLE_WP_PLUGINS_PAGE)->setRequiresTranslation();
495
+		// note usage of the "JS_HANDLE.." constant is intentional here because css uses the same handle.
496
+		$this->addCss(self::JS_HANDLE_WP_PLUGINS_PAGE);
497
+	}
498 498
 }
Please login to merge, or discard this patch.
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
         $this->addJs(self::JS_HANDLE_HOOKS);
209 209
         $this->addJs(self::JS_HANDLE_VALUE_OBJECTS)->setRequiresTranslation();
210 210
         $this->addJs(self::JS_HANDLE_DATA_STORES)->setRequiresTranslation()->setInlineDataCallback(
211
-            static function () {
211
+            static function() {
212 212
                 wp_add_inline_script(
213 213
                     CoreAssetManager::JS_HANDLE_DATA_STORES,
214 214
                     is_admin()
@@ -266,11 +266,11 @@  discard block
 block discarded – undo
266 266
 
267 267
         $this->addJavascript(
268 268
             CoreAssetManager::JS_HANDLE_CORE,
269
-            EE_GLOBAL_ASSETS_URL . 'scripts/espresso_core.js',
269
+            EE_GLOBAL_ASSETS_URL.'scripts/espresso_core.js',
270 270
             array(CoreAssetManager::JS_HANDLE_JQUERY)
271 271
         )
272 272
         ->setInlineDataCallback(
273
-            static function () {
273
+            static function() {
274 274
                 wp_localize_script(
275 275
                     CoreAssetManager::JS_HANDLE_CORE,
276 276
                     CoreAssetManager::JS_HANDLE_I18N,
@@ -375,16 +375,16 @@  discard block
 block discarded – undo
375 375
         if ($this->template_config->enable_default_style && ! is_admin()) {
376 376
             $this->addStylesheet(
377 377
                 CoreAssetManager::CSS_HANDLE_DEFAULT,
378
-                is_readable(EVENT_ESPRESSO_UPLOAD_DIR . 'css/style.css')
378
+                is_readable(EVENT_ESPRESSO_UPLOAD_DIR.'css/style.css')
379 379
                     ? EVENT_ESPRESSO_UPLOAD_DIR . 'css/espresso_default.css'
380
-                    : EE_GLOBAL_ASSETS_URL . 'css/espresso_default.css',
380
+                    : EE_GLOBAL_ASSETS_URL.'css/espresso_default.css',
381 381
                 array('dashicons')
382 382
             );
383 383
             //Load custom style sheet if available
384 384
             if ($this->template_config->custom_style_sheet !== null) {
385 385
                 $this->addStylesheet(
386 386
                     CoreAssetManager::CSS_HANDLE_CUSTOM,
387
-                    EVENT_ESPRESSO_UPLOAD_URL . 'css/' . $this->template_config->custom_style_sheet,
387
+                    EVENT_ESPRESSO_UPLOAD_URL.'css/'.$this->template_config->custom_style_sheet,
388 388
                     array(CoreAssetManager::CSS_HANDLE_DEFAULT)
389 389
                 );
390 390
             }
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
     {
409 409
         $this->addJavascript(
410 410
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE,
411
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.min.js',
411
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.min.js',
412 412
             array(CoreAssetManager::JS_HANDLE_JQUERY),
413 413
             true,
414 414
             '1.15.0'
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 
417 417
         $this->addJavascript(
418 418
             CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE_EXTRA,
419
-            EE_GLOBAL_ASSETS_URL . 'scripts/jquery.validate.additional-methods.min.js',
419
+            EE_GLOBAL_ASSETS_URL.'scripts/jquery.validate.additional-methods.min.js',
420 420
             array(CoreAssetManager::JS_HANDLE_JQUERY_VALIDATE),
421 421
             true,
422 422
             '1.15.0'
@@ -439,7 +439,7 @@  discard block
 block discarded – undo
439 439
         // @link http://josscrowcroft.github.io/accounting.js/
440 440
         $this->addJavascript(
441 441
             CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE,
442
-            EE_THIRD_PARTY_URL . 'accounting/accounting.js',
442
+            EE_THIRD_PARTY_URL.'accounting/accounting.js',
443 443
             array(CoreAssetManager::JS_HANDLE_UNDERSCORE),
444 444
             true,
445 445
             '0.3.2'
@@ -447,11 +447,11 @@  discard block
 block discarded – undo
447 447
 
448 448
         $this->addJavascript(
449 449
             CoreAssetManager::JS_HANDLE_ACCOUNTING,
450
-            EE_GLOBAL_ASSETS_URL . 'scripts/ee-accounting-config.js',
450
+            EE_GLOBAL_ASSETS_URL.'scripts/ee-accounting-config.js',
451 451
             array(CoreAssetManager::JS_HANDLE_ACCOUNTING_CORE)
452 452
         )
453 453
         ->setInlineDataCallback(
454
-            function () {
454
+            function() {
455 455
                  wp_localize_script(
456 456
                      CoreAssetManager::JS_HANDLE_ACCOUNTING,
457 457
                      'EE_ACCOUNTING_CFG',
Please login to merge, or discard this patch.
espresso.php 1 patch
Indentation   +80 added lines, -80 removed lines patch added patch discarded remove patch
@@ -37,103 +37,103 @@
 block discarded – undo
37 37
  * @since           4.0
38 38
  */
39 39
 if (function_exists('espresso_version')) {
40
-    if (! function_exists('espresso_duplicate_plugin_error')) {
41
-        /**
42
-         *    espresso_duplicate_plugin_error
43
-         *    displays if more than one version of EE is activated at the same time
44
-         */
45
-        function espresso_duplicate_plugin_error()
46
-        {
47
-            ?>
40
+	if (! function_exists('espresso_duplicate_plugin_error')) {
41
+		/**
42
+		 *    espresso_duplicate_plugin_error
43
+		 *    displays if more than one version of EE is activated at the same time
44
+		 */
45
+		function espresso_duplicate_plugin_error()
46
+		{
47
+			?>
48 48
             <div class="error">
49 49
                 <p>
50 50
                     <?php
51
-                    echo esc_html__(
52
-                        'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
-                        'event_espresso'
54
-                    ); ?>
51
+					echo esc_html__(
52
+						'Can not run multiple versions of Event Espresso! One version has been automatically deactivated. Please verify that you have the correct version you want still active.',
53
+						'event_espresso'
54
+					); ?>
55 55
                 </p>
56 56
             </div>
57 57
             <?php
58
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
59
-        }
60
-    }
61
-    add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
58
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
59
+		}
60
+	}
61
+	add_action('admin_notices', 'espresso_duplicate_plugin_error', 1);
62 62
 } else {
63
-    define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
64
-    if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
-        /**
66
-         * espresso_minimum_php_version_error
67
-         *
68
-         * @return void
69
-         */
70
-        function espresso_minimum_php_version_error()
71
-        {
72
-            ?>
63
+	define('EE_MIN_PHP_VER_REQUIRED', '5.4.0');
64
+	if (! version_compare(PHP_VERSION, EE_MIN_PHP_VER_REQUIRED, '>=')) {
65
+		/**
66
+		 * espresso_minimum_php_version_error
67
+		 *
68
+		 * @return void
69
+		 */
70
+		function espresso_minimum_php_version_error()
71
+		{
72
+			?>
73 73
             <div class="error">
74 74
                 <p>
75 75
                     <?php
76
-                    printf(
77
-                        esc_html__(
78
-                            'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
-                            'event_espresso'
80
-                        ),
81
-                        EE_MIN_PHP_VER_REQUIRED,
82
-                        PHP_VERSION,
83
-                        '<br/>',
84
-                        '<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
85
-                    );
86
-                    ?>
76
+					printf(
77
+						esc_html__(
78
+							'We\'re sorry, but Event Espresso requires PHP version %1$s or greater in order to operate. You are currently running version %2$s.%3$sIn order to update your version of PHP, you will need to contact your current hosting provider.%3$sFor information on stable PHP versions, please go to %4$s.',
79
+							'event_espresso'
80
+						),
81
+						EE_MIN_PHP_VER_REQUIRED,
82
+						PHP_VERSION,
83
+						'<br/>',
84
+						'<a href="http://php.net/downloads.php">http://php.net/downloads.php</a>'
85
+					);
86
+					?>
87 87
                 </p>
88 88
             </div>
89 89
             <?php
90
-            espresso_deactivate_plugin(plugin_basename(__FILE__));
91
-        }
90
+			espresso_deactivate_plugin(plugin_basename(__FILE__));
91
+		}
92 92
 
93
-        add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
-    } else {
95
-        define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96
-        /**
97
-         * espresso_version
98
-         * Returns the plugin version
99
-         *
100
-         * @return string
101
-         */
102
-        function espresso_version()
103
-        {
104
-            return apply_filters('FHEE__espresso__espresso_version', '4.10.2.rc.046');
105
-        }
93
+		add_action('admin_notices', 'espresso_minimum_php_version_error', 1);
94
+	} else {
95
+		define('EVENT_ESPRESSO_MAIN_FILE', __FILE__);
96
+		/**
97
+		 * espresso_version
98
+		 * Returns the plugin version
99
+		 *
100
+		 * @return string
101
+		 */
102
+		function espresso_version()
103
+		{
104
+			return apply_filters('FHEE__espresso__espresso_version', '4.10.2.rc.046');
105
+		}
106 106
 
107
-        /**
108
-         * espresso_plugin_activation
109
-         * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
110
-         */
111
-        function espresso_plugin_activation()
112
-        {
113
-            update_option('ee_espresso_activation', true);
114
-        }
107
+		/**
108
+		 * espresso_plugin_activation
109
+		 * adds a wp-option to indicate that EE has been activated via the WP admin plugins page
110
+		 */
111
+		function espresso_plugin_activation()
112
+		{
113
+			update_option('ee_espresso_activation', true);
114
+		}
115 115
 
116
-        register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
116
+		register_activation_hook(EVENT_ESPRESSO_MAIN_FILE, 'espresso_plugin_activation');
117 117
 
118
-        require_once __DIR__ . '/core/bootstrap_espresso.php';
119
-        bootstrap_espresso();
120
-    }
118
+		require_once __DIR__ . '/core/bootstrap_espresso.php';
119
+		bootstrap_espresso();
120
+	}
121 121
 }
122 122
 if (! function_exists('espresso_deactivate_plugin')) {
123
-    /**
124
-     *    deactivate_plugin
125
-     * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
126
-     *
127
-     * @access public
128
-     * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
129
-     * @return    void
130
-     */
131
-    function espresso_deactivate_plugin($plugin_basename = '')
132
-    {
133
-        if (! function_exists('deactivate_plugins')) {
134
-            require_once ABSPATH . 'wp-admin/includes/plugin.php';
135
-        }
136
-        unset($_GET['activate'], $_REQUEST['activate']);
137
-        deactivate_plugins($plugin_basename);
138
-    }
123
+	/**
124
+	 *    deactivate_plugin
125
+	 * usage:  espresso_deactivate_plugin( plugin_basename( __FILE__ ));
126
+	 *
127
+	 * @access public
128
+	 * @param string $plugin_basename - the results of plugin_basename( __FILE__ ) for the plugin's main file
129
+	 * @return    void
130
+	 */
131
+	function espresso_deactivate_plugin($plugin_basename = '')
132
+	{
133
+		if (! function_exists('deactivate_plugins')) {
134
+			require_once ABSPATH . 'wp-admin/includes/plugin.php';
135
+		}
136
+		unset($_GET['activate'], $_REQUEST['activate']);
137
+		deactivate_plugins($plugin_basename);
138
+	}
139 139
 }
Please login to merge, or discard this patch.