forked from lochmueller/staticfilecache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConfiguration.php
296 lines (270 loc) · 9.8 KB
/
Configuration.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
<?php
/**
* Configuration.
*/
declare(strict_types = 1);
namespace SFC\Staticfilecache;
use SFC\Staticfilecache\Cache\RemoteFileBackend;
use SFC\Staticfilecache\Cache\Rule\Enable;
use SFC\Staticfilecache\Cache\Rule\ForceStaticCache;
use SFC\Staticfilecache\Cache\Rule\LoginDeniedConfiguration;
use SFC\Staticfilecache\Cache\Rule\NoBackendUser;
use SFC\Staticfilecache\Cache\Rule\NoBackendUserCookie;
use SFC\Staticfilecache\Cache\Rule\NoFakeFrontend;
use SFC\Staticfilecache\Cache\Rule\NoIntScripts;
use SFC\Staticfilecache\Cache\Rule\NoLongPathSegment;
use SFC\Staticfilecache\Cache\Rule\NoNoCache;
use SFC\Staticfilecache\Cache\Rule\NoUserOrGroupSet;
use SFC\Staticfilecache\Cache\Rule\NoWorkspacePreview;
use SFC\Staticfilecache\Cache\Rule\PageCacheable;
use SFC\Staticfilecache\Cache\Rule\SiteCacheable;
use SFC\Staticfilecache\Cache\Rule\StaticCacheable;
use SFC\Staticfilecache\Cache\Rule\ValidDoktype;
use SFC\Staticfilecache\Cache\Rule\ValidPageInformation;
use SFC\Staticfilecache\Cache\Rule\ValidRequestMethod;
use SFC\Staticfilecache\Cache\Rule\ValidUri;
use SFC\Staticfilecache\Cache\StaticFileBackend;
use SFC\Staticfilecache\Cache\UriFrontend;
use SFC\Staticfilecache\Generator\BrotliGenerator;
use SFC\Staticfilecache\Generator\ConfigGenerator;
use SFC\Staticfilecache\Generator\GzipGenerator;
use SFC\Staticfilecache\Generator\HtaccessGenerator;
use SFC\Staticfilecache\Generator\ManifestGenerator;
use SFC\Staticfilecache\Generator\PlainGenerator;
use SFC\Staticfilecache\Hook\InitFrontendUser;
use SFC\Staticfilecache\Hook\LogoffFrontendUser;
use SFC\Staticfilecache\Hook\UninstallProcess;
use SFC\Staticfilecache\Service\HttpPush\FontHttpPush;
use SFC\Staticfilecache\Service\HttpPush\ImageHttpPush;
use SFC\Staticfilecache\Service\HttpPush\ScriptHttpPush;
use SFC\Staticfilecache\Service\HttpPush\StyleHttpPush;
use SFC\Staticfilecache\Service\ObjectFactoryService;
use TYPO3\CMS\Core\Cache\Backend\NullBackend;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Imaging\IconProvider\FontawesomeIconProvider;
use TYPO3\CMS\Core\Imaging\IconRegistry;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Extbase\SignalSlot\Dispatcher;
use TYPO3\CMS\Extbase\Utility\ExtensionUtility;
use TYPO3\CMS\Extensionmanager\Utility\InstallUtility;
/**
* Configuration.
*/
class Configuration extends StaticFileCacheObject
{
/**
* @var array
*/
protected $configuration = [];
/**
* Configuration constructor.
* @throws \TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationExtensionNotConfiguredException
* @throws \TYPO3\CMS\Core\Configuration\Exception\ExtensionConfigurationPathDoesNotExistException
*/
public function __construct()
{
$this->configuration = (array)GeneralUtility::makeInstance(ExtensionConfiguration::class)->get('staticfilecache');
}
/**
* Call in ext_localconf.php
*/
public function extLocalconf(): void
{
$this->registerHooks()
->registerSlots()
->registerRules()
->registerCachingFramework()
->registerIcons()
->registerFluidNamespace()
->registerEid()
->registerGenerators()
->registerHttpPushServices();
}
/**
* Call in ext_tables.php
*/
public function extTables(): void
{
$this->registerBackendModule();
}
/**
* Add Web>Info module:.
*/
protected function registerBackendModule(): Configuration
{
ExtensionUtility::registerModule(
'SFC.Staticfilecache',
'web',
'staticfilecache',
'',
[
'Backend' => 'list,boost,support',
],
[
'access' => 'user,group',
'icon' => 'EXT:staticfilecache/Resources/Public/Icons/Extension.svg',
'labels' => 'LLL:EXT:staticfilecache/Resources/Private/Language/locallang_mod.xlf',
]
);
return $this;
}
/**
* Register hooks.
*/
protected function registerHooks(): Configuration
{
// Set cookie when User logs in
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['tslib/class.tslib_fe.php']['initFEuser']['staticfilecache'] = InitFrontendUser::class . '->setFeUserCookie';
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_userauth.php']['logoff_post_processing']['staticfilecache'] = LogoffFrontendUser::class . '->logoff';
return $this;
}
/**
* Register slots.
*/
protected function registerSlots(): Configuration
{
$signalSlotDispatcher = GeneralUtility::makeInstance(Dispatcher::class);
$signalSlotDispatcher->connect(InstallUtility::class, 'afterExtensionUninstall', UninstallProcess::class, 'afterExtensionUninstall');
return $this;
}
/**
* Register rules
*
* @return Configuration
*/
protected function registerRules(): Configuration
{
GeneralUtility::makeInstance(ObjectFactoryService::class)->set('CacheRule', [
'staticCacheable' => StaticCacheable::class,
'validUri' => ValidUri::class,
'siteCacheable' => SiteCacheable::class,
'validDoktype' => ValidDoktype::class,
'noWorkspacePreview' => NoWorkspacePreview::class,
'noUserOrGroupSet' => NoUserOrGroupSet::class,
'noIntScripts' => NoIntScripts::class,
'loginDeniedConfiguration' => LoginDeniedConfiguration::class,
'pageCacheable' => PageCacheable::class,
'noNoCache' => NoNoCache::class,
'noBackendUser' => NoBackendUser::class,
'enable' => Enable::class,
'validRequestMethod' => ValidRequestMethod::class,
'validPageInformation' => ValidPageInformation::class,
'forceStaticCache' => ForceStaticCache::class,
'noFakeFrontend' => NoFakeFrontend::class,
'noLongPathSegment' => NoLongPathSegment::class,
]);
GeneralUtility::makeInstance(ObjectFactoryService::class)->set('CacheRuleFallback', [
'validUri' => ValidUri::class,
'validRequestMethod' => ValidRequestMethod::class,
'noBackendUserCookie' => NoBackendUserCookie::class,
]);
return $this;
}
/**
* Register caching framework.
*/
protected function registerCachingFramework(): Configuration
{
$useNullBackend = isset($this->configuration['disableInDevelopment']) && $this->configuration['disableInDevelopment'] && GeneralUtility::getApplicationContext()->isDevelopment();
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['staticfilecache'] = [
'frontend' => UriFrontend::class,
'backend' => $useNullBackend ? NullBackend::class : StaticFileBackend::class,
'groups' => [
'pages',
'all',
],
];
$GLOBALS['TYPO3_CONF_VARS']['SYS']['caching']['cacheConfigurations']['remote_file'] = [
'frontend' => UriFrontend::class,
'backend' => RemoteFileBackend::class,
'groups' => [
'all',
],
'options' => [
// 'defaultLifetime' => 3600,
// 'hashLength' => 10,
],
];
return $this;
}
/**
* Add fluid namespaces.
*/
protected function registerFluidNamespace(): Configuration
{
$GLOBALS['TYPO3_CONF_VARS']['SYS']['fluid']['namespaces']['sfc'] = ['SFC\\Staticfilecache\\ViewHelpers'];
return $this;
}
/**
* Register eID scripts
*/
protected function registerEid(): Configuration
{
$GLOBALS['TYPO3_CONF_VARS']['FE']['eID_include']['sfc_manifest'] = 'EXT:staticfilecache/Resources/Private/Php/Manifest.php';
return $this;
}
/**
* Register generator
*
* @return Configuration
*/
protected function registerGenerators(): Configuration
{
$generator = [
'config' => ConfigGenerator::class,
'htaccess' => HtaccessGenerator::class,
];
if ($this->configuration['enableGeneratorManifest']) {
$generator['manifest'] = ManifestGenerator::class;
}
if ($this->configuration['enableGeneratorPlain']) {
$generator['plain'] = PlainGenerator::class;
}
if ($this->configuration['enableGeneratorGzip']) {
$generator['gzip'] = GzipGenerator::class;
}
if ($this->configuration['enableGeneratorBrotli']) {
$generator['brotli'] = BrotliGenerator::class;
}
GeneralUtility::makeInstance(ObjectFactoryService::class)->set('Generator', $generator);
return $this;
}
/**
* Register HTTP push services
*
* @return Configuration
*/
protected function registerHttpPushServices(): Configuration
{
GeneralUtility::makeInstance(ObjectFactoryService::class)->set('HttpPush', [
'style' => StyleHttpPush::class,
'script' => ScriptHttpPush::class,
'image' => ImageHttpPush::class,
'font' => FontHttpPush::class,
]);
return $this;
}
/**
* Register icons.
*/
protected function registerIcons(): Configuration
{
$iconRegistry = GeneralUtility::makeInstance(IconRegistry::class);
$iconRegistry->registerIcon(
'brand-amazon',
FontawesomeIconProvider::class,
['name' => 'amazon']
);
$iconRegistry->registerIcon(
'brand-paypal',
FontawesomeIconProvider::class,
['name' => 'paypal']
);
$iconRegistry->registerIcon(
'documentation-book',
FontawesomeIconProvider::class,
['name' => 'book']
);
return $this;
}
}