Skip to content
Open
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
775f53e
chore(deps): keep rector below 2.9 until typo3-rector supports it
Mainbird Nov 27, 2026
5b7e35a
refactor: remove the unused OptionsReader::path method
Mainbird Nov 27, 2026
641a8e2
refactor: remove the unread product property from ComponentLifecycle
Mainbird Nov 27, 2026
b1865e0
chore: declare strict types in ext_localconf.php
Mainbird Nov 27, 2026
c4ef6ef
chore: use the preset's full constant type coverage now that PHP 8.4 …
Mainbird Nov 27, 2026
8d0c803
chore: add dead code detection to the PHPStan setup
Mainbird Nov 27, 2026
a2958a9
test: cover the JavaScript minifier with its own unit tests
Mainbird Nov 27, 2026
9961a38
refactor: move whitespace and comment handling out of the JavaScript …
Mainbird Nov 27, 2026
05d35ba
refactor: extract the date formatting of the last deployment listener
Mainbird Nov 27, 2026
73cd649
fix: show the last deployment time when the checked file exists
Mainbird Nov 27, 2026
1e1d45a
fix: throw on invalid JSON instead of decoding it to null
Mainbird Nov 27, 2026
0412ab1
fix: keep widget option exception codes within the 32-bit integer range
Mainbird Nov 27, 2026
a48f4c5
refactor: move the unescaped tag builder of the CSS view helper into …
Mainbird Nov 27, 2026
cfc6636
refactor: read the current date from the date aspect in the dashboard…
Mainbird Nov 27, 2026
60e5b99
chore(deps): raise the CGL presets and typo3/coding-standards to thei…
Mainbird Nov 27, 2026
0d3c7d1
chore(deps): require phpunit directly, the unit tests use it
Mainbird Nov 27, 2026
20e87ff
chore: scan ext_localconf.php and allow packages for consuming projec…
Mainbird Nov 27, 2026
7b76785
chore: add the spirit team as code owner
Mainbird Nov 27, 2026
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
3 changes: 3 additions & 0 deletions Classes/Domain/Repository/AbstractRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
use TYPO3\CMS\Core\Database\Query\QueryBuilder;
use TYPO3\CMS\Core\Utility\GeneralUtility;

/**
* @api
*/
abstract class AbstractRepository
{
abstract protected function getTableName(): string;
Expand Down
52 changes: 29 additions & 23 deletions Classes/EventListener/LastDeploymentEventListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,32 +21,11 @@ public function __invoke(SystemInformationToolbarCollectorEvent $systemInformati
return;
}
$path = GeneralUtility::getFileAbsFileName($GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS'][Configuration::EXT_KEY->value]['systemInformationToolbar']['fileToCheck']);
if ($path !== '' || !file_exists($path)) {
if ($path === '' || !file_exists($path)) {
return;
}

$lastModified = $this->getLastModifiedTime($path);
if (class_exists(\IntlDateFormatter::class)) {
$locale = $GLOBALS['TYPO3_CONF_VARS']['SYS']['locale'] ?? \Locale::getDefault();
$timeZone = 'Europe/Berlin';

if (isset($GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone']) && $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'] !== '') {
$timeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'];
} elseif (date_default_timezone_get() !== '') {
$timeZone = date_default_timezone_get();
}

$formatter = new \IntlDateFormatter(
$locale,
\IntlDateFormatter::FULL,
\IntlDateFormatter::FULL,
$timeZone,
\IntlDateFormatter::GREGORIAN
);
$humanFormatDateTime = $formatter->format($lastModified) ?: '';
} else {
$humanFormatDateTime = date('D, d.m.Y H:i', $lastModified);
}
$humanFormatDateTime = $this->formatDateTime($this->getLastModifiedTime($path));

$systemInformation->getToolbarItem()->addSystemInformation(
$this->getLanguageService()->sL('typo3_toolbox.be:system_information.last_updated'),
Expand All @@ -55,6 +34,33 @@ public function __invoke(SystemInformationToolbarCollectorEvent $systemInformati
);
}

private function formatDateTime(int $timestamp): string
{
if (!class_exists(\IntlDateFormatter::class)) {
return date('D, d.m.Y H:i', $timestamp);
}

$formatter = new \IntlDateFormatter(
$GLOBALS['TYPO3_CONF_VARS']['SYS']['locale'] ?? \Locale::getDefault(),
\IntlDateFormatter::FULL,
\IntlDateFormatter::FULL,
$this->getTimeZone(),
\IntlDateFormatter::GREGORIAN
);

return $formatter->format($timestamp) ?: '';
}

private function getTimeZone(): string
{
$configuredTimeZone = $GLOBALS['TYPO3_CONF_VARS']['SYS']['phpTimeZone'] ?? '';
if ($configuredTimeZone !== '') {
return $configuredTimeZone;
}

return date_default_timezone_get() ?: 'Europe/Berlin';
}

private function getLastModifiedTime(string $path): int
{
if (!file_exists($path)) {
Expand Down
2 changes: 1 addition & 1 deletion Classes/Minifier/HtmlMinifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ function (array $matches): string {
$json = trim($matches[1]);

try {
$minifiedJson = json_encode(json_decode($json, true), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
$minifiedJson = json_encode(json_decode($json, true, 512, JSON_THROW_ON_ERROR), JSON_THROW_ON_ERROR | JSON_UNESCAPED_SLASHES);
} catch (\JsonException) {
return '';
}
Expand Down
103 changes: 10 additions & 93 deletions Classes/Minifier/JavaScriptMinifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace MoveElevator\Typo3Toolbox\Minifier;

final class JavaScriptMinifier
final readonly class JavaScriptMinifier
{
/**
* @var list<string>
Expand Down Expand Up @@ -40,11 +40,10 @@ final class JavaScriptMinifier

private const string REGULAR_EXPRESSION_PATTERN = '/\/(?:\\\\.|\[(?:\\\\.|[^\]\\\\\n])*\]|[^\/\\\\\n\[])+\/[a-z]*/A';

private const string IDENTIFIER_CHARACTER_PATTERN = '/[\w$\\\\\x80-\xff]/';

private const string STATEMENT_END_PATTERN = '/[\w$)\]}\'"`]/';

private const string STATEMENT_START_PATTERN = '/[\w$({\[+\-!~\'"`\/]/';
public function __construct(
private JavaScriptWhitespace $whitespace = new JavaScriptWhitespace(),
) {
}

public function minify(string $code): string
{
Expand All @@ -56,18 +55,15 @@ public function minify(string $code): string
$followsControlHead = false;

while ($position < $length) {
$skipped = $this->readComment($code, $position) ?? $this->readWhitespace($code, $position);
$skipped = $this->whitespace->skip($code, $position);

if (null !== $skipped) {
[$position, $spansLines] = $skipped;
$pendingLinebreak = ($pendingLinebreak ?? false) || $spansLines;
continue;
}

if (null !== $pendingLinebreak && '' !== $result) {
$result .= $this->separator($result, $code[$position], $pendingLinebreak);
}

$result .= $this->whitespace->separator($result, $code[$position], $pendingLinebreak);
$pendingLinebreak = null;
$literal = $this->readLiteral($code, $position, $result, $followsControlHead);

Expand All @@ -93,85 +89,6 @@ public function minify(string $code): string
return $result;
}

/**
* @return array{int, bool}|null
*/
private function readWhitespace(string $code, int $position): ?array
{
$run = strspn($code, " \t\n\r", $position);

if (0 === $run) {
return null;
}

$whitespace = substr($code, $position, $run);

return [$position + $run, str_contains($whitespace, "\n") || str_contains($whitespace, "\r")];
}

/**
* @return array{int, bool}|null
*/
private function readComment(string $code, int $position): ?array
{
if ('/' !== $code[$position]) {
return null;
}

$nextCharacter = $code[$position + 1] ?? '';

if ('*' === $nextCharacter) {
$end = strpos($code, '*/', $position + 2);
$end = false === $end ? strlen($code) : $end + 2;

return [$end, str_contains(substr($code, $position, $end - $position), "\n")];
}

if ('/' === $nextCharacter) {
$end = strpos($code, "\n", $position);

return [false === $end ? strlen($code) : $end, false];
}

return null;
}

/**
* A linebreak that automatic semicolon insertion relies on has to survive, otherwise
* `return` and its value end up on one line and the script changes meaning.
*/
private function separator(string $precedingCode, string $nextCharacter, bool $spansLines): string
{
$previousCharacter = $precedingCode[strlen($precedingCode) - 1];

if ($spansLines
&& 1 === preg_match(self::STATEMENT_END_PATTERN, $previousCharacter)
&& 1 === preg_match(self::STATEMENT_START_PATTERN, $nextCharacter)
) {
return "\n";
}

return $this->needsSpace($previousCharacter, $nextCharacter) ? ' ' : '';
}

/**
* Dropping the space would merge two identifiers, or turn `a + +b` into an increment.
*/
private function needsSpace(string $previousCharacter, string $nextCharacter): bool
{
if (('+' === $previousCharacter || '-' === $previousCharacter) && $previousCharacter === $nextCharacter) {
return true;
}

// `1 .toString()` would collapse into the invalid numeric literal `1.toString()`
if ('.' === $nextCharacter && 1 === preg_match('/\d/', $previousCharacter)) {
return true;
}

return 1 === preg_match(self::IDENTIFIER_CHARACTER_PATTERN, $previousCharacter)
&& 1 === preg_match(self::IDENTIFIER_CHARACTER_PATTERN, $nextCharacter);
}

/**
* @return array{string, int}|null
*/
Expand Down Expand Up @@ -245,10 +162,10 @@ private function findInterpolationEnd(string $code, int $position): int
$depth = 1;

while ($position < $length) {
$comment = $this->readComment($code, $position);
$skipped = $this->whitespace->skip($code, $position);

if (null !== $comment) {
$position = $comment[0];
if (null !== $skipped) {
$position = $skipped[0];
continue;
}

Expand Down
110 changes: 110 additions & 0 deletions Classes/Minifier/JavaScriptWhitespace.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?php

declare(strict_types=1);

namespace MoveElevator\Typo3Toolbox\Minifier;

/**
* Whitespace and comments between JavaScript tokens, and what has to remain of them.
*/
final class JavaScriptWhitespace
{
private const string IDENTIFIER_CHARACTER_PATTERN = '/[\w$\\\\\x80-\xff]/';

private const string STATEMENT_END_PATTERN = '/[\w$)\]}\'"`]/';

private const string STATEMENT_START_PATTERN = '/[\w$({\[+\-!~\'"`\/]/';

/**
* @return array{int, bool}|null the position after the comment or whitespace run, and whether it spans lines
*/
public function skip(string $code, int $position): ?array
{
return $this->readComment($code, $position) ?? $this->readWhitespace($code, $position);
}

/**
* A linebreak that automatic semicolon insertion relies on has to survive, otherwise
* `return` and its value end up on one line and the script changes meaning.
*
* @param bool|null $spansLines null when nothing was skipped between the two tokens
*/
public function separator(string $precedingCode, string $nextCharacter, ?bool $spansLines): string
{
if (null === $spansLines || '' === $precedingCode) {
return '';
}

$previousCharacter = $precedingCode[strlen($precedingCode) - 1];

if ($spansLines
&& 1 === preg_match(self::STATEMENT_END_PATTERN, $previousCharacter)
&& 1 === preg_match(self::STATEMENT_START_PATTERN, $nextCharacter)
) {
return "\n";
}

return $this->needsSpace($previousCharacter, $nextCharacter) ? ' ' : '';
}

/**
* @return array{int, bool}|null
*/
private function readWhitespace(string $code, int $position): ?array
{
$run = strspn($code, " \t\n\r", $position);

if (0 === $run) {
return null;
}

$whitespace = substr($code, $position, $run);

return [$position + $run, str_contains($whitespace, "\n") || str_contains($whitespace, "\r")];
}

/**
* @return array{int, bool}|null
*/
private function readComment(string $code, int $position): ?array
{
if ('/' !== $code[$position]) {
return null;
}

$nextCharacter = $code[$position + 1] ?? '';

if ('*' === $nextCharacter) {
$end = strpos($code, '*/', $position + 2);
$end = false === $end ? strlen($code) : $end + 2;

return [$end, str_contains(substr($code, $position, $end - $position), "\n")];
}

if ('/' === $nextCharacter) {
$end = strpos($code, "\n", $position);

return [false === $end ? strlen($code) : $end, false];
}

return null;
}

/**
* Dropping the space would merge two identifiers, or turn `a + +b` into an increment.
*/
private function needsSpace(string $previousCharacter, string $nextCharacter): bool
{
if (('+' === $previousCharacter || '-' === $previousCharacter) && $previousCharacter === $nextCharacter) {
return true;
}

// `1 .toString()` would collapse into the invalid numeric literal `1.toString()`
if ('.' === $nextCharacter && 1 === preg_match('/\d/', $previousCharacter)) {
return true;
}

return 1 === preg_match(self::IDENTIFIER_CHARACTER_PATTERN, $previousCharacter)
&& 1 === preg_match(self::IDENTIFIER_CHARACTER_PATTERN, $nextCharacter);
}
}
11 changes: 1 addition & 10 deletions Classes/ViewHelpers/Asset/CssViewHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use TYPO3\CMS\Core\Page\AssetCollector;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3Fluid\Fluid\Core\ViewHelper\AbstractTagBasedViewHelper;
use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;

/*
* Usage example:
Expand Down Expand Up @@ -35,15 +34,7 @@ public function __construct(protected AssetCollector $assetCollector)
#[\Override]
public function initialize(): void
{
// Add a tag builder, that does not html encode values, because rendering with encoding happens in AssetRenderer
$this->setTagBuilder(
new class () extends TagBuilder {
public function addAttribute($attributeName, $attributeValue, $escapeSpecialCharacters = false): void // @phpstan-ignore-line typeCoverage.paramTypeCoverage
{
parent::addAttribute($attributeName, $attributeValue, false);
}
}
);
$this->setTagBuilder(new UnescapedTagBuilder());

parent::initialize();
}
Expand Down
24 changes: 24 additions & 0 deletions Classes/ViewHelpers/Asset/UnescapedTagBuilder.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace MoveElevator\Typo3Toolbox\ViewHelpers\Asset;

use TYPO3Fluid\Fluid\Core\ViewHelper\TagBuilder;

/**
* Leaves attribute values unencoded, because the AssetRenderer encodes them when rendering.
*/
final class UnescapedTagBuilder extends TagBuilder
{
/**
* Replaces the inherited PHPDoc type, whose array and Traversable lack value types.
*
* @param mixed $attributeValue
*/
#[\Override]
public function addAttribute(string $attributeName, mixed $attributeValue, bool $escapeSpecialCharacters = false): void
{
parent::addAttribute($attributeName, $attributeValue, false);
}
}
Loading