1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Leonidas\Framework\Module\Abstracts; |
4
|
|
|
|
5
|
|
|
use Leonidas\Contracts\Extension\ModuleInterface; |
6
|
|
|
use Leonidas\Contracts\Ui\Asset\InlineScriptCollectionInterface; |
7
|
|
|
use Leonidas\Contracts\Ui\Asset\InlineStyleCollectionInterface; |
8
|
|
|
use Leonidas\Contracts\Ui\Asset\ScriptCollectionInterface; |
9
|
|
|
use Leonidas\Contracts\Ui\Asset\ScriptLocalizationCollectionInterface; |
10
|
|
|
use Leonidas\Contracts\Ui\Asset\StyleCollectionInterface; |
11
|
|
|
use Leonidas\Framework\Module\Abstracts\Traits\ProvisionsAssetsTrait; |
12
|
|
|
use Leonidas\Hooks\TargetsAdminEnqueueScriptsHook; |
13
|
|
|
use Leonidas\Hooks\TargetsEnqueueBlockEditorAssetsHook; |
14
|
|
|
use Leonidas\Hooks\TargetsLoginEnqueueScriptsHook; |
15
|
|
|
use Leonidas\Hooks\TargetsScriptLoaderTagHook; |
16
|
|
|
use Leonidas\Hooks\TargetsStyleLoaderTagHook; |
17
|
|
|
use Leonidas\Hooks\TargetsWpEnqueueScriptsHook; |
18
|
|
|
|
19
|
|
|
abstract class GlobalAssetProviderModule extends Module implements ModuleInterface |
20
|
|
|
{ |
21
|
|
|
use TargetsEnqueueBlockEditorAssetsHook; |
22
|
|
|
use TargetsAdminEnqueueScriptsHook; |
23
|
|
|
use TargetsLoginEnqueueScriptsHook; |
24
|
|
|
use TargetsWpEnqueueScriptsHook; |
25
|
|
|
use TargetsScriptLoaderTagHook; |
26
|
|
|
use TargetsStyleLoaderTagHook; |
27
|
|
|
use ProvisionsAssetsTrait; |
28
|
|
|
|
29
|
|
|
protected const CONTEXTS = [ |
30
|
|
|
'admin_enqueue_scripts' => 'admin', |
31
|
|
|
'enqueue_block_editor_assets' => 'blockEditor', |
32
|
|
|
'login_enqueue_scripts' => 'login', |
33
|
|
|
'wp_enqueue_scripts' => 'public', |
34
|
|
|
]; |
35
|
|
|
|
36
|
|
|
public function hook(): void |
37
|
|
|
{ |
38
|
|
|
$this->targetEnqueueBlockEditorAssetsHook(); |
39
|
|
|
$this->targetAdminEnqueueScriptsHook(); |
40
|
|
|
$this->targetLoginEnqueueScriptsHook(); |
41
|
|
|
$this->targetWpEnqueueScriptsHook(); |
42
|
|
|
// $this->targetScriptLoaderTagHook(); |
43
|
|
|
// $this->targetStyleLoaderTagHook(); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
protected function doAdminEnqueueScriptsAction(string $hookSuffix): void |
47
|
|
|
{ |
48
|
|
|
$this->provisionAssets($hookSuffix); |
49
|
|
|
} |
50
|
|
|
|
51
|
|
|
protected function doEnqueueBlockEditorAssetsAction(): void |
52
|
|
|
{ |
53
|
|
|
$this->provisionAssets(); |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
protected function doLoginEnqueueScriptsAction(): void |
57
|
|
|
{ |
58
|
|
|
$this->provisionAssets(); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
protected function doWpEnqueueScriptsAction(): void |
62
|
|
|
{ |
63
|
|
|
$this->provisionAssets(); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
protected function scripts(): ?ScriptCollectionInterface |
67
|
|
|
{ |
68
|
|
|
return $this->getContextAssetsMethod('Scripts')(); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
protected function styles(): ?StyleCollectionInterface |
72
|
|
|
{ |
73
|
|
|
return $this->getContextAssetsMethod('Styles')(); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
protected function inlineScripts(): ?InlineScriptCollectionInterface |
77
|
|
|
{ |
78
|
|
|
return $this->getContextAssetsMethod('InlineScripts')(); |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
protected function inlineStyles(): ?InlineStyleCollectionInterface |
82
|
|
|
{ |
83
|
|
|
return $this->getContextAssetsMethod('InlineStyles')(); |
84
|
|
|
} |
85
|
|
|
|
86
|
|
|
protected function scriptLocalizations(): ?ScriptLocalizationCollectionInterface |
87
|
|
|
{ |
88
|
|
|
return $this->getContextAssetsMethod('ScriptLocalizations')(); |
89
|
|
|
} |
90
|
|
|
|
91
|
|
|
protected function getContextAssetsMethod(string $type): array |
92
|
|
|
{ |
93
|
|
|
return [$this, static::CONTEXTS[current_action()] . $type]; |
|
|
|
|
94
|
|
|
} |
95
|
|
|
|
96
|
|
|
protected function adminScripts(): ?ScriptCollectionInterface |
97
|
|
|
{ |
98
|
|
|
return null; |
99
|
|
|
} |
100
|
|
|
|
101
|
|
|
protected function adminStyles(): ?StyleCollectionInterface |
102
|
|
|
{ |
103
|
|
|
return null; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
protected function blockEditorScripts(): ?ScriptCollectionInterface |
107
|
|
|
{ |
108
|
|
|
return null; |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
protected function blockEditorStyles(): ?StyleCollectionInterface |
112
|
|
|
{ |
113
|
|
|
return null; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
protected function loginScripts(): ?ScriptCollectionInterface |
117
|
|
|
{ |
118
|
|
|
return null; |
119
|
|
|
} |
120
|
|
|
|
121
|
|
|
protected function loginStyles(): ?StyleCollectionInterface |
122
|
|
|
{ |
123
|
|
|
return null; |
124
|
|
|
} |
125
|
|
|
|
126
|
|
|
protected function publicScripts(): ?ScriptCollectionInterface |
127
|
|
|
{ |
128
|
|
|
return null; |
129
|
|
|
} |
130
|
|
|
|
131
|
|
|
protected function publicStyles(): ?StyleCollectionInterface |
132
|
|
|
{ |
133
|
|
|
return null; |
134
|
|
|
} |
135
|
|
|
|
136
|
|
|
protected function adminInlineScripts(): ?InlineScriptCollectionInterface |
137
|
|
|
{ |
138
|
|
|
return null; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
protected function adminInlineStyles(): ?InlineStyleCollectionInterface |
142
|
|
|
{ |
143
|
|
|
return null; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
protected function blockEditorInlineScripts(): ?InlineScriptCollectionInterface |
147
|
|
|
{ |
148
|
|
|
return null; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
protected function blockEditorInlineStyles(): ?InlineStyleCollectionInterface |
152
|
|
|
{ |
153
|
|
|
return null; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
protected function loginInlineScripts(): ?InlineScriptCollectionInterface |
157
|
|
|
{ |
158
|
|
|
return null; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
protected function loginInlineStyles(): ?InlineStyleCollectionInterface |
162
|
|
|
{ |
163
|
|
|
return null; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
protected function publicInlineScripts(): ?InlineScriptCollectionInterface |
167
|
|
|
{ |
168
|
|
|
return null; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
protected function publicInlineStyles(): ?InlineStyleCollectionInterface |
172
|
|
|
{ |
173
|
|
|
return null; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
protected function adminScriptLocalizations(): ?ScriptLocalizationCollectionInterface |
177
|
|
|
{ |
178
|
|
|
return null; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
protected function blockEditorScriptLocalizations(): ?ScriptLocalizationCollectionInterface |
182
|
|
|
{ |
183
|
|
|
return null; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
protected function loginScriptLocalizations(): ?ScriptLocalizationCollectionInterface |
187
|
|
|
{ |
188
|
|
|
return null; |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
protected function publicScriptLocalizations(): ?ScriptLocalizationCollectionInterface |
192
|
|
|
{ |
193
|
|
|
return null; |
194
|
|
|
} |
195
|
|
|
} |
196
|
|
|
|