@@ -23,179 +23,179 @@ |
||
23 | 23 | abstract class AssetManager implements AssetManagerInterface |
24 | 24 | { |
25 | 25 | |
26 | - /** |
|
27 | - * @var AssetCollection $assets |
|
28 | - */ |
|
29 | - protected $assets; |
|
30 | - |
|
31 | - /** |
|
32 | - * @var DomainInterface |
|
33 | - */ |
|
34 | - protected $domain; |
|
35 | - |
|
36 | - /** |
|
37 | - * @var Registry $registry |
|
38 | - */ |
|
39 | - protected $registry; |
|
40 | - |
|
41 | - |
|
42 | - /** |
|
43 | - * AssetRegister constructor. |
|
44 | - * |
|
45 | - * @param DomainInterface $domain |
|
46 | - * @param AssetCollection $assets |
|
47 | - * @param Registry $registry |
|
48 | - */ |
|
49 | - public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
50 | - { |
|
51 | - $this->domain = $domain; |
|
52 | - $this->assets = $assets; |
|
53 | - $this->registry = $registry; |
|
54 | - add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
55 | - add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
56 | - add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
57 | - add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
58 | - } |
|
59 | - |
|
60 | - |
|
61 | - /** |
|
62 | - * @since $VID:$ |
|
63 | - * @return string |
|
64 | - */ |
|
65 | - public function assetNamespace() |
|
66 | - { |
|
67 | - return $this->domain->assetNamespace(); |
|
68 | - } |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @return void |
|
73 | - * @throws DuplicateCollectionIdentifierException |
|
74 | - * @throws InvalidDataTypeException |
|
75 | - * @throws InvalidEntityException |
|
76 | - * @since 4.9.62.p |
|
77 | - */ |
|
78 | - public function addManifestFile() |
|
79 | - { |
|
80 | - // if a manifest file has already been added for this domain, then just return |
|
81 | - if ($this->assets->has($this->domain->assetNamespace())) { |
|
82 | - return; |
|
83 | - } |
|
84 | - $asset = new ManifestFile($this->domain); |
|
85 | - $this->assets->add($asset, $this->domain->assetNamespace()); |
|
86 | - } |
|
87 | - |
|
88 | - |
|
89 | - /** |
|
90 | - * @return ManifestFile[] |
|
91 | - * @since 4.9.62.p |
|
92 | - */ |
|
93 | - public function getManifestFile() |
|
94 | - { |
|
95 | - return $this->assets->getManifestFiles(); |
|
96 | - } |
|
97 | - |
|
98 | - |
|
99 | - /** |
|
100 | - * @param string $handle |
|
101 | - * @param string $source |
|
102 | - * @param array $dependencies |
|
103 | - * @param bool $load_in_footer |
|
104 | - * @return JavascriptAsset |
|
105 | - * @throws DuplicateCollectionIdentifierException |
|
106 | - * @throws InvalidDataTypeException |
|
107 | - * @throws InvalidEntityException |
|
108 | - * @since 4.9.62.p |
|
109 | - */ |
|
110 | - public function addJavascript( |
|
111 | - $handle, |
|
112 | - $source, |
|
113 | - array $dependencies = array(), |
|
114 | - $load_in_footer = true |
|
115 | - ) { |
|
116 | - $asset = new JavascriptAsset( |
|
117 | - $handle, |
|
118 | - $source, |
|
119 | - $dependencies, |
|
120 | - $load_in_footer, |
|
121 | - $this->domain |
|
122 | - ); |
|
123 | - $this->assets->add($asset, $handle); |
|
124 | - return $asset; |
|
125 | - } |
|
126 | - |
|
127 | - |
|
128 | - /** |
|
129 | - * @param string $handle |
|
130 | - * @param array $dependencies |
|
131 | - * @param bool $load_in_footer |
|
132 | - * @return JavascriptAsset |
|
133 | - * @throws DuplicateCollectionIdentifierException |
|
134 | - * @throws InvalidDataTypeException |
|
135 | - * @throws InvalidEntityException |
|
136 | - * @throws DomainException |
|
137 | - * @since $VID:$ |
|
138 | - */ |
|
139 | - public function addVendorJavascript( |
|
140 | - $handle, |
|
141 | - array $dependencies = array(), |
|
142 | - $load_in_footer = true |
|
143 | - ) { |
|
144 | - $dev_suffix = wp_scripts_get_suffix('dev'); |
|
145 | - $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/'; |
|
146 | - return $this->addJavascript( |
|
147 | - $handle, |
|
148 | - "{$vendor_path}{$handle}{$dev_suffix}.js", |
|
149 | - $dependencies, |
|
150 | - $load_in_footer |
|
151 | - ); |
|
152 | - } |
|
153 | - |
|
154 | - |
|
155 | - |
|
156 | - /** |
|
157 | - * @param string $handle |
|
158 | - * @param string $source |
|
159 | - * @param array $dependencies |
|
160 | - * @param string $media |
|
161 | - * @return StylesheetAsset |
|
162 | - * @throws DuplicateCollectionIdentifierException |
|
163 | - * @throws InvalidDataTypeException |
|
164 | - * @throws InvalidEntityException |
|
165 | - * @since 4.9.62.p |
|
166 | - */ |
|
167 | - public function addStylesheet( |
|
168 | - $handle, |
|
169 | - $source, |
|
170 | - array $dependencies = array(), |
|
171 | - $media = 'all' |
|
172 | - ) { |
|
173 | - $asset = new StylesheetAsset( |
|
174 | - $handle, |
|
175 | - $source, |
|
176 | - $dependencies, |
|
177 | - $this->domain, |
|
178 | - $media |
|
179 | - ); |
|
180 | - $this->assets->add($asset, $handle); |
|
181 | - return $asset; |
|
182 | - } |
|
183 | - |
|
184 | - |
|
185 | - /** |
|
186 | - * @param string $handle |
|
187 | - * @return bool |
|
188 | - * @since 4.9.62.p |
|
189 | - */ |
|
190 | - public function enqueueAsset($handle) |
|
191 | - { |
|
192 | - if ($this->assets->has($handle)) { |
|
193 | - $asset = $this->assets->get($handle); |
|
194 | - if ($asset->isRegistered()) { |
|
195 | - $asset->enqueueAsset(); |
|
196 | - return true; |
|
197 | - } |
|
198 | - } |
|
199 | - return false; |
|
200 | - } |
|
26 | + /** |
|
27 | + * @var AssetCollection $assets |
|
28 | + */ |
|
29 | + protected $assets; |
|
30 | + |
|
31 | + /** |
|
32 | + * @var DomainInterface |
|
33 | + */ |
|
34 | + protected $domain; |
|
35 | + |
|
36 | + /** |
|
37 | + * @var Registry $registry |
|
38 | + */ |
|
39 | + protected $registry; |
|
40 | + |
|
41 | + |
|
42 | + /** |
|
43 | + * AssetRegister constructor. |
|
44 | + * |
|
45 | + * @param DomainInterface $domain |
|
46 | + * @param AssetCollection $assets |
|
47 | + * @param Registry $registry |
|
48 | + */ |
|
49 | + public function __construct(DomainInterface $domain, AssetCollection $assets, Registry $registry) |
|
50 | + { |
|
51 | + $this->domain = $domain; |
|
52 | + $this->assets = $assets; |
|
53 | + $this->registry = $registry; |
|
54 | + add_action('wp_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
55 | + add_action('admin_enqueue_scripts', array($this, 'addManifestFile'), 0); |
|
56 | + add_action('wp_enqueue_scripts', array($this, 'addAssets'), 2); |
|
57 | + add_action('admin_enqueue_scripts', array($this, 'addAssets'), 2); |
|
58 | + } |
|
59 | + |
|
60 | + |
|
61 | + /** |
|
62 | + * @since $VID:$ |
|
63 | + * @return string |
|
64 | + */ |
|
65 | + public function assetNamespace() |
|
66 | + { |
|
67 | + return $this->domain->assetNamespace(); |
|
68 | + } |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @return void |
|
73 | + * @throws DuplicateCollectionIdentifierException |
|
74 | + * @throws InvalidDataTypeException |
|
75 | + * @throws InvalidEntityException |
|
76 | + * @since 4.9.62.p |
|
77 | + */ |
|
78 | + public function addManifestFile() |
|
79 | + { |
|
80 | + // if a manifest file has already been added for this domain, then just return |
|
81 | + if ($this->assets->has($this->domain->assetNamespace())) { |
|
82 | + return; |
|
83 | + } |
|
84 | + $asset = new ManifestFile($this->domain); |
|
85 | + $this->assets->add($asset, $this->domain->assetNamespace()); |
|
86 | + } |
|
87 | + |
|
88 | + |
|
89 | + /** |
|
90 | + * @return ManifestFile[] |
|
91 | + * @since 4.9.62.p |
|
92 | + */ |
|
93 | + public function getManifestFile() |
|
94 | + { |
|
95 | + return $this->assets->getManifestFiles(); |
|
96 | + } |
|
97 | + |
|
98 | + |
|
99 | + /** |
|
100 | + * @param string $handle |
|
101 | + * @param string $source |
|
102 | + * @param array $dependencies |
|
103 | + * @param bool $load_in_footer |
|
104 | + * @return JavascriptAsset |
|
105 | + * @throws DuplicateCollectionIdentifierException |
|
106 | + * @throws InvalidDataTypeException |
|
107 | + * @throws InvalidEntityException |
|
108 | + * @since 4.9.62.p |
|
109 | + */ |
|
110 | + public function addJavascript( |
|
111 | + $handle, |
|
112 | + $source, |
|
113 | + array $dependencies = array(), |
|
114 | + $load_in_footer = true |
|
115 | + ) { |
|
116 | + $asset = new JavascriptAsset( |
|
117 | + $handle, |
|
118 | + $source, |
|
119 | + $dependencies, |
|
120 | + $load_in_footer, |
|
121 | + $this->domain |
|
122 | + ); |
|
123 | + $this->assets->add($asset, $handle); |
|
124 | + return $asset; |
|
125 | + } |
|
126 | + |
|
127 | + |
|
128 | + /** |
|
129 | + * @param string $handle |
|
130 | + * @param array $dependencies |
|
131 | + * @param bool $load_in_footer |
|
132 | + * @return JavascriptAsset |
|
133 | + * @throws DuplicateCollectionIdentifierException |
|
134 | + * @throws InvalidDataTypeException |
|
135 | + * @throws InvalidEntityException |
|
136 | + * @throws DomainException |
|
137 | + * @since $VID:$ |
|
138 | + */ |
|
139 | + public function addVendorJavascript( |
|
140 | + $handle, |
|
141 | + array $dependencies = array(), |
|
142 | + $load_in_footer = true |
|
143 | + ) { |
|
144 | + $dev_suffix = wp_scripts_get_suffix('dev'); |
|
145 | + $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/'; |
|
146 | + return $this->addJavascript( |
|
147 | + $handle, |
|
148 | + "{$vendor_path}{$handle}{$dev_suffix}.js", |
|
149 | + $dependencies, |
|
150 | + $load_in_footer |
|
151 | + ); |
|
152 | + } |
|
153 | + |
|
154 | + |
|
155 | + |
|
156 | + /** |
|
157 | + * @param string $handle |
|
158 | + * @param string $source |
|
159 | + * @param array $dependencies |
|
160 | + * @param string $media |
|
161 | + * @return StylesheetAsset |
|
162 | + * @throws DuplicateCollectionIdentifierException |
|
163 | + * @throws InvalidDataTypeException |
|
164 | + * @throws InvalidEntityException |
|
165 | + * @since 4.9.62.p |
|
166 | + */ |
|
167 | + public function addStylesheet( |
|
168 | + $handle, |
|
169 | + $source, |
|
170 | + array $dependencies = array(), |
|
171 | + $media = 'all' |
|
172 | + ) { |
|
173 | + $asset = new StylesheetAsset( |
|
174 | + $handle, |
|
175 | + $source, |
|
176 | + $dependencies, |
|
177 | + $this->domain, |
|
178 | + $media |
|
179 | + ); |
|
180 | + $this->assets->add($asset, $handle); |
|
181 | + return $asset; |
|
182 | + } |
|
183 | + |
|
184 | + |
|
185 | + /** |
|
186 | + * @param string $handle |
|
187 | + * @return bool |
|
188 | + * @since 4.9.62.p |
|
189 | + */ |
|
190 | + public function enqueueAsset($handle) |
|
191 | + { |
|
192 | + if ($this->assets->has($handle)) { |
|
193 | + $asset = $this->assets->get($handle); |
|
194 | + if ($asset->isRegistered()) { |
|
195 | + $asset->enqueueAsset(); |
|
196 | + return true; |
|
197 | + } |
|
198 | + } |
|
199 | + return false; |
|
200 | + } |
|
201 | 201 | } |
@@ -142,7 +142,7 @@ |
||
142 | 142 | $load_in_footer = true |
143 | 143 | ) { |
144 | 144 | $dev_suffix = wp_scripts_get_suffix('dev'); |
145 | - $vendor_path = $this->domain->pluginUrl() . 'assets/vendor/'; |
|
145 | + $vendor_path = $this->domain->pluginUrl().'assets/vendor/'; |
|
146 | 146 | return $this->addJavascript( |
147 | 147 | $handle, |
148 | 148 | "{$vendor_path}{$handle}{$dev_suffix}.js", |
@@ -20,92 +20,92 @@ |
||
20 | 20 | */ |
21 | 21 | interface AssetManagerInterface |
22 | 22 | { |
23 | - /** |
|
24 | - * @since $VID:$ |
|
25 | - * @return string |
|
26 | - */ |
|
27 | - public function assetNamespace(); |
|
28 | - |
|
29 | - /** |
|
30 | - * @since 4.9.62.p |
|
31 | - */ |
|
32 | - public function addAssets(); |
|
33 | - |
|
34 | - |
|
35 | - /** |
|
36 | - * @return ManifestFile |
|
37 | - * @throws DuplicateCollectionIdentifierException |
|
38 | - * @throws InvalidDataTypeException |
|
39 | - * @throws InvalidEntityException |
|
40 | - * @since 4.9.62.p |
|
41 | - */ |
|
42 | - public function addManifestFile(); |
|
43 | - |
|
44 | - |
|
45 | - /** |
|
46 | - * @return ManifestFile[] |
|
47 | - * @since 4.9.62.p |
|
48 | - */ |
|
49 | - public function getManifestFile(); |
|
50 | - |
|
51 | - |
|
52 | - /** |
|
53 | - * @param string $handle |
|
54 | - * @param string $source |
|
55 | - * @param array $dependencies |
|
56 | - * @param bool $load_in_footer |
|
57 | - * @return JavascriptAsset |
|
58 | - * @throws DuplicateCollectionIdentifierException |
|
59 | - * @throws InvalidDataTypeException |
|
60 | - * @throws InvalidEntityException |
|
61 | - * @since 4.9.62.p |
|
62 | - */ |
|
63 | - public function addJavascript( |
|
64 | - $handle, |
|
65 | - $source, |
|
66 | - array $dependencies = array(), |
|
67 | - $load_in_footer = true |
|
68 | - ); |
|
69 | - |
|
70 | - |
|
71 | - /** |
|
72 | - * @since $VID:$ |
|
73 | - * @param string $handle |
|
74 | - * @param array $dependencies |
|
75 | - * @param bool $load_in_footer |
|
76 | - * @return JavascriptAsset |
|
77 | - */ |
|
78 | - public function addVendorJavascript( |
|
79 | - $handle, |
|
80 | - array $dependencies = array(), |
|
81 | - $load_in_footer = true |
|
82 | - ); |
|
83 | - |
|
84 | - |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $handle |
|
88 | - * @param string $source |
|
89 | - * @param array $dependencies |
|
90 | - * @param string $media |
|
91 | - * @return StylesheetAsset |
|
92 | - * @throws DuplicateCollectionIdentifierException |
|
93 | - * @throws InvalidDataTypeException |
|
94 | - * @throws InvalidEntityException |
|
95 | - * @since 4.9.62.p |
|
96 | - */ |
|
97 | - public function addStylesheet( |
|
98 | - $handle, |
|
99 | - $source, |
|
100 | - array $dependencies = array(), |
|
101 | - $media = 'all' |
|
102 | - ); |
|
103 | - |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $handle |
|
107 | - * @return bool |
|
108 | - * @since 4.9.62.p |
|
109 | - */ |
|
110 | - public function enqueueAsset($handle); |
|
23 | + /** |
|
24 | + * @since $VID:$ |
|
25 | + * @return string |
|
26 | + */ |
|
27 | + public function assetNamespace(); |
|
28 | + |
|
29 | + /** |
|
30 | + * @since 4.9.62.p |
|
31 | + */ |
|
32 | + public function addAssets(); |
|
33 | + |
|
34 | + |
|
35 | + /** |
|
36 | + * @return ManifestFile |
|
37 | + * @throws DuplicateCollectionIdentifierException |
|
38 | + * @throws InvalidDataTypeException |
|
39 | + * @throws InvalidEntityException |
|
40 | + * @since 4.9.62.p |
|
41 | + */ |
|
42 | + public function addManifestFile(); |
|
43 | + |
|
44 | + |
|
45 | + /** |
|
46 | + * @return ManifestFile[] |
|
47 | + * @since 4.9.62.p |
|
48 | + */ |
|
49 | + public function getManifestFile(); |
|
50 | + |
|
51 | + |
|
52 | + /** |
|
53 | + * @param string $handle |
|
54 | + * @param string $source |
|
55 | + * @param array $dependencies |
|
56 | + * @param bool $load_in_footer |
|
57 | + * @return JavascriptAsset |
|
58 | + * @throws DuplicateCollectionIdentifierException |
|
59 | + * @throws InvalidDataTypeException |
|
60 | + * @throws InvalidEntityException |
|
61 | + * @since 4.9.62.p |
|
62 | + */ |
|
63 | + public function addJavascript( |
|
64 | + $handle, |
|
65 | + $source, |
|
66 | + array $dependencies = array(), |
|
67 | + $load_in_footer = true |
|
68 | + ); |
|
69 | + |
|
70 | + |
|
71 | + /** |
|
72 | + * @since $VID:$ |
|
73 | + * @param string $handle |
|
74 | + * @param array $dependencies |
|
75 | + * @param bool $load_in_footer |
|
76 | + * @return JavascriptAsset |
|
77 | + */ |
|
78 | + public function addVendorJavascript( |
|
79 | + $handle, |
|
80 | + array $dependencies = array(), |
|
81 | + $load_in_footer = true |
|
82 | + ); |
|
83 | + |
|
84 | + |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $handle |
|
88 | + * @param string $source |
|
89 | + * @param array $dependencies |
|
90 | + * @param string $media |
|
91 | + * @return StylesheetAsset |
|
92 | + * @throws DuplicateCollectionIdentifierException |
|
93 | + * @throws InvalidDataTypeException |
|
94 | + * @throws InvalidEntityException |
|
95 | + * @since 4.9.62.p |
|
96 | + */ |
|
97 | + public function addStylesheet( |
|
98 | + $handle, |
|
99 | + $source, |
|
100 | + array $dependencies = array(), |
|
101 | + $media = 'all' |
|
102 | + ); |
|
103 | + |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $handle |
|
107 | + * @return bool |
|
108 | + * @since 4.9.62.p |
|
109 | + */ |
|
110 | + public function enqueueAsset($handle); |
|
111 | 111 | } |