Skip to content

Commit

Permalink
Merge pull request #7 from andersundsehr/feature/php8.3
Browse files Browse the repository at this point in the history
Support PHP 8.3, drops < PHP 8.1 support
  • Loading branch information
weakbit authored Jun 13, 2024
2 parents f3988a5 + b462b18 commit a9113df
Show file tree
Hide file tree
Showing 15 changed files with 180 additions and 59 deletions.
25 changes: 18 additions & 7 deletions .github/workflows/tasks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,30 @@ on: [push, pull_request]

jobs:
lint-php:
name: Linting php with grumphp
name: "php: ${{ matrix.php }} TYPO3: ${{ matrix.typo3 }}"
runs-on: ubuntu-latest
container:
image: kanti/buildy:7.4
strategy:
fail-fast: false
matrix:
php: [ '8.1', '8.2', '8.3' ]
typo3: [ '11', '12' ]
exclude:
- php: '8.1'
typo3: '13'
steps:
- name: Setup PHP with PECL extension
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
- uses: actions/checkout@v2
- uses: actions/cache@v2
with:
path: ~/.composer/cache/files
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.lock') }}
key: ${{ runner.os }}-${{ matrix.php }}-composer-${{ hashFiles('**/composer.lock') }}
restore-keys: |
${{ runner.os }}-composer-
- run: composer install --no-interaction --no-progress --ignore-platform-req=ext*
${{ runner.os }}-${{ matrix.php }}-composer-
- run: composer require typo3/minimal="^${{ matrix.typo3 }}" -W --dev
- run: composer install --no-interaction --no-progress
- run: ./vendor/bin/grumphp run --ansi

ter-release:
Expand All @@ -40,7 +51,7 @@ jobs:
- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
php-version: '8.1'
extensions: intl, mbstring, xml, soap, zip, curl
tools: composer

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
composer.lock
public/
vendor/
var/
39 changes: 39 additions & 0 deletions Classes/Cache/ClearCache.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

declare(strict_types=1);

namespace AUS\SsiInclude\Cache;

use AUS\SsiInclude\ViewHelpers\RenderIncludeViewHelper;
use TYPO3\CMS\Core\Core\Environment;

class ClearCache
{
/** @param array<mixed> $parameters */
public function clearCache(array $parameters): void
{
if (isset($parameters['cacheCmd']) && ($parameters['cacheCmd'] === 'pages' || $parameters['cacheCmd'] === 'all')) {
$path = Environment::getPublicPath() . RenderIncludeViewHelper::SSI_INCLUDE_DIR;
$this->removeFiles($path);
}
}

protected function removeFiles(string $dir): void
{
if (is_dir($dir)) {
$objects = scandir($dir);
if (!$objects) {
return;
}

foreach ($objects as $object) {
if ($object !== '.' && $object !== '..') {
$filePath = $dir . DIRECTORY_SEPARATOR . $object;
if (is_file($filePath) && is_writable($filePath)) {
unlink($filePath);
}
}
}
}
}
}
5 changes: 1 addition & 4 deletions Classes/Event/RenderedEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,8 @@

class RenderedEvent
{
protected string $html;

public function __construct(string $html)
public function __construct(protected string $html)
{
$this->html = $html;
}

public function getHtml(): string
Expand Down
5 changes: 4 additions & 1 deletion Classes/Middleware/InternalSsiRedirectMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,20 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
{
if (isset($request->getQueryParams()['ssi_include'])) {
$ssiInclude = $request->getQueryParams()['ssi_include'];
if (!preg_match('/^([a-zA-Z0-9_]+)$/', $ssiInclude)) {
if (!preg_match('/^(\w+)$/', (string) $ssiInclude)) {
return new HtmlResponse('ssi_include invalid', 400);
}

$cacheFileName = RenderIncludeViewHelper::SSI_INCLUDE_DIR . $ssiInclude;
$absolutePath = Environment::getPublicPath() . $cacheFileName;
if (!file_exists($absolutePath)) {
// ignore response use the content of the file:
$handler->handle($request->withAttribute('noCache', true));
}

return new HtmlResponse(file_get_contents($absolutePath) ?: '');
}

return $handler->handle($request);
}
}
2 changes: 1 addition & 1 deletion Classes/Utility/VersionUtility.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function getVersion(): string
$str = 'dev';
try {
return explode('@', Versions::getVersion('andersundsehr/ssi-include'))[0] ?? $str;
} catch (Throwable $e) {
} catch (Throwable) {
return $str;
}
}
Expand Down
26 changes: 13 additions & 13 deletions Classes/ViewHelpers/RenderIncludeViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace AUS\SsiInclude\ViewHelpers;

use Webimpress\SafeWriter\Exception\ExceptionInterface;
use Closure;
use AUS\SsiInclude\Event\RenderedEvent;
use Exception;
use TYPO3\CMS\Core\Context\Context;
Expand Down Expand Up @@ -33,14 +35,12 @@ public function initializeArguments(): void

/**
* @param array<string, mixed> $arguments
* @param \Closure $renderChildrenClosure
* @param RenderingContextInterface $renderingContext
* @return string
* @throws \Webimpress\SafeWriter\Exception\ExceptionInterface
* @throws Exception
* @throws ExceptionInterface
*/
public static function renderStatic(array $arguments, \Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
public static function renderStatic(array $arguments, Closure $renderChildrenClosure, RenderingContextInterface $renderingContext): string
{
$name = static::validateName($arguments);
$name = self::validateName($arguments);

$filename = static::getSiteName() . '_' . static::getLangauge() . '_' . $name;
$basePath = self::SSI_INCLUDE_DIR . $filename;
Expand All @@ -56,10 +56,11 @@ public static function renderStatic(array $arguments, \Closure $renderChildrenCl
$eventDispatcher->dispatch($renderedHtmlEvent);
$html = $renderedHtmlEvent->getHtml();

@mkdir(dirname($absolutePath), octdec($GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask']), true);
@mkdir(dirname($absolutePath), (int)octdec((string)$GLOBALS['TYPO3_CONF_VARS']['SYS']['folderCreateMask']), true);
FileWriter::writeFile($absolutePath, $html);
GeneralUtility::fixPermissions($absolutePath);
}

return '<!--# include wait="yes" virtual="' . $basePath . '?ssi_include=' . $filename . '" -->';
}

Expand All @@ -68,25 +69,24 @@ private static function shouldRenderFile(string $absolutePath, int $cacheLifeTim
if (!file_exists($absolutePath)) {
return true;
}

if ((filemtime($absolutePath) + $cacheLifeTime) < time()) {
return true;
}
if (self::isBackendUser()) {
return true;
}
return false;

return self::isBackendUser();
}

/**
* @param array<string, mixed> $arguments
* @return string
* @throws Exception
*/
private static function validateName(array $arguments): string
{
if (ctype_alnum($arguments['name'])) {
if (ctype_alnum((string) $arguments['name'])) {
return $arguments['name'];
}

throw new Exception(sprintf('Only Alphanumeric characters allowed got: "%s"', $arguments['name']));
}

Expand Down
6 changes: 4 additions & 2 deletions Configuration/RequestMiddlewares.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

use AUS\SsiInclude\Middleware\InternalSsiRedirectMiddleware;

return [
'frontend' => [
\AUS\SsiInclude\Middleware\InternalSsiRedirectMiddleware::class => [
'target' => \AUS\SsiInclude\Middleware\InternalSsiRedirectMiddleware::class,
InternalSsiRedirectMiddleware::class => [
'target' => InternalSsiRedirectMiddleware::class,
'before' => [
'typo3/cms-core/normalized-params-attribute'
],
Expand Down
56 changes: 26 additions & 30 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,57 +1,53 @@
{
"name": "andersundsehr/ssi-include",
"description": "Allows to periodically create ssi includes from anders und sehr GmbH",
"type": "typo3-cms-extension",
"license": "GPL-3.0-or-later",
"type": "typo3-cms-extension",
"authors": [
{
"name": "Matthias Vogel",
"email": "[email protected]",
"homepage": "https://andersundsehr.com"
}
],
"require": {
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
"ocramius/package-versions": "^2.1.0",
"typo3/cms-fluid": "^10.4.0 || ^11.5.0 || ^12.4.0",
"typo3/cms-frontend": "^10.4.0 || ^11.5.0 || ^12.4.0",
"webimpress/safe-writer": "^2.2.0"
},
"require-dev": {
"composer/composer": "^2.5.5",
"pluswerk/grumphp-config": "^7.0",
"saschaegerer/phpstan-typo3": "^1.10.0",
"ssch/typo3-rector": "^2.5.0"
},
"replace": {
"typo3-ter/ssi-include": "self.version"
},
"extra": {
"typo3/cms": {
"extension-key": "ssi_include"
},
"pluswerk/grumphp-config": {
"auto-setting": true
},
"grumphp": {
"config-default-path": "vendor/pluswerk/grumphp-config/grumphp.yml"
"autoload": {
"psr-4": {
"AUS\\SsiInclude\\": "Classes/"
}
},
"config": {
"sort-packages": true,
"allow-plugins": {
"ergebnis/composer-normalize": true,
"phpro/grumphp": true,
"typo3/class-alias-loader": true,
"typo3/cms-composer-installers": true,
"phpstan/extension-installer": true,
"pluswerk/grumphp-config": true,
"phpstan/extension-installer": true
}
"typo3/class-alias-loader": true,
"typo3/cms-composer-installers": true
},
"sort-packages": true
},
"autoload": {
"psr-4": {
"AUS\\SsiInclude\\": "Classes/"
"extra": {
"typo3/cms": {
"extension-key": "ssi_include"
}
},
"ter-require": {
"webimpress/safe-writer": "^2.2.0"
},
"require": {
"php": "~7.4.0 || ~8.0.0 || ~8.1.0 || ~8.2.0",
"ocramius/package-versions": "^2.1.0",
"typo3/cms-fluid": "^10.4.0 || ^11.5.0 || ^12.4.0",
"typo3/cms-frontend": "^10.4.0 || ^11.5.0 || ^12.4.0",
"webimpress/safe-writer": "^2.2.0"
},
"require-dev": {
"phpstan/extension-installer": "^1.1.0",
"pluswerk/grumphp-config": "^5.0",
"saschaegerer/phpstan-typo3": "^0.13.3"
}
}
4 changes: 3 additions & 1 deletion ext_emconf.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

use AUS\SsiInclude\Utility\VersionUtility;

/** @var string $_EXTKEY */
$EM_CONF[$_EXTKEY] = [
'title' => 'SSI Include - Render your includes',
Expand All @@ -10,7 +12,7 @@
'author_company' => 'anders und sehr GmbH',
'state' => 'stable',
'clearCacheOnLoad' => 0,
'version' => \AUS\SsiInclude\Utility\VersionUtility::getVersion(),
'version' => VersionUtility::getVersion(),
'constraints' => [
'depends' => [
'typo3' => '10.4.0-11.99.99',
Expand Down
4 changes: 4 additions & 0 deletions ext_localconf.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<?php

use AUS\SsiInclude\Cache\ClearCache;

if (!defined('TYPO3_COMPOSER_MODE')) {
// include autoload if this is the TER version
require __DIR__ . '/vendor/autoload.php';
}

$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['t3lib/class.t3lib_tcemain.php']['clearCachePostProc'][] = ClearCache::class . '->clearCache';
16 changes: 16 additions & 0 deletions grumphp.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
imports:
- { resource: vendor/pluswerk/grumphp-config/grumphp.yml }
parameters:
convention.process_timeout: 240
convention.security_checker_blocking: true
convention.jsonlint_ignore_pattern: { }
convention.xmllint_ignore_pattern: { }
convention.yamllint_ignore_pattern: { }
convention.phpcslint_ignore_pattern: { }
convention.phpcslint_exclude: { }
convention.xlifflint_ignore_pattern: { }
convention.rector_ignore_pattern: { }
convention.rector_enabled: true
convention.rector_config: rector.php
convention.rector_clear-cache: false
convention.phpstan_level: null
1 change: 1 addition & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
parameters:
7 changes: 7 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
includes:
- phpstan-baseline.neon
- vendor/andersundsehr/phpstan-git-files/extension.php

parameters:
level: 8
reportUnmatchedIgnoredErrors: false
Loading

0 comments on commit a9113df

Please sign in to comment.