Skip to content

Commit 0946c0b

Browse files
committed
!!![TASK] change requirements
* remove TYPO3 < 12 support * add TYPO3 13 support
1 parent b8e7074 commit 0946c0b

7 files changed

Lines changed: 56 additions & 47 deletions

File tree

.github/workflows/publish.yml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,13 @@ jobs:
88
publish:
99
name: Publish new version to TER
1010
if: startsWith(github.ref, 'refs/tags/')
11-
runs-on: ubuntu-20.04
11+
runs-on: ubuntu-latest
1212
env:
13-
TYPO3_EXTENSION_KEY: ${{ secrets.TYPO3_EXTENSION_KEY }}
1413
TYPO3_API_TOKEN: ${{ secrets.TYPO3_API_TOKEN }}
1514

1615
steps:
1716
- name: Checkout repository
18-
uses: actions/checkout@v2
17+
uses: actions/checkout@v4
1918

2019
- name: Check tag
2120
run: |
@@ -31,14 +30,14 @@ jobs:
3130
run: |
3231
readonly local comment=$(git tag -n10 -l ${{ steps.get-version.outputs.version }} | sed "s/^[0-9.]*[ ]*//g")
3332
if [[ -z "${comment// }" ]]; then
34-
echo ::set-output name=comment::Released version ${{ steps.get-version.outputs.version }} of ${{ env.TYPO3_EXTENSION_KEY }}
33+
echo ::set-output name=comment::Released version ${{ steps.get-version.outputs.version }} of http2
3534
else
3635
echo ::set-output name=comment::$comment
3736
fi
3837
- name: Setup PHP
3938
uses: shivammathur/setup-php@v2
4039
with:
41-
php-version: 7.4
40+
php-version: 8.3
4241
extensions: intl, mbstring, json, zip, curl
4342

4443
- name: Install tailor

Classes/Http/ResourcePusher.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -31,25 +31,25 @@ class ResourcePusher implements MiddlewareInterface
3131
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
3232
{
3333
$response = $handler->handle($request);
34-
if (($GLOBALS['TSFE'] ?? null) instanceof TypoScriptFrontendController) {
35-
$resources = $GLOBALS['TSFE']->config['b13/http2'] ?? null;
36-
/** @var NormalizedParams $normalizedParams */
37-
$normalizedParams = $request->getAttribute('normalizedParams');
38-
if (is_array($resources) && $normalizedParams->isHttps()) {
39-
foreach ($resources['scripts'] ?? [] as $resource) {
40-
$response = $this->addPreloadHeaderToResponse($response, $resource, 'script');
41-
}
42-
foreach ($resources['styles'] ?? [] as $resource) {
43-
$response = $this->addPreloadHeaderToResponse($response, $resource, 'style');
44-
}
34+
/** @var TypoScriptFrontendController $frontendController */
35+
$frontendController = $request->getAttribute('frontend.controller');
36+
$resources = $frontendController->config['b13/http2'] ?? null;
37+
/** @var NormalizedParams $normalizedParams */
38+
$normalizedParams = $request->getAttribute('normalizedParams');
39+
if (is_array($resources) && $normalizedParams->isHttps()) {
40+
foreach ($resources['scripts'] ?? [] as $resource) {
41+
$response = $this->addPreloadHeaderToResponse($response, $resource, 'script');
42+
}
43+
foreach ($resources['styles'] ?? [] as $resource) {
44+
$response = $this->addPreloadHeaderToResponse($response, $resource, 'style');
4545
}
4646
}
4747
return $response;
4848
}
4949

5050
protected function addPreloadHeaderToResponse(ResponseInterface $response, string $uri, string $type): ResponseInterface
5151
{
52-
if(str_contains($uri, '.mjs')) {
52+
if (str_contains($uri, '.mjs')) {
5353
return $response->withAddedHeader('Link', '<' . htmlspecialchars(PathUtility::getAbsoluteWebPath($uri)) . '>; rel=modulepreload; as=' . $type);
5454
} else {
5555
return $response->withAddedHeader('Link', '<' . htmlspecialchars(PathUtility::getAbsoluteWebPath($uri)) . '>; rel=preload; as=' . $type);

Classes/PageRendererHook.php

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@
1010
* of the License, or any later version.
1111
*/
1212

13+
use Psr\Http\Message\ServerRequestInterface;
14+
use TYPO3\CMS\Core\Http\ApplicationType;
1315
use TYPO3\CMS\Core\Page\PageRenderer;
1416
use TYPO3\CMS\Core\Utility\GeneralUtility;
1517
use TYPO3\CMS\Frontend\Controller\TypoScriptFrontendController;
@@ -22,17 +24,9 @@
2224
*/
2325
class PageRendererHook
2426
{
25-
/**
26-
* @var ResourceMatcher
27-
*/
28-
protected $matcher;
2927

30-
/**
31-
* @param ResourceMatcher|null $matcher
32-
*/
33-
public function __construct(ResourceMatcher $matcher = null)
28+
public function __construct(protected ResourceMatcher $matcher)
3429
{
35-
$this->matcher = $matcher ?: GeneralUtility::makeInstance(ResourceMatcher::class);
3630
}
3731

3832
/**
@@ -42,9 +36,15 @@ public function __construct(ResourceMatcher $matcher = null)
4236
*/
4337
public function accumulateResources(array $params, PageRenderer $pageRenderer)
4438
{
39+
$request = $this->getRequest();
40+
if ($request === null) {
41+
return;
42+
}
4543
// If this is a second run (non-cached cObjects adding more data), then the existing cached data is fetched
46-
if ($this->getTypoScriptFrontendController() instanceof TypoScriptFrontendController) {
47-
$allResources = $this->getTypoScriptFrontendController()->config['b13/http2'] ?? [];
44+
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
45+
/** @var TypoScriptFrontendController $frontendController */
46+
$frontendController = $request->getAttribute('frontend.controller');
47+
$allResources = $frontendController->config['b13/http2'] ?? [];
4848
} else {
4949
$allResources = [];
5050
}
@@ -64,7 +64,7 @@ public function accumulateResources(array $params, PageRenderer $pageRenderer)
6464
$allResources['scripts'] = array_unique($allResources['scripts'] ?? []);
6565
$allResources['styles'] = array_unique($allResources['styles'] ?? []);
6666

67-
$this->process($allResources);
67+
$this->process($allResources, $request);
6868
}
6969

7070
/**
@@ -73,18 +73,20 @@ public function accumulateResources(array $params, PageRenderer $pageRenderer)
7373
*
7474
* @param array $allResources
7575
*/
76-
protected function process(array $allResources)
76+
protected function process(array $allResources, ServerRequestInterface $request): void
7777
{
78-
if ($this->getTypoScriptFrontendController() instanceof TypoScriptFrontendController) {
79-
$this->getTypoScriptFrontendController()->config['b13/http2'] = $allResources;
78+
if (ApplicationType::fromRequest($GLOBALS['TYPO3_REQUEST'])->isFrontend()) {
79+
/** @var TypoScriptFrontendController $frontendController */
80+
$frontendController = $request->getAttribute('frontend.controller');
81+
$frontendController->config['b13/http2'] = $allResources;
8082
} elseif (GeneralUtility::getIndpEnv('TYPO3_SSL')) {
8183
// Push directly into the TYPO3 Backend, but only if TYPO3 is running in SSL
8284
GeneralUtility::makeInstance(ResourcePusher::class)->pushAll($allResources);
8385
}
8486
}
8587

86-
protected function getTypoScriptFrontendController()
88+
protected function getRequest(): ?ServerRequestInterface
8789
{
88-
return $GLOBALS['TSFE'] ?? null;
90+
return $GLOBALS['TYPO3_REQUEST'] ?? null;
8991
}
9092
}

Configuration/RequestMiddlewares.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
'typo3/cms-frontend/prepare-tsfe-rendering',
88
],
99
'after' => [
10-
'typo3/cms-frontend/authentication',
10+
'typo3/cms-frontend/tsfe',
1111
],
1212
],
1313
]

Configuration/Services.yaml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
services:
2+
_defaults:
3+
autowire: true
4+
autoconfigure: true
5+
public: false
6+
7+
B13\Http2\:
8+
resource: '../Classes/*'
9+
10+
B13\Http2\PageRendererHook:
11+
public: true

Tests/Unit/ResourceMatcherTest.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313

1414
use B13\Http2\ResourceMatcher;
15+
use PHPUnit\Framework\Attributes\DataProvider;
16+
use PHPUnit\Framework\Attributes\Test;
1517
use PHPUnit\Framework\TestCase;
1618

1719
class ResourceMatcherTest extends TestCase
1820
{
19-
public function matchDataProvider()
21+
public static function matchDataProvider()
2022
{
2123
return [
2224
'nothing useful' => [
@@ -62,10 +64,8 @@ public function matchDataProvider()
6264
];
6365
}
6466

65-
/**
66-
* @test
67-
* @dataProvider matchDataProvider
68-
*/
67+
#[DataProvider('matchDataProvider')]
68+
#[Test]
6969
public function matchExtractsProperInformation($input, $expectedScripts, $expectedStyles)
7070
{
7171
$expectedResult = [

composer.json

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,12 @@
33
"type": "typo3-cms-extension",
44
"description": "Speed up TYPO3 rendering via HTTP/2 Server Push",
55
"require": {
6-
"php": "^7.4 || ^8.0",
7-
"psr/http-server-middleware": "^1.0",
8-
"typo3/cms-core": "^10.0 || ^11.0 || ^12.0",
9-
"typo3/cms-frontend": "^10.0 || ^11.0 || ^12.0"
6+
"typo3/cms-core": "^12.4 || ^13.4",
7+
"typo3/cms-frontend": "^12.4 || ^13.4"
108
},
119
"require-dev": {
12-
"phpunit/phpunit": "~7.0",
13-
"squizlabs/php_codesniffer": "^2.3",
14-
"typo3/tailor": "^1.4.0"
10+
"phpunit/phpunit": "^11.0",
11+
"squizlabs/php_codesniffer": "^3.0"
1512
},
1613
"homepage": "https://b13.com",
1714
"license": ["GPL-2.0-or-later"],

0 commit comments

Comments
 (0)