-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEATURE] Add support for TYPO3 13.4 LTS
- Loading branch information
1 parent
51912cf
commit a293770
Showing
15 changed files
with
237 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,17 +1,18 @@ | ||
* text=auto | ||
/.github export-ignore | ||
/Tests export-ignore | ||
/.editorconfig export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.php-cs-fixer.php export-ignore | ||
/CODE_OF_CONDUCT.md export-ignore | ||
/composer.lock export-ignore | ||
/CONTRIBUTING.md export-ignore | ||
/packaging_exclude.php export-ignore | ||
/phpstan.neon export-ignore | ||
/phpstan-baseline.neon export-ignore | ||
/phpunit.functional.xml export-ignore | ||
/phpunit.unit.xml export-ignore | ||
/rector.php export-ignore | ||
/renovate.json export-ignore | ||
* text=auto | ||
/.github export-ignore | ||
/Tests export-ignore | ||
/.editorconfig export-ignore | ||
/.gitattributes export-ignore | ||
/.gitignore export-ignore | ||
/.php-cs-fixer.php export-ignore | ||
/CODE_OF_CONDUCT.md export-ignore | ||
/composer.lock export-ignore | ||
/CONTRIBUTING.md export-ignore | ||
/dependency-checker.json export-ignore | ||
/packaging_exclude.php export-ignore | ||
/phpstan.neon export-ignore | ||
/phpstan-baseline.neon export-ignore | ||
/phpunit.functional.xml export-ignore | ||
/phpunit.unit.xml export-ignore | ||
/rector.php export-ignore | ||
/renovate.json export-ignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS extension "cache_bags". | ||
* | ||
* Copyright (C) 2024 Elias Häußler <[email protected]> | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
namespace CPSIT\Typo3CacheBags\Cache\Expiration; | ||
|
||
use CPSIT\Typo3CacheBags\Cache\Bag\CacheBag; | ||
use TYPO3\CMS\Core\Context\Context; | ||
|
||
/** | ||
* CacheLifetimeCalculator | ||
* | ||
* @author Elias Häußler <[email protected]> | ||
* @license GPL-2.0-or-later | ||
*/ | ||
class CacheLifetimeCalculator | ||
{ | ||
public function __construct( | ||
protected readonly Context $context, | ||
) {} | ||
|
||
public function forCacheBag(CacheBag $cacheBag): ?int | ||
{ | ||
$expirationDate = $cacheBag->getExpirationDate(); | ||
|
||
if ($expirationDate !== null) { | ||
return $this->forExpirationDate($expirationDate); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function forExpirationDate(\DateTimeInterface $expirationDate): int | ||
{ | ||
/** @var non-negative-int $now */ | ||
$now = $this->context->getPropertyFromAspect('date', 'accessTime', 0); | ||
|
||
return \max(0, $expirationDate->getTimestamp() - $now); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -24,32 +24,38 @@ | |
namespace CPSIT\Typo3CacheBags\EventListener; | ||
|
||
use CPSIT\Typo3CacheBags\Cache\Bag\CacheBagRegistry; | ||
use CPSIT\Typo3CacheBags\Cache\Expiration\CacheLifetimeCalculator; | ||
use CPSIT\Typo3CacheBags\Enum\CacheScope; | ||
use TYPO3\CMS\Core\Context\Context; | ||
use TYPO3\CMS\Core\Cache\CacheDataCollector; | ||
use TYPO3\CMS\Frontend\Event\ModifyCacheLifetimeForPageEvent; | ||
|
||
/** | ||
* PageCacheLifetimeEventListener | ||
* | ||
* @author Elias Häußler <[email protected]> | ||
* @license GPL-2.0-or-later | ||
* | ||
* @todo Remove once support for TYPO3 v11 and v12 is dropped | ||
*/ | ||
final class PageCacheLifetimeEventListener | ||
{ | ||
public function __construct( | ||
private readonly Context $context, | ||
private readonly CacheBagRegistry $cacheBagRegistry, | ||
private readonly CacheLifetimeCalculator $cacheLifetimeCalculator, | ||
) {} | ||
|
||
public function __invoke(ModifyCacheLifetimeForPageEvent $event): void | ||
{ | ||
// Lifetime modification for TYPO3 >= 13.4 is already done when cache bags are registered | ||
if (class_exists(CacheDataCollector::class)) { | ||
return; | ||
} | ||
|
||
$expirationDate = $this->cacheBagRegistry->getExpirationDate(CacheScope::Pages); | ||
/** @var non-negative-int $now */ | ||
$now = $this->context->getPropertyFromAspect('date', 'accessTime', 0); | ||
|
||
if ($expirationDate !== null) { | ||
$event->setCacheLifetime( | ||
\max(0, $expirationDate->getTimestamp() - $now) | ||
$this->cacheLifetimeCalculator->forExpirationDate($expirationDate), | ||
); | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
{ | ||
"symbol-whitelist": [ | ||
"TYPO3\\CMS\\Core\\Cache\\CacheDataCollector", | ||
"TYPO3\\CMS\\Core\\Cache\\CacheTag", | ||
"TYPO3\\CMS\\Core\\Schema\\Capability\\TcaSchemaCapability", | ||
"TYPO3\\CMS\\Core\\Schema\\TcaSchema", | ||
"TYPO3\\CMS\\Core\\Schema\\TcaSchemaFactory" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.