Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
Tests export-ignore
.github export-ignore

.gitattributes export-ignore
.gitignore export-ignore

ecs.php export-ignore
rector.php export-ignore
phpstan-baseline.neon export-ignore
phpstan.neon export-ignore
phpunit.xml.dist export-ignore
47 changes: 39 additions & 8 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.1
php-version: 8.2
coverage: none
tools: composer:v2
env:
Expand All @@ -29,9 +29,9 @@ jobs:
strategy:
matrix:
php-version:
- 8.1
- 8.2
- 8.3
- 8.4
steps:
- name: Checkout
uses: actions/checkout@v3
Expand All @@ -55,7 +55,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
php-version: "8.2"
coverage: none
tools: composer:v2
env:
Expand Down Expand Up @@ -86,7 +86,7 @@ jobs:
- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "8.1"
php-version: "8.2"
coverage: none
tools: composer:v2
env:
Expand All @@ -106,12 +106,12 @@ jobs:
strategy:
matrix:
include:
- php-version: '8.1'
typo3-version: '^12.4'
- php-version: '8.2'
typo3-version: '^12.4'
typo3-version: '^13.4'
- php-version: '8.3'
typo3-version: '^12.4'
typo3-version: '^13.4'
- php-version: '8.4'
typo3-version: '^13.4'
steps:
- uses: actions/checkout@v3

Expand All @@ -129,3 +129,34 @@ jobs:

- name: PHPUnit Tests
run: ./vendor/bin/phpunit --testdox

phpstan:
runs-on: ubuntu-latest
needs:
- check-composer
strategy:
matrix:
include:
- php-version: '8.2'
typo3-version: '^13.4'
- php-version: '8.3'
typo3-version: '^13.4'
- php-version: '8.4'
typo3-version: '^13.4'
steps:
- uses: actions/checkout@v3

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: "${{ matrix.php-version }}"
coverage: none
tools: composer:v2
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Install dependencies with expected TYPO3 version
run: composer require --no-progress --no-interaction --optimize-autoloader "typo3/cms-core:${{ matrix.typo3-version }}"

- name: PHPStan
run: ./vendor/bin/phpstan
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 5.0.0 (2025-09-18)

[!!!][TASK] TYPO3 13 compatibility

## 3.0.0 (2022-06-16)

[TASK] php annotation
Expand Down
1 change: 0 additions & 1 deletion Classes/Domain/Model/Marker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ public function __construct(
public int $uid,
public string $key,
public string $replacement,
// public ?int $smallestValueFromTimeFields,
) {
}

Expand Down
6 changes: 6 additions & 0 deletions Classes/Domain/Model/MarkerCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@

use Ramsey\Collection\AbstractArray;

/**
* @extends AbstractArray<Marker>
*/
class MarkerCollection extends AbstractArray
{
public function getType(): string
Expand All @@ -41,6 +44,9 @@ public function get(string $markerKey): Marker
return $this[$markerKey];
}

/**
* @return mixed[]
*/
public function getMarkerKeys(): array
{
return array_keys($this->data);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,26 @@
* The TYPO3 project - inspiring people to share!
*/

namespace Sinso\Variables\Hooks;
namespace Sinso\Variables\EventListener;

use Sinso\Variables\Service\VariablesService;
use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;

class ContentProcessor
{
protected VariablesService $variablesService;

public function __construct()
{
$this->variablesService = GeneralUtility::makeInstance(VariablesService::class);
public function __construct(
private readonly VariablesService $variablesService,
) {
}

#[AsEventListener()]
public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
{
$extensionConfiguration = GeneralUtility::makeInstance(ExtensionConfiguration::class);
$this->variablesService->initialize($extensionConfiguration, $event->getController());
$this->variablesService->replaceMarkersInStructureAndAdjustCaching($event->getController()->content);
$this->variablesService->replaceMarkersInStructureAndAdjustCaching(
$event->getRequest(),
$event->getController()->content
);
}
}
4 changes: 3 additions & 1 deletion Classes/EventListener/ModifyCacheLifetime.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,21 @@
namespace Sinso\Variables\EventListener;

use Sinso\Variables\Service\VariablesService;
use TYPO3\CMS\Core\Attribute\AsEventListener;
use TYPO3\CMS\Frontend\Event\ModifyCacheLifetimeForPageEvent;

final class ModifyCacheLifetime
{
public function __construct(
private VariablesService $variablesService,
private readonly VariablesService $variablesService,
) {
}

/**
* Calculate shortest lifetime (aka duration) respecting data from
* markers
*/
#[AsEventListener()]
public function __invoke(ModifyCacheLifetimeForPageEvent $event): void
{
$event->setCacheLifetime(
Expand Down
24 changes: 18 additions & 6 deletions Classes/Hooks/DataHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use TYPO3\CMS\Core\Cache\CacheManager;
use TYPO3\CMS\Core\Database\Connection;
use TYPO3\CMS\Core\Database\ConnectionPool;
use TYPO3\CMS\Core\DataHandling\DataHandler as Typo3CoreDataHandler;

class DataHandler
{
Expand All @@ -31,8 +32,9 @@ public function __construct(

/**
* Flushes the cache if a marker record was edited.
* @param array<string, mixed> $params
*/
public function clearCachePostProc(array $params, \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler): void
public function clearCachePostProc(array $params, Typo3CoreDataHandler $dataHandler): void
{
$marker = $this->getMarkerFromHook($params, $dataHandler);

Expand All @@ -47,27 +49,31 @@ public function clearCachePostProc(array $params, \TYPO3\CMS\Core\DataHandling\D
$this->cacheManager->flushCachesInGroupByTag('pages', $cacheTagToFlush);
}

protected function getMarkerFromHook(array $params, \TYPO3\CMS\Core\DataHandling\DataHandler $dataHandler): ?Marker
/**
* @param array<string, mixed> $params
*/
protected function getMarkerFromHook(array $params, Typo3CoreDataHandler $dataHandler): ?Marker
{
if (
($params['table'] !== 'tx_variables_marker')
(($params['table'] ?? '') !== 'tx_variables_marker')
|| !isset($params['uid'])
|| is_numeric($params['uid']) === false
) {
return null;
}

$marker = $dataHandler->datamap[$params['table']][$params['uid']]['marker'] ?? null;

if (!$marker) {
$marker = $this->findVariableMarkerByUidEventIfHiddenOrDeleted($params['uid']);
$marker = $this->findVariableMarkerByUidEventIfHiddenOrDeleted((int) $params['uid']);
}

if (!$marker) {
return null;
}

return new Marker(
uid: $params['uid'],
uid: (int) $params['uid'],
key: $marker,
replacement: '', // value doesn't matter here
);
Expand All @@ -77,13 +83,19 @@ protected function findVariableMarkerByUidEventIfHiddenOrDeleted(int $uid): ?str
{
$queryBuilder = $this->connectionPool->getQueryBuilderForTable('tx_variables_marker');
$queryBuilder->getRestrictions()->removeAll();
return $queryBuilder
$result = $queryBuilder
->select('marker')
->from('tx_variables_marker')
->where(
$queryBuilder->expr()->eq('uid', $queryBuilder->createNamedParameter($uid, Connection::PARAM_INT)),
)
->executeQuery()
->fetchOne();

if (is_string($result) || is_null($result)) {
return $result;
}

return null;
}
}
2 changes: 1 addition & 1 deletion Classes/Hooks/MarkersProcessorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,5 @@

interface MarkersProcessorInterface
{
public function postProcessMarkers(MarkerCollection $markers);
public function postProcessMarkers(MarkerCollection $markers): void;
}
Loading