Completed
Pull Request — Gutenberg/master (#476)
by
unknown
33:56 queued 19:41
created
core/services/assets/AssetCollection.php 2 patches
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -21,201 +21,201 @@
 block discarded – undo
21 21
 {
22 22
 
23 23
 
24
-    /**
25
-     * AssetCollection constructor
26
-     *
27
-     * @throws InvalidInterfaceException
28
-     */
29
-    public function __construct()
30
-    {
31
-        parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
-    }
33
-
34
-
35
-    /**
36
-     * @return StylesheetAsset[]
37
-     * @since 4.9.62.p
38
-     */
39
-    public function getStylesheetAssets()
40
-    {
41
-        return $this->getAssetsOfType(Asset::TYPE_CSS);
42
-    }
43
-
44
-
45
-    /**
46
-     * @return JavascriptAsset[]
47
-     * @since 4.9.62.p
48
-     */
49
-    public function getJavascriptAssets()
50
-    {
51
-        return $this->getAssetsOfType(Asset::TYPE_JS);
52
-    }
53
-
54
-
55
-    /**
56
-     * @return ManifestFile[]
57
-     * @since 4.9.62.p
58
-     */
59
-    public function getManifestFiles()
60
-    {
61
-        return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
-    }
63
-
64
-
65
-    /**
66
-     * @param $type
67
-     * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
-     * @since 4.9.62.p
69
-     */
70
-    protected function getAssetsOfType($type)
71
-    {
72
-        $files = array();
73
-        $this->rewind();
74
-        while ($this->valid()) {
75
-            /** @var Asset $asset */
76
-            $asset = $this->current();
77
-            if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
79
-            }
80
-            $this->next();
81
-        }
82
-        $this->rewind();
83
-        return $files;
84
-    }
85
-
86
-
87
-    /**
88
-     * @return JavascriptAsset[]
89
-     * @since 4.9.62.p
90
-     */
91
-    public function getJavascriptAssetsWithData()
92
-    {
93
-        $files = array();
94
-        $this->rewind();
95
-        while ($this->valid()) {
96
-            /** @var JavascriptAsset $asset */
97
-            $asset = $this->current();
98
-            if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
100
-            }
101
-            $this->next();
102
-        }
103
-        $this->rewind();
104
-        return $files;
105
-    }
106
-
107
-
108
-    /**
109
-     * has
110
-     * returns TRUE or FALSE
111
-     * depending on whether the object is within the Collection
112
-     * based on the supplied $identifier and type
113
-     *
114
-     * @access public
115
-     * @param  mixed $identifier
116
-     * @param string $type
117
-     * @return bool
118
-     */
119
-    public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
120
-    {
121
-        $this->rewind();
122
-        while ($this->valid()) {
123
-            if ($this->getInfo() === $identifier && $this->current() === $type) {
124
-                $this->rewind();
125
-                return true;
126
-            }
127
-            $this->next();
128
-        }
129
-        return false;
130
-    }
131
-
132
-
133
-    /**
134
-     * has
135
-     * returns TRUE or FALSE
136
-     * depending on whether the Stylesheet Asset is within the Collection
137
-     * based on the supplied $identifier
138
-     *
139
-     * @access public
140
-     * @param  mixed $identifier
141
-     * @return bool
142
-     */
143
-    public function hasStylesheetAsset($identifier)
144
-    {
145
-        return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
146
-    }
147
-
148
-
149
-    /**
150
-     * has
151
-     * returns TRUE or FALSE
152
-     * depending on whether the Javascript Asset is within the Collection
153
-     * based on the supplied $identifier
154
-     *
155
-     * @access public
156
-     * @param  mixed $identifier
157
-     * @return bool
158
-     */
159
-    public function hasJavascriptAsset($identifier)
160
-    {
161
-        return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
162
-    }
163
-
164
-    /**
165
-     * has
166
-     * returns TRUE or FALSE
167
-     * depending on whether the object is within the Collection
168
-     * based on the supplied $identifier and type
169
-     *
170
-     * @access public
171
-     * @param  mixed $identifier
172
-     * @param string $type
173
-     * @return JavascriptAsset|StylesheetAsset
174
-     */
175
-    public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
176
-    {
177
-        $this->rewind();
178
-        while ($this->valid()) {
179
-            if ($this->getInfo() === $identifier && $this->current() === $type) {
180
-                /** @var JavascriptAsset|StylesheetAsset $object */
181
-                $object = $this->current();
182
-                $this->rewind();
183
-                return $object;
184
-            }
185
-            $this->next();
186
-        }
187
-        return null;
188
-    }
189
-
190
-
191
-    /**
192
-     * has
193
-     * returns TRUE or FALSE
194
-     * depending on whether the Stylesheet Asset is within the Collection
195
-     * based on the supplied $identifier
196
-     *
197
-     * @access public
198
-     * @param  mixed $identifier
199
-     * @return StylesheetAsset
200
-     */
201
-    public function getStylesheetAsset($identifier)
202
-    {
203
-        return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
204
-    }
205
-
206
-
207
-    /**
208
-     * has
209
-     * returns TRUE or FALSE
210
-     * depending on whether the Javascript Asset is within the Collection
211
-     * based on the supplied $identifier
212
-     *
213
-     * @access public
214
-     * @param  mixed $identifier
215
-     * @return JavascriptAsset
216
-     */
217
-    public function getJavascriptAsset($identifier)
218
-    {
219
-        return $this->getAssetOfType($identifier, Asset::TYPE_JS);
220
-    }
24
+	/**
25
+	 * AssetCollection constructor
26
+	 *
27
+	 * @throws InvalidInterfaceException
28
+	 */
29
+	public function __construct()
30
+	{
31
+		parent::__construct('EventEspresso\core\domain\values\assets\Asset');
32
+	}
33
+
34
+
35
+	/**
36
+	 * @return StylesheetAsset[]
37
+	 * @since 4.9.62.p
38
+	 */
39
+	public function getStylesheetAssets()
40
+	{
41
+		return $this->getAssetsOfType(Asset::TYPE_CSS);
42
+	}
43
+
44
+
45
+	/**
46
+	 * @return JavascriptAsset[]
47
+	 * @since 4.9.62.p
48
+	 */
49
+	public function getJavascriptAssets()
50
+	{
51
+		return $this->getAssetsOfType(Asset::TYPE_JS);
52
+	}
53
+
54
+
55
+	/**
56
+	 * @return ManifestFile[]
57
+	 * @since 4.9.62.p
58
+	 */
59
+	public function getManifestFiles()
60
+	{
61
+		return $this->getAssetsOfType(Asset::TYPE_MANIFEST);
62
+	}
63
+
64
+
65
+	/**
66
+	 * @param $type
67
+	 * @return JavascriptAsset[]|StylesheetAsset[]|ManifestFile[]
68
+	 * @since 4.9.62.p
69
+	 */
70
+	protected function getAssetsOfType($type)
71
+	{
72
+		$files = array();
73
+		$this->rewind();
74
+		while ($this->valid()) {
75
+			/** @var Asset $asset */
76
+			$asset = $this->current();
77
+			if ($asset->type() === $type) {
78
+				$files[ $asset->handle() ] = $asset;
79
+			}
80
+			$this->next();
81
+		}
82
+		$this->rewind();
83
+		return $files;
84
+	}
85
+
86
+
87
+	/**
88
+	 * @return JavascriptAsset[]
89
+	 * @since 4.9.62.p
90
+	 */
91
+	public function getJavascriptAssetsWithData()
92
+	{
93
+		$files = array();
94
+		$this->rewind();
95
+		while ($this->valid()) {
96
+			/** @var JavascriptAsset $asset */
97
+			$asset = $this->current();
98
+			if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
+				$files[ $asset->handle() ] = $asset;
100
+			}
101
+			$this->next();
102
+		}
103
+		$this->rewind();
104
+		return $files;
105
+	}
106
+
107
+
108
+	/**
109
+	 * has
110
+	 * returns TRUE or FALSE
111
+	 * depending on whether the object is within the Collection
112
+	 * based on the supplied $identifier and type
113
+	 *
114
+	 * @access public
115
+	 * @param  mixed $identifier
116
+	 * @param string $type
117
+	 * @return bool
118
+	 */
119
+	public function hasAssetOfType($identifier, $type = Asset::TYPE_JS)
120
+	{
121
+		$this->rewind();
122
+		while ($this->valid()) {
123
+			if ($this->getInfo() === $identifier && $this->current() === $type) {
124
+				$this->rewind();
125
+				return true;
126
+			}
127
+			$this->next();
128
+		}
129
+		return false;
130
+	}
131
+
132
+
133
+	/**
134
+	 * has
135
+	 * returns TRUE or FALSE
136
+	 * depending on whether the Stylesheet Asset is within the Collection
137
+	 * based on the supplied $identifier
138
+	 *
139
+	 * @access public
140
+	 * @param  mixed $identifier
141
+	 * @return bool
142
+	 */
143
+	public function hasStylesheetAsset($identifier)
144
+	{
145
+		return $this->hasAssetOfType($identifier, Asset::TYPE_CSS);
146
+	}
147
+
148
+
149
+	/**
150
+	 * has
151
+	 * returns TRUE or FALSE
152
+	 * depending on whether the Javascript Asset is within the Collection
153
+	 * based on the supplied $identifier
154
+	 *
155
+	 * @access public
156
+	 * @param  mixed $identifier
157
+	 * @return bool
158
+	 */
159
+	public function hasJavascriptAsset($identifier)
160
+	{
161
+		return $this->hasAssetOfType($identifier, Asset::TYPE_JS);
162
+	}
163
+
164
+	/**
165
+	 * has
166
+	 * returns TRUE or FALSE
167
+	 * depending on whether the object is within the Collection
168
+	 * based on the supplied $identifier and type
169
+	 *
170
+	 * @access public
171
+	 * @param  mixed $identifier
172
+	 * @param string $type
173
+	 * @return JavascriptAsset|StylesheetAsset
174
+	 */
175
+	public function getAssetOfType($identifier, $type = Asset::TYPE_JS)
176
+	{
177
+		$this->rewind();
178
+		while ($this->valid()) {
179
+			if ($this->getInfo() === $identifier && $this->current() === $type) {
180
+				/** @var JavascriptAsset|StylesheetAsset $object */
181
+				$object = $this->current();
182
+				$this->rewind();
183
+				return $object;
184
+			}
185
+			$this->next();
186
+		}
187
+		return null;
188
+	}
189
+
190
+
191
+	/**
192
+	 * has
193
+	 * returns TRUE or FALSE
194
+	 * depending on whether the Stylesheet Asset is within the Collection
195
+	 * based on the supplied $identifier
196
+	 *
197
+	 * @access public
198
+	 * @param  mixed $identifier
199
+	 * @return StylesheetAsset
200
+	 */
201
+	public function getStylesheetAsset($identifier)
202
+	{
203
+		return $this->getAssetOfType($identifier, Asset::TYPE_CSS);
204
+	}
205
+
206
+
207
+	/**
208
+	 * has
209
+	 * returns TRUE or FALSE
210
+	 * depending on whether the Javascript Asset is within the Collection
211
+	 * based on the supplied $identifier
212
+	 *
213
+	 * @access public
214
+	 * @param  mixed $identifier
215
+	 * @return JavascriptAsset
216
+	 */
217
+	public function getJavascriptAsset($identifier)
218
+	{
219
+		return $this->getAssetOfType($identifier, Asset::TYPE_JS);
220
+	}
221 221
 }
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@  discard block
 block discarded – undo
75 75
             /** @var Asset $asset */
76 76
             $asset = $this->current();
77 77
             if ($asset->type() === $type) {
78
-                $files[ $asset->handle() ] = $asset;
78
+                $files[$asset->handle()] = $asset;
79 79
             }
80 80
             $this->next();
81 81
         }
@@ -96,7 +96,7 @@  discard block
 block discarded – undo
96 96
             /** @var JavascriptAsset $asset */
97 97
             $asset = $this->current();
98 98
             if ($asset->type() === Asset::TYPE_JS && $asset->hasInlineData()) {
99
-                $files[ $asset->handle() ] = $asset;
99
+                $files[$asset->handle()] = $asset;
100 100
             }
101 101
             $this->next();
102 102
         }
Please login to merge, or discard this patch.
core/services/assets/BlockAssetManager.php 3 patches
Unused Use Statements   -1 removed lines patch added patch discarded remove patch
@@ -4,7 +4,6 @@
 block discarded – undo
4 4
 
5 5
 use EventEspresso\core\domain\entities\editor\BlockInterface;
6 6
 use EventEspresso\core\domain\services\assets\CoreAssetManager;
7
-use EventEspresso\core\domain\values\assets\Asset;
8 7
 use EventEspresso\core\domain\values\assets\BrowserAsset;
9 8
 use EventEspresso\core\domain\values\assets\JavascriptAsset;
10 9
 use EventEspresso\core\domain\values\assets\StylesheetAsset;
Please login to merge, or discard this patch.
Indentation   +306 added lines, -306 removed lines patch added patch discarded remove patch
@@ -23,311 +23,311 @@
 block discarded – undo
23 23
 abstract class BlockAssetManager extends AssetManager implements BlockAssetManagerInterface
24 24
 {
25 25
 
26
-    /**
27
-     * @var string $editor_script_handle
28
-     */
29
-    private $editor_script_handle;
30
-
31
-    /**
32
-     * @var string $editor_style_handle
33
-     */
34
-    private $editor_style_handle;
35
-
36
-    /**
37
-     * @var string $script_handle
38
-     */
39
-    private $script_handle;
40
-
41
-    /**
42
-     * @var string $style_handle
43
-     */
44
-    private $style_handle;
45
-
46
-
47
-    /**
48
-     * @return string
49
-     */
50
-    public function getEditorScriptHandle()
51
-    {
52
-        return $this->editor_script_handle;
53
-    }
54
-
55
-
56
-    /**
57
-     * @param string $editor_script_handle
58
-     */
59
-    public function setEditorScriptHandle($editor_script_handle)
60
-    {
61
-        if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
62
-            $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
63
-        }
64
-        $this->editor_script_handle = $editor_script_handle;
65
-    }
66
-
67
-
68
-    /**
69
-     * @return string
70
-     */
71
-    public function getEditorStyleHandle()
72
-    {
73
-        return $this->editor_style_handle;
74
-    }
75
-
76
-
77
-    /**
78
-     * @param string $editor_style_handle
79
-     */
80
-    public function setEditorStyleHandle($editor_style_handle)
81
-    {
82
-        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
83
-            $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
84
-        }
85
-        $this->editor_style_handle = $editor_style_handle;
86
-    }
87
-
88
-
89
-    /**
90
-     * @return string
91
-     */
92
-    public function getScriptHandle()
93
-    {
94
-        return $this->script_handle;
95
-    }
96
-
97
-
98
-    /**
99
-     * @param string $script_handle
100
-     */
101
-    public function setScriptHandle($script_handle)
102
-    {
103
-        if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
104
-            $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
105
-        }
106
-        $this->script_handle = $script_handle;
107
-    }
108
-
109
-
110
-    /**
111
-     * @return string
112
-     */
113
-    public function getStyleHandle()
114
-    {
115
-        return $this->style_handle;
116
-    }
117
-
118
-
119
-    /**
120
-     * @param string $style_handle
121
-     */
122
-    public function setStyleHandle($style_handle)
123
-    {
124
-        if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
125
-            $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
126
-        }
127
-        $this->style_handle = $style_handle;
128
-    }
129
-
130
-    /**
131
-     * @since $VID:$
132
-     * @throws InvalidDataTypeException
133
-     * @throws InvalidEntityException
134
-     * @throws DuplicateCollectionIdentifierException
135
-     */
136
-    public function addAssets()
137
-    {
138
-        $this->addEditorScript($this->getEditorScriptHandle());
139
-        $this->addEditorStyle($this->getEditorStyleHandle());
140
-        $this->setScriptHandle($this->getScriptHandle());
141
-        $this->setStyleHandle($this->getStyleHandle());
142
-    }
143
-
144
-
145
-    /**
146
-     * @param       $handle
147
-     * @param array $dependencies
148
-     * @since $VID:$
149
-     * @return JavascriptAsset
150
-     * @throws InvalidDataTypeException
151
-     * @throws InvalidEntityException
152
-     * @throws DuplicateCollectionIdentifierException
153
-     */
154
-    public function addEditorScript($handle, array $dependencies = array())
155
-    {
156
-        if($this->assets->hasJavascriptAsset($handle)){
157
-            return $this->assets->getJavascriptAsset($handle);
158
-        }
159
-        return parent::addJavascript(
160
-            $handle,
161
-            $this->registry->getJsUrl(
162
-                $this->domain->assetNamespace(),
163
-                $handle
164
-            ),
165
-            $this->addDefaultBlockScriptDependencies($dependencies)
166
-        )
167
-        ->setRequiresTranslation();
168
-    }
169
-
170
-
171
-    /**
172
-     * @param        $handle
173
-     * @param array  $dependencies
174
-     * @since $VID:$
175
-     * @return StylesheetAsset
176
-     * @throws InvalidDataTypeException
177
-     * @throws InvalidEntityException
178
-     * @throws DuplicateCollectionIdentifierException
179
-     */
180
-    public function addEditorStyle($handle, array $dependencies = array())
181
-    {
182
-        if ($this->assets->hasStylesheetAsset($handle)) {
183
-            return $this->assets->getStylesheetAsset($handle);
184
-        }
185
-        return parent::addStylesheet(
186
-            $handle,
187
-            $this->registry->getCssUrl(
188
-                $this->domain->assetNamespace(),
189
-                $handle
190
-            ),
191
-            $dependencies
192
-        );
193
-    }
194
-
195
-
196
-    /**
197
-     * @param       $handle
198
-     * @param array $dependencies
199
-     * @since $VID:$
200
-     * @return JavascriptAsset
201
-     * @throws InvalidDataTypeException
202
-     * @throws InvalidEntityException
203
-     * @throws DuplicateCollectionIdentifierException
204
-     */
205
-    public function addScript($handle, array $dependencies = array())
206
-    {
207
-        if ($this->assets->hasJavascriptAsset($handle)) {
208
-            return $this->assets->getJavascriptAsset($handle);
209
-        }
210
-        return parent::addJavascript(
211
-            $handle,
212
-            $this->registry->getJsUrl(
213
-                $this->domain->assetNamespace(),
214
-                $handle
215
-            ),
216
-            $this->addDefaultBlockScriptDependencies($dependencies)
217
-        )
218
-        ->setRequiresTranslation();
219
-    }
220
-
221
-
222
-    /**
223
-     * @param        $handle
224
-     * @param array  $dependencies
225
-     * @since $VID:$
226
-     * @return StylesheetAsset
227
-     * @throws InvalidDataTypeException
228
-     * @throws InvalidEntityException
229
-     * @throws DuplicateCollectionIdentifierException
230
-     */
231
-    public function addStyle($handle, array $dependencies = array())
232
-    {
233
-        if ($this->assets->hasStylesheetAsset($handle)) {
234
-            return $this->assets->getStylesheetAsset($handle);
235
-        }
236
-        return parent::addStylesheet(
237
-            $handle,
238
-            $this->registry->getCssUrl(
239
-                $this->domain->assetNamespace(),
240
-                $handle
241
-            ),
242
-            $dependencies
243
-        );
244
-    }
245
-
246
-
247
-    /**
248
-     * @param array $dependencies
249
-     * @return array
250
-     */
251
-    protected function addDefaultBlockScriptDependencies(array $dependencies)
252
-    {
253
-        $dependencies += array(
254
-                'wp-blocks',    // Provides useful functions and components for extending the editor
255
-                'wp-i18n',      // Provides localization functions
256
-                'wp-element',   // Provides React.Component
257
-                'wp-components', // Provides many prebuilt components and controls
258
-                CoreAssetManager::JS_HANDLE_EE_COMPONENTS
259
-            );
260
-        return $dependencies;
261
-    }
262
-
263
-
264
-    /**
265
-     * @param string $handle
266
-     * @param string $type
267
-     * @return mixed|null
268
-     * @since $VID:$
269
-     */
270
-    public function getAsset($handle, $type)
271
-    {
272
-        if ($this->assets->hasAssetOfType($handle, $type)) {
273
-            return $this->assets->getAssetOfType($handle, $type);
274
-        }
275
-        return null;
276
-    }
277
-
278
-
279
-    /**
280
-     * @return JavascriptAsset|null
281
-     */
282
-    public function getEditorScript()
283
-    {
284
-        return $this->assets->getJavascriptAsset($this->editor_script_handle);
285
-    }
286
-
287
-
288
-    /**
289
-     * @return StylesheetAsset|null
290
-     */
291
-    public function getEditorStyle()
292
-    {
293
-        return $this->assets->getStylesheetAsset($this->editor_style_handle);
294
-    }
295
-
296
-
297
-    /**
298
-     * @return JavascriptAsset|null
299
-     */
300
-    public function getScript()
301
-    {
302
-        return $this->assets->getJavascriptAsset($this->script_handle);
303
-    }
304
-
305
-
306
-    /**
307
-     * @return StylesheetAsset|null
308
-     */
309
-    public function getStyle()
310
-    {
311
-        return $this->assets->getStylesheetAsset($this->style_handle);
312
-    }
313
-
314
-
315
-    /**
316
-     * @return  void
317
-     */
318
-    public function enqueueAssets()
319
-    {
320
-        $assets = array(
321
-            $this->getEditorScript(),
322
-            $this->getEditorStyle(),
323
-            $this->getScript(),
324
-            $this->getStyle(),
325
-        );
326
-        foreach ($assets as $asset) {
327
-            if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
328
-                $asset->enqueueAsset();
329
-            }
330
-        }
331
-    }
26
+	/**
27
+	 * @var string $editor_script_handle
28
+	 */
29
+	private $editor_script_handle;
30
+
31
+	/**
32
+	 * @var string $editor_style_handle
33
+	 */
34
+	private $editor_style_handle;
35
+
36
+	/**
37
+	 * @var string $script_handle
38
+	 */
39
+	private $script_handle;
40
+
41
+	/**
42
+	 * @var string $style_handle
43
+	 */
44
+	private $style_handle;
45
+
46
+
47
+	/**
48
+	 * @return string
49
+	 */
50
+	public function getEditorScriptHandle()
51
+	{
52
+		return $this->editor_script_handle;
53
+	}
54
+
55
+
56
+	/**
57
+	 * @param string $editor_script_handle
58
+	 */
59
+	public function setEditorScriptHandle($editor_script_handle)
60
+	{
61
+		if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
62
+			$editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
63
+		}
64
+		$this->editor_script_handle = $editor_script_handle;
65
+	}
66
+
67
+
68
+	/**
69
+	 * @return string
70
+	 */
71
+	public function getEditorStyleHandle()
72
+	{
73
+		return $this->editor_style_handle;
74
+	}
75
+
76
+
77
+	/**
78
+	 * @param string $editor_style_handle
79
+	 */
80
+	public function setEditorStyleHandle($editor_style_handle)
81
+	{
82
+		if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
83
+			$editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
84
+		}
85
+		$this->editor_style_handle = $editor_style_handle;
86
+	}
87
+
88
+
89
+	/**
90
+	 * @return string
91
+	 */
92
+	public function getScriptHandle()
93
+	{
94
+		return $this->script_handle;
95
+	}
96
+
97
+
98
+	/**
99
+	 * @param string $script_handle
100
+	 */
101
+	public function setScriptHandle($script_handle)
102
+	{
103
+		if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
104
+			$script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
105
+		}
106
+		$this->script_handle = $script_handle;
107
+	}
108
+
109
+
110
+	/**
111
+	 * @return string
112
+	 */
113
+	public function getStyleHandle()
114
+	{
115
+		return $this->style_handle;
116
+	}
117
+
118
+
119
+	/**
120
+	 * @param string $style_handle
121
+	 */
122
+	public function setStyleHandle($style_handle)
123
+	{
124
+		if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
125
+			$style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
126
+		}
127
+		$this->style_handle = $style_handle;
128
+	}
129
+
130
+	/**
131
+	 * @since $VID:$
132
+	 * @throws InvalidDataTypeException
133
+	 * @throws InvalidEntityException
134
+	 * @throws DuplicateCollectionIdentifierException
135
+	 */
136
+	public function addAssets()
137
+	{
138
+		$this->addEditorScript($this->getEditorScriptHandle());
139
+		$this->addEditorStyle($this->getEditorStyleHandle());
140
+		$this->setScriptHandle($this->getScriptHandle());
141
+		$this->setStyleHandle($this->getStyleHandle());
142
+	}
143
+
144
+
145
+	/**
146
+	 * @param       $handle
147
+	 * @param array $dependencies
148
+	 * @since $VID:$
149
+	 * @return JavascriptAsset
150
+	 * @throws InvalidDataTypeException
151
+	 * @throws InvalidEntityException
152
+	 * @throws DuplicateCollectionIdentifierException
153
+	 */
154
+	public function addEditorScript($handle, array $dependencies = array())
155
+	{
156
+		if($this->assets->hasJavascriptAsset($handle)){
157
+			return $this->assets->getJavascriptAsset($handle);
158
+		}
159
+		return parent::addJavascript(
160
+			$handle,
161
+			$this->registry->getJsUrl(
162
+				$this->domain->assetNamespace(),
163
+				$handle
164
+			),
165
+			$this->addDefaultBlockScriptDependencies($dependencies)
166
+		)
167
+		->setRequiresTranslation();
168
+	}
169
+
170
+
171
+	/**
172
+	 * @param        $handle
173
+	 * @param array  $dependencies
174
+	 * @since $VID:$
175
+	 * @return StylesheetAsset
176
+	 * @throws InvalidDataTypeException
177
+	 * @throws InvalidEntityException
178
+	 * @throws DuplicateCollectionIdentifierException
179
+	 */
180
+	public function addEditorStyle($handle, array $dependencies = array())
181
+	{
182
+		if ($this->assets->hasStylesheetAsset($handle)) {
183
+			return $this->assets->getStylesheetAsset($handle);
184
+		}
185
+		return parent::addStylesheet(
186
+			$handle,
187
+			$this->registry->getCssUrl(
188
+				$this->domain->assetNamespace(),
189
+				$handle
190
+			),
191
+			$dependencies
192
+		);
193
+	}
194
+
195
+
196
+	/**
197
+	 * @param       $handle
198
+	 * @param array $dependencies
199
+	 * @since $VID:$
200
+	 * @return JavascriptAsset
201
+	 * @throws InvalidDataTypeException
202
+	 * @throws InvalidEntityException
203
+	 * @throws DuplicateCollectionIdentifierException
204
+	 */
205
+	public function addScript($handle, array $dependencies = array())
206
+	{
207
+		if ($this->assets->hasJavascriptAsset($handle)) {
208
+			return $this->assets->getJavascriptAsset($handle);
209
+		}
210
+		return parent::addJavascript(
211
+			$handle,
212
+			$this->registry->getJsUrl(
213
+				$this->domain->assetNamespace(),
214
+				$handle
215
+			),
216
+			$this->addDefaultBlockScriptDependencies($dependencies)
217
+		)
218
+		->setRequiresTranslation();
219
+	}
220
+
221
+
222
+	/**
223
+	 * @param        $handle
224
+	 * @param array  $dependencies
225
+	 * @since $VID:$
226
+	 * @return StylesheetAsset
227
+	 * @throws InvalidDataTypeException
228
+	 * @throws InvalidEntityException
229
+	 * @throws DuplicateCollectionIdentifierException
230
+	 */
231
+	public function addStyle($handle, array $dependencies = array())
232
+	{
233
+		if ($this->assets->hasStylesheetAsset($handle)) {
234
+			return $this->assets->getStylesheetAsset($handle);
235
+		}
236
+		return parent::addStylesheet(
237
+			$handle,
238
+			$this->registry->getCssUrl(
239
+				$this->domain->assetNamespace(),
240
+				$handle
241
+			),
242
+			$dependencies
243
+		);
244
+	}
245
+
246
+
247
+	/**
248
+	 * @param array $dependencies
249
+	 * @return array
250
+	 */
251
+	protected function addDefaultBlockScriptDependencies(array $dependencies)
252
+	{
253
+		$dependencies += array(
254
+				'wp-blocks',    // Provides useful functions and components for extending the editor
255
+				'wp-i18n',      // Provides localization functions
256
+				'wp-element',   // Provides React.Component
257
+				'wp-components', // Provides many prebuilt components and controls
258
+				CoreAssetManager::JS_HANDLE_EE_COMPONENTS
259
+			);
260
+		return $dependencies;
261
+	}
262
+
263
+
264
+	/**
265
+	 * @param string $handle
266
+	 * @param string $type
267
+	 * @return mixed|null
268
+	 * @since $VID:$
269
+	 */
270
+	public function getAsset($handle, $type)
271
+	{
272
+		if ($this->assets->hasAssetOfType($handle, $type)) {
273
+			return $this->assets->getAssetOfType($handle, $type);
274
+		}
275
+		return null;
276
+	}
277
+
278
+
279
+	/**
280
+	 * @return JavascriptAsset|null
281
+	 */
282
+	public function getEditorScript()
283
+	{
284
+		return $this->assets->getJavascriptAsset($this->editor_script_handle);
285
+	}
286
+
287
+
288
+	/**
289
+	 * @return StylesheetAsset|null
290
+	 */
291
+	public function getEditorStyle()
292
+	{
293
+		return $this->assets->getStylesheetAsset($this->editor_style_handle);
294
+	}
295
+
296
+
297
+	/**
298
+	 * @return JavascriptAsset|null
299
+	 */
300
+	public function getScript()
301
+	{
302
+		return $this->assets->getJavascriptAsset($this->script_handle);
303
+	}
304
+
305
+
306
+	/**
307
+	 * @return StylesheetAsset|null
308
+	 */
309
+	public function getStyle()
310
+	{
311
+		return $this->assets->getStylesheetAsset($this->style_handle);
312
+	}
313
+
314
+
315
+	/**
316
+	 * @return  void
317
+	 */
318
+	public function enqueueAssets()
319
+	{
320
+		$assets = array(
321
+			$this->getEditorScript(),
322
+			$this->getEditorStyle(),
323
+			$this->getScript(),
324
+			$this->getStyle(),
325
+		);
326
+		foreach ($assets as $asset) {
327
+			if ($asset instanceof BrowserAsset && $asset->isRegistered()) {
328
+				$asset->enqueueAsset();
329
+			}
330
+		}
331
+	}
332 332
 
333 333
 }
Please login to merge, or discard this patch.
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -58,8 +58,8 @@  discard block
 block discarded – undo
58 58
      */
59 59
     public function setEditorScriptHandle($editor_script_handle)
60 60
     {
61
-        if(strpos($editor_script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
62
-            $editor_script_handle = BlockInterface::NAME_SPACE . '-' . $editor_script_handle;
61
+        if (strpos($editor_script_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
62
+            $editor_script_handle = BlockInterface::NAME_SPACE.'-'.$editor_script_handle;
63 63
         }
64 64
         $this->editor_script_handle = $editor_script_handle;
65 65
     }
@@ -79,8 +79,8 @@  discard block
 block discarded – undo
79 79
      */
80 80
     public function setEditorStyleHandle($editor_style_handle)
81 81
     {
82
-        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
83
-            $editor_style_handle = BlockInterface::NAME_SPACE . '-' . $editor_style_handle;
82
+        if (strpos($editor_style_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
83
+            $editor_style_handle = BlockInterface::NAME_SPACE.'-'.$editor_style_handle;
84 84
         }
85 85
         $this->editor_style_handle = $editor_style_handle;
86 86
     }
@@ -100,8 +100,8 @@  discard block
 block discarded – undo
100 100
      */
101 101
     public function setScriptHandle($script_handle)
102 102
     {
103
-        if (strpos($script_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
104
-            $script_handle = BlockInterface::NAME_SPACE . '-' . $script_handle;
103
+        if (strpos($script_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
104
+            $script_handle = BlockInterface::NAME_SPACE.'-'.$script_handle;
105 105
         }
106 106
         $this->script_handle = $script_handle;
107 107
     }
@@ -121,8 +121,8 @@  discard block
 block discarded – undo
121 121
      */
122 122
     public function setStyleHandle($style_handle)
123 123
     {
124
-        if (strpos($style_handle, BlockInterface::NAME_SPACE . '-') !== 0) {
125
-            $style_handle = BlockInterface::NAME_SPACE . '-' . $style_handle;
124
+        if (strpos($style_handle, BlockInterface::NAME_SPACE.'-') !== 0) {
125
+            $style_handle = BlockInterface::NAME_SPACE.'-'.$style_handle;
126 126
         }
127 127
         $this->style_handle = $style_handle;
128 128
     }
@@ -153,7 +153,7 @@  discard block
 block discarded – undo
153 153
      */
154 154
     public function addEditorScript($handle, array $dependencies = array())
155 155
     {
156
-        if($this->assets->hasJavascriptAsset($handle)){
156
+        if ($this->assets->hasJavascriptAsset($handle)) {
157 157
             return $this->assets->getJavascriptAsset($handle);
158 158
         }
159 159
         return parent::addJavascript(
@@ -251,9 +251,9 @@  discard block
 block discarded – undo
251 251
     protected function addDefaultBlockScriptDependencies(array $dependencies)
252 252
     {
253 253
         $dependencies += array(
254
-                'wp-blocks',    // Provides useful functions and components for extending the editor
255
-                'wp-i18n',      // Provides localization functions
256
-                'wp-element',   // Provides React.Component
254
+                'wp-blocks', // Provides useful functions and components for extending the editor
255
+                'wp-i18n', // Provides localization functions
256
+                'wp-element', // Provides React.Component
257 257
                 'wp-components', // Provides many prebuilt components and controls
258 258
                 CoreAssetManager::JS_HANDLE_EE_COMPONENTS
259 259
             );
Please login to merge, or discard this patch.