2020 */
2121class RemoteFileBackend extends AbstractBackend implements TaggableBackendInterface, TransientBackendInterface
2222{
23+ public const DATETIME_EXPIRYTIME_UNLIMITED_INTERNAL = '9999-12-31T23:59:59+0000 ' ;
24+ public const UNLIMITED_LIFETIME_INTERNAL = 0 ;
25+
2326 /**
2427 * Relative folder name.
2528 */
@@ -93,7 +96,7 @@ public function set($entryIdentifier, $data, array $tags = [], $lifetime = null)
9396 }
9497
9598 GeneralUtility::writeFile ($ absoluteCacheDir . $ fileName . self ::FILE_EXTENSION_TAG , '| ' . implode ('| ' , $ tags ) . '| ' );
96- GeneralUtility::writeFile ($ absoluteCacheDir . $ fileName . self ::FILE_EXTENSION_LIFETIME , (string ) $ this ->calculateExpiryTime ($ lifetime )->getTimestamp ());
99+ GeneralUtility::writeFile ($ absoluteCacheDir . $ fileName . self ::FILE_EXTENSION_LIFETIME , (string ) $ this ->calculateExpiryTimeInternal ($ lifetime )->getTimestamp ());
97100 GeneralUtility::writeFile ($ absoluteCacheDir . $ fileName . self ::FILE_EXTENSION_IDENTIFIER , $ entryIdentifier );
98101 }
99102
@@ -262,12 +265,15 @@ protected function getFileName(string $entryIdentifier): string
262265 try {
263266 if (GeneralUtility::makeInstance (Typo3Version::class)->getMajorVersion () < 14 ) {
264267 /** @var ResourceFactory $resourceFactory */
268+ // @phpstan-ignore-next-line
265269 $ resourceFactory = GeneralUtility::makeInstance (ResourceFactory::class);
266270 } else {
267271 /** @var StorageRepository $resourceFactory */
272+ // @phpstan-ignore-next-line
268273 $ resourceFactory = GeneralUtility::makeInstance (\TYPO3 \CMS \Core \Resource \StorageRepository::class);
269274 }
270275
276+ // @phpstan-ignore-next-line
271277 $ storage = $ resourceFactory ->getDefaultStorage ();
272278 $ baseName = (string ) $ storage ->sanitizeFileName ($ baseName );
273279 } catch (\Exception $ exception ) {
@@ -287,4 +293,20 @@ public function flushByTags(array $tags): void
287293 $ this ->flushByTag ($ tag );
288294 }
289295 }
296+
297+ /**
298+ * @see https://github.com/TYPO3/typo3/blob/13.4/typo3/sysext/core/Classes/Cache/Backend/AbstractBackend.php#L138 (method do not exists in v14 anymore)
299+ */
300+ protected function calculateExpiryTimeInternal ($ lifetime = null )
301+ {
302+ if ($ lifetime === self ::UNLIMITED_LIFETIME_INTERNAL || $ lifetime === null && $ this ->defaultLifetime === self ::UNLIMITED_LIFETIME_INTERNAL ) {
303+ $ expiryTime = new \DateTime (self ::DATETIME_EXPIRYTIME_UNLIMITED_INTERNAL , new \DateTimeZone ('UTC ' ));
304+ } else {
305+ if ($ lifetime === null ) {
306+ $ lifetime = $ this ->defaultLifetime ;
307+ }
308+ $ expiryTime = new \DateTime ('now + ' . $ lifetime . ' seconds ' , new \DateTimeZone ('UTC ' ));
309+ }
310+ return $ expiryTime ;
311+ }
290312}
0 commit comments