Skip to content

Commit b2a8bbd

Browse files
committed
!!! [TASK] change requirements
* drop TYPO3 < 11 Support * add TYPO3 13 Support * add ci workflow * add BeforeMiddlewareIsAppliedEvent Fixes: #5 Fixes: #11
1 parent d899d70 commit b2a8bbd

File tree

11 files changed

+164
-38
lines changed

11 files changed

+164
-38
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ indent_size = 2
1818

1919
# JSON-Files
2020
[*.json]
21-
indent_style = tab
21+
indent_size = 2
2222

2323
# ReST-Files
2424
[*.rst]

.github/workflows/ci.yml

+48
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: CI
2+
3+
on: [push, pull_request]
4+
5+
jobs:
6+
testsuite:
7+
8+
runs-on: ubuntu-latest
9+
strategy:
10+
matrix:
11+
TYPO3: ['11' , '12', '13']
12+
13+
steps:
14+
- name: Checkout
15+
uses: actions/checkout@v2
16+
17+
- name: Set up PHP Version
18+
uses: shivammathur/setup-php@v2
19+
with:
20+
php-version: 8.3
21+
tools: composer:v2
22+
23+
- name: Validate composer.json and composer.lock
24+
run: composer validate
25+
26+
- name: Cache dependencies
27+
uses: actions/cache@v1
28+
with:
29+
path: ~/.composer/cache
30+
key: dependencies-composer-${{ hashFiles('composer.json') }}
31+
32+
- name: Install composer dependencies TYPO3 13
33+
if: matrix.TYPO3 == '13'
34+
run: |
35+
composer install --no-progress --no-interaction
36+
37+
- name: Install composer dependencies TYPO3 12
38+
if: matrix.TYPO3 == '12'
39+
run: |
40+
composer require typo3/cms-core:^12.4 --no-progress --no-interaction --dev -W
41+
- name: Install composer dependencies TYPO3 11
42+
if: matrix.TYPO3 == '11'
43+
run: |
44+
composer require typo3/cms-core:^11.5 --no-progress --no-interaction --dev -W
45+
- name: Phpstan
46+
run: ./vendor/bin/phpstan analyze -c phpstan.neon
47+
- name: Phpcsfix
48+
run: ./vendor/bin/php-cs-fixer fix --config=php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
/composer.lock
22
/public/
33
/vendor/
4-
/.php_cs.cache
4+
/.php-cs-fixer.cache

Configuration/Services.yaml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
services:
2+
_defaults:
3+
autowire: true
4+
autoconfigure: true
5+
public: false
6+
7+
B13\JustInCase\:
8+
resource: '../src/*'

Configuration/SiteConfiguration/Overrides/sites.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,5 +37,5 @@
3737
$GLOBALS['SiteConfiguration']['site_language']['types']['1']['showitem'] = str_replace(
3838
'flag',
3939
'flag, ,--palette--;;justincase',
40-
(string) $GLOBALS['SiteConfiguration']['site_language']['types']['1']['showitem']
40+
(string)$GLOBALS['SiteConfiguration']['site_language']['types']['1']['showitem']
4141
);

README.md

+5
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ If you wish to enable redirect for all languages, add these lines at the bottom
4343

4444
Please note that this option only works for GET or HEAD requests.
4545

46+
## Events
47+
48+
a ```BeforeMiddlewareIsAppliedEvent``` is fired before LowerCaseUri Middleware is applied.
49+
you can prevent applying Middleware by calling `event->doNotApply`
50+
4651
## Caveats
4752

4853
If specific route enhancers check on camel-case (e.g. `{order}/paymentForm/`) this might lead to unexpected behaviours

composer.json

+36-31
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,38 @@
11
{
2-
"name": "b13/justincase",
3-
"type": "typo3-cms-extension",
4-
"description": "With incoming URLs, it does not matter if they are upper/lowercase, they just work.",
5-
"license": "GPL-2.0-or-later",
6-
"require": {
7-
"php": "^7.2 || ^8.0",
8-
"typo3/cms-core": "^9.5 || ^10.0 || ^11.0 || ^12.0"
9-
},
10-
"replace": {
11-
"typo3-ter/justincase": "self.version"
12-
},
13-
"extra": {
14-
"typo3/cms": {
15-
"extension-key": "justincase"
16-
}
17-
},
18-
"autoload": {
19-
"psr-4": {
20-
"B13\\JustInCase\\": "src/"
21-
}
22-
},
23-
"require-dev": {
24-
"typo3/coding-standards": "^0.2.0",
25-
"typo3/tailor": "^1.1"
26-
},
27-
"config": {
28-
"sort-packages": true
29-
},
30-
"scripts": {
31-
"php:cs": "@composer exec php-cs-fixer fix"
32-
}
2+
"name": "b13/justincase",
3+
"type": "typo3-cms-extension",
4+
"description": "With incoming URLs, it does not matter if they are upper/lowercase, they just work.",
5+
"license": "GPL-2.0-or-later",
6+
"require": {
7+
"typo3/cms-core": "^11.5 || ^12.4 || ^13.1"
8+
},
9+
"replace": {
10+
"typo3-ter/justincase": "self.version"
11+
},
12+
"extra": {
13+
"typo3/cms": {
14+
"extension-key": "justincase"
15+
}
16+
},
17+
"autoload": {
18+
"psr-4": {
19+
"B13\\JustInCase\\": "src/"
20+
}
21+
},
22+
"require-dev": {
23+
"typo3/coding-standards": "^0.5.5",
24+
"saschaegerer/phpstan-typo3": "^1.8",
25+
"typo3/tailor": "^1.1"
26+
},
27+
"config": {
28+
"sort-packages": true,
29+
"allow-plugins": {
30+
"typo3/cms-composer-installers": true,
31+
"typo3/class-alias-loader": true
32+
}
33+
},
34+
"scripts": {
35+
"php:cs": "@composer exec 'php-cs-fixer fix --config=php-cs-fixer.php'",
36+
"php:phpstan": "@composer exec 'phpstan analyse -c phpstan.neon'"
37+
}
3338
}

.php_cs php-cs-fixer.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<?php
22

33
$config = \TYPO3\CodingStandards\CsFixerConfig::create();
4-
$config->getFinder()->in(__DIR__);
4+
$config->getFinder()->exclude(['public', 'vendor'])->in(__DIR__);
55
return $config;

phpstan.neon

+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
parameters:
2+
level: 5
3+
4+
paths:
5+
- %currentWorkingDirectory%/src
6+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace B13\JustInCase\Middleware;
6+
7+
/*
8+
* This file is part of TYPO3 CMS-based extension "JustInCase" by b13.
9+
*
10+
* It is free software; you can redistribute it and/or modify it under
11+
* the terms of the GNU General Public License, either version 2
12+
* of the License, or any later version.
13+
*/
14+
15+
use Psr\Http\Message\ServerRequestInterface;
16+
17+
final class BeforeMiddlewareIsAppliedEvent
18+
{
19+
protected bool $shouldBeApplied = true;
20+
protected ServerRequestInterface $serverRequest;
21+
22+
public function __construct(ServerRequestInterface $serverRequest)
23+
{
24+
$this->serverRequest = $serverRequest;
25+
}
26+
27+
public function doNotApply(): void
28+
{
29+
$this->shouldBeApplied = false;
30+
}
31+
32+
public function getServerRequest(): ServerRequestInterface
33+
{
34+
return $this->serverRequest;
35+
}
36+
37+
public function shouldBeApplied(): bool
38+
{
39+
return $this->shouldBeApplied;
40+
}
41+
}

src/Middleware/LowerCaseUri.php

+16-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Psr\Http\Message\ServerRequestInterface;
1717
use Psr\Http\Server\MiddlewareInterface;
1818
use Psr\Http\Server\RequestHandlerInterface;
19+
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
1920
use TYPO3\CMS\Core\Http\RedirectResponse;
2021
use TYPO3\CMS\Core\Routing\RouteNotFoundException;
2122
use TYPO3\CMS\Core\Routing\SiteRouteResult;
@@ -30,8 +31,20 @@
3031
*/
3132
class LowerCaseUri implements MiddlewareInterface
3233
{
34+
protected EventDispatcher $eventDispatcher;
35+
36+
public function __construct(EventDispatcher $eventDispatcher)
37+
{
38+
$this->eventDispatcher = $eventDispatcher;
39+
}
40+
3341
public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
3442
{
43+
$beforeMiddlewareIsAppliedEvent = new BeforeMiddlewareIsAppliedEvent($request);
44+
$this->eventDispatcher->dispatch($beforeMiddlewareIsAppliedEvent);
45+
if ($beforeMiddlewareIsAppliedEvent->shouldBeApplied() === false) {
46+
return $handler->handle($request);
47+
}
3548
/** @var Site $site */
3649
$site = $request->getAttribute('site');
3750

@@ -60,8 +73,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
6073
$redirectStatusCode = 307;
6174
if ($site instanceof Site) {
6275
$siteLanguage = $request->getAttribute('language')->toArray();
63-
$doRedirect = (bool) ($site->getConfiguration()['settings']['redirectOnUpperCase'] ?? $siteLanguage['redirectOnUpperCase'] ?? false);
64-
$redirectStatusCode = (int) ($site->getConfiguration()['settings']['redirectStatusCode'] ?? $siteLanguage['redirectStatusCode'] ?? 307);
76+
$doRedirect = (bool)($site->getConfiguration()['settings']['redirectOnUpperCase'] ?? $siteLanguage['redirectOnUpperCase'] ?? false);
77+
$redirectStatusCode = (int)($site->getConfiguration()['settings']['redirectStatusCode'] ?? $siteLanguage['redirectStatusCode'] ?? 307);
6578
}
6679
// Redirects only work on GET and HEAD requests
6780
if ($doRedirect && in_array($request->getMethod(), ['GET', 'HEAD'])) {
@@ -76,7 +89,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
7689
$updatedUri,
7790
$routeResult->getSite(),
7891
$routeResult->getLanguage(),
79-
mb_strtolower((string) $routeResult->getTail())
92+
mb_strtolower((string)$routeResult->getTail())
8093
);
8194
$request = $request->withAttribute('routing', $routeResult);
8295
}

0 commit comments

Comments
 (0)