Skip to content

Commit

Permalink
!!! [TASK] change requirements
Browse files Browse the repository at this point in the history
* drop TYPO3 < 11 Support
* add TYPO3 13 Support
* add ci workflow
* add BeforeMiddlewareIsAppliedEvent

Fixes: #5
Fixes: #11
  • Loading branch information
achimfritz committed Jul 1, 2024
1 parent d899d70 commit b2a8bbd
Show file tree
Hide file tree
Showing 11 changed files with 164 additions and 38 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ indent_size = 2

# JSON-Files
[*.json]
indent_style = tab
indent_size = 2

# ReST-Files
[*.rst]
Expand Down
48 changes: 48 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: CI

on: [push, pull_request]

jobs:
testsuite:

runs-on: ubuntu-latest
strategy:
matrix:
TYPO3: ['11' , '12', '13']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Set up PHP Version
uses: shivammathur/setup-php@v2
with:
php-version: 8.3
tools: composer:v2

- name: Validate composer.json and composer.lock
run: composer validate

- name: Cache dependencies
uses: actions/cache@v1
with:
path: ~/.composer/cache
key: dependencies-composer-${{ hashFiles('composer.json') }}

- name: Install composer dependencies TYPO3 13
if: matrix.TYPO3 == '13'
run: |
composer install --no-progress --no-interaction
- name: Install composer dependencies TYPO3 12
if: matrix.TYPO3 == '12'
run: |
composer require typo3/cms-core:^12.4 --no-progress --no-interaction --dev -W
- name: Install composer dependencies TYPO3 11
if: matrix.TYPO3 == '11'
run: |
composer require typo3/cms-core:^11.5 --no-progress --no-interaction --dev -W
- name: Phpstan
run: ./vendor/bin/phpstan analyze -c phpstan.neon
- name: Phpcsfix
run: ./vendor/bin/php-cs-fixer fix --config=php-cs-fixer.php --dry-run --stop-on-violation --using-cache=no
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/composer.lock
/public/
/vendor/
/.php_cs.cache
/.php-cs-fixer.cache
8 changes: 8 additions & 0 deletions Configuration/Services.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
services:
_defaults:
autowire: true
autoconfigure: true
public: false

B13\JustInCase\:
resource: '../src/*'
2 changes: 1 addition & 1 deletion Configuration/SiteConfiguration/Overrides/sites.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,5 +37,5 @@
$GLOBALS['SiteConfiguration']['site_language']['types']['1']['showitem'] = str_replace(
'flag',
'flag, ,--palette--;;justincase',
(string) $GLOBALS['SiteConfiguration']['site_language']['types']['1']['showitem']
(string)$GLOBALS['SiteConfiguration']['site_language']['types']['1']['showitem']
);
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,11 @@ If you wish to enable redirect for all languages, add these lines at the bottom

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

## Events

a ```BeforeMiddlewareIsAppliedEvent``` is fired before LowerCaseUri Middleware is applied.
you can prevent applying Middleware by calling `event->doNotApply`

## Caveats

If specific route enhancers check on camel-case (e.g. `{order}/paymentForm/`) this might lead to unexpected behaviours
Expand Down
67 changes: 36 additions & 31 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,33 +1,38 @@
{
"name": "b13/justincase",
"type": "typo3-cms-extension",
"description": "With incoming URLs, it does not matter if they are upper/lowercase, they just work.",
"license": "GPL-2.0-or-later",
"require": {
"php": "^7.2 || ^8.0",
"typo3/cms-core": "^9.5 || ^10.0 || ^11.0 || ^12.0"
},
"replace": {
"typo3-ter/justincase": "self.version"
},
"extra": {
"typo3/cms": {
"extension-key": "justincase"
}
},
"autoload": {
"psr-4": {
"B13\\JustInCase\\": "src/"
}
},
"require-dev": {
"typo3/coding-standards": "^0.2.0",
"typo3/tailor": "^1.1"
},
"config": {
"sort-packages": true
},
"scripts": {
"php:cs": "@composer exec php-cs-fixer fix"
}
"name": "b13/justincase",
"type": "typo3-cms-extension",
"description": "With incoming URLs, it does not matter if they are upper/lowercase, they just work.",
"license": "GPL-2.0-or-later",
"require": {
"typo3/cms-core": "^11.5 || ^12.4 || ^13.1"
},
"replace": {
"typo3-ter/justincase": "self.version"
},
"extra": {
"typo3/cms": {
"extension-key": "justincase"
}
},
"autoload": {
"psr-4": {
"B13\\JustInCase\\": "src/"
}
},
"require-dev": {
"typo3/coding-standards": "^0.5.5",
"saschaegerer/phpstan-typo3": "^1.8",
"typo3/tailor": "^1.1"
},
"config": {
"sort-packages": true,
"allow-plugins": {
"typo3/cms-composer-installers": true,
"typo3/class-alias-loader": true
}
},
"scripts": {
"php:cs": "@composer exec 'php-cs-fixer fix --config=php-cs-fixer.php'",
"php:phpstan": "@composer exec 'phpstan analyse -c phpstan.neon'"
}
}
2 changes: 1 addition & 1 deletion .php_cs → php-cs-fixer.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?php

$config = \TYPO3\CodingStandards\CsFixerConfig::create();
$config->getFinder()->in(__DIR__);
$config->getFinder()->exclude(['public', 'vendor'])->in(__DIR__);
return $config;
6 changes: 6 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
parameters:
level: 5

paths:
- %currentWorkingDirectory%/src

41 changes: 41 additions & 0 deletions src/Middleware/BeforeMiddlewareIsAppliedEvent.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

declare(strict_types=1);

namespace B13\JustInCase\Middleware;

/*
* This file is part of TYPO3 CMS-based extension "JustInCase" by b13.
*
* It is free software; you can redistribute it and/or modify it under
* the terms of the GNU General Public License, either version 2
* of the License, or any later version.
*/

use Psr\Http\Message\ServerRequestInterface;

final class BeforeMiddlewareIsAppliedEvent
{
protected bool $shouldBeApplied = true;
protected ServerRequestInterface $serverRequest;

public function __construct(ServerRequestInterface $serverRequest)
{
$this->serverRequest = $serverRequest;
}

public function doNotApply(): void
{
$this->shouldBeApplied = false;
}

public function getServerRequest(): ServerRequestInterface
{
return $this->serverRequest;
}

public function shouldBeApplied(): bool
{
return $this->shouldBeApplied;
}
}
19 changes: 16 additions & 3 deletions src/Middleware/LowerCaseUri.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;
use TYPO3\CMS\Core\EventDispatcher\EventDispatcher;
use TYPO3\CMS\Core\Http\RedirectResponse;
use TYPO3\CMS\Core\Routing\RouteNotFoundException;
use TYPO3\CMS\Core\Routing\SiteRouteResult;
Expand All @@ -30,8 +31,20 @@
*/
class LowerCaseUri implements MiddlewareInterface
{
protected EventDispatcher $eventDispatcher;

public function __construct(EventDispatcher $eventDispatcher)
{
$this->eventDispatcher = $eventDispatcher;
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$beforeMiddlewareIsAppliedEvent = new BeforeMiddlewareIsAppliedEvent($request);
$this->eventDispatcher->dispatch($beforeMiddlewareIsAppliedEvent);
if ($beforeMiddlewareIsAppliedEvent->shouldBeApplied() === false) {
return $handler->handle($request);
}
/** @var Site $site */
$site = $request->getAttribute('site');

Expand Down Expand Up @@ -60,8 +73,8 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$redirectStatusCode = 307;
if ($site instanceof Site) {
$siteLanguage = $request->getAttribute('language')->toArray();
$doRedirect = (bool) ($site->getConfiguration()['settings']['redirectOnUpperCase'] ?? $siteLanguage['redirectOnUpperCase'] ?? false);
$redirectStatusCode = (int) ($site->getConfiguration()['settings']['redirectStatusCode'] ?? $siteLanguage['redirectStatusCode'] ?? 307);
$doRedirect = (bool)($site->getConfiguration()['settings']['redirectOnUpperCase'] ?? $siteLanguage['redirectOnUpperCase'] ?? false);
$redirectStatusCode = (int)($site->getConfiguration()['settings']['redirectStatusCode'] ?? $siteLanguage['redirectStatusCode'] ?? 307);
}
// Redirects only work on GET and HEAD requests
if ($doRedirect && in_array($request->getMethod(), ['GET', 'HEAD'])) {
Expand All @@ -76,7 +89,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$updatedUri,
$routeResult->getSite(),
$routeResult->getLanguage(),
mb_strtolower((string) $routeResult->getTail())
mb_strtolower((string)$routeResult->getTail())
);
$request = $request->withAttribute('routing', $routeResult);
}
Expand Down

0 comments on commit b2a8bbd

Please sign in to comment.