Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TASK: Add TYPO3 13 compatibility #230

Merged
merged 1 commit into from
Oct 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .github/workflows/coding_standard.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ 7.4, 8.0, 8.1 ]
php-versions: [ 8.1 ]
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/php_linter.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: [ 7.4, 8.0, 8.1 ]
php-versions: [ 8.1, 8.2, 8.3 ]
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/phpstan.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:

- uses: shivammathur/setup-php@v2
with:
php-version: 7.4
php-version: 8.1
coverage: none
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,8 @@ jobs:
strategy:
matrix:
typo3-php-versions:
- { typo3: 10, php: 7.4 }
- { typo3: 11, php: 7.4 }
- { typo3: 12, php: 8.1 }
- { typo3: 13, php: 8.1 }

name: "Run tests with PHP ${{ matrix.typo3-php-versions.php }} using TYPO3 ${{ matrix.typo3-php-versions.typo3 }}"
steps:
Expand Down
12 changes: 6 additions & 6 deletions Build/FunctionalTests.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>../Classes/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/FunctionalTestsBootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd">
<testsuites>
<testsuite name="typo3_encore tests">
<directory>../Tests/Functional/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>../Classes/</directory>
</include>
</source>
</phpunit>
12 changes: 6 additions & 6 deletions Build/UnitTests.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<?xml version="1.0"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory>../Classes/</directory>
</include>
</coverage>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="true" bootstrap="../.Build/vendor/typo3/testing-framework/Resources/Core/Build/UnitTestsBootstrap.php" colors="true" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.4/phpunit.xsd">
<testsuites>
<testsuite name="typo3_encore tests">
<directory>../Tests/Unit/</directory>
</testsuite>
</testsuites>
<source>
<include>
<directory>../Classes/</directory>
</include>
</source>
</phpunit>
16 changes: 5 additions & 11 deletions Classes/Asset/EntrypointLookup.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,20 @@ final class EntrypointLookup implements EntrypointLookupInterface, IntegrityData
{
private ?array $entriesData = null;

private string $entrypointJsonPath;
private readonly string $entrypointJsonPath;

private array $returnedFiles = [];

private JsonDecoderInterface $jsonDecoder;

private FilesystemInterface $filesystem;

private bool $strictMode;
private readonly FilesystemInterface $filesystem;

public function __construct(
string $entrypointJsonPath,
bool $strictMode,
JsonDecoderInterface $jsonDecoder,
private readonly bool $strictMode,
private readonly JsonDecoderInterface $jsonDecoder,
FilesystemInterface $filesystem
) {
$this->entrypointJsonPath = $filesystem->getFileAbsFileName($entrypointJsonPath);
$this->jsonDecoder = $jsonDecoder;
$this->filesystem = $filesystem;
$this->strictMode = $strictMode;
}

public function getJavaScriptFiles(string $entryName): array
Expand Down Expand Up @@ -127,7 +121,7 @@ private function getEntriesData(): array

try {
$this->entriesData = $this->jsonDecoder->decode($this->filesystem->get($this->entrypointJsonPath));
} catch (JsonDecodeException $e) {
} catch (JsonDecodeException) {
throw new InvalidArgumentException(sprintf(
'There was a problem JSON decoding the "%s" file',
$this->entrypointJsonPath
Expand Down
12 changes: 4 additions & 8 deletions Classes/Asset/EntrypointLookupCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,15 @@

class EntrypointLookupCollection implements EntrypointLookupCollectionInterface
{
private EntryLookupFactoryInterface $entryLookupFactory;

/**
* @var array|EntrypointLookupInterface[]
*/
private ?array $buildEntrypoints = null;

private ?string $defaultBuildName;

public function __construct(EntryLookupFactoryInterface $entryLookupFactory, string $defaultBuildName = null)
{
$this->entryLookupFactory = $entryLookupFactory;
$this->defaultBuildName = $defaultBuildName;
public function __construct(
private readonly EntryLookupFactoryInterface $entryLookupFactory,
private readonly ?string $defaultBuildName = null
) {
}

public function getEntrypointLookup(string $buildName = null): EntrypointLookupInterface
Expand Down
23 changes: 8 additions & 15 deletions Classes/Asset/TagRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,11 @@

final class TagRenderer implements TagRendererInterface
{
private EntrypointLookupCollectionInterface $entrypointLookupCollection;

private AssetRegistryInterface $assetRegistry;

private ?ApplicationType $applicationType = null;

public function __construct(
EntrypointLookupCollectionInterface $entrypointLookupCollection,
AssetRegistryInterface $assetRegistry
private readonly EntrypointLookupCollectionInterface $entrypointLookupCollection,
private readonly AssetRegistryInterface $assetRegistry
) {
try {
$this->applicationType = array_key_exists(
Expand All @@ -42,12 +38,9 @@ public function __construct(
) && $GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface ? ApplicationType::fromRequest(
$GLOBALS['TYPO3_REQUEST']
) : null;
} catch (RuntimeException $e) {
} catch (RuntimeException) {
$this->applicationType = null;
}

$this->entrypointLookupCollection = $entrypointLookupCollection;
$this->assetRegistry = $assetRegistry;
}

public function renderWebpackScriptTags(ScriptTag $scriptTag): void
Expand All @@ -71,7 +64,7 @@ public function renderWebpackScriptTags(ScriptTag $scriptTag): void
// To do this, it's split up into two parts. The first part wraps the first file
// and the second part wraps the last file.
$splitChar = ! empty($parameters['splitChar']) ? $parameters['splitChar'] : '|';
$wrapArr = explode($splitChar, $parameters['allWrap'], 2);
$wrapArr = explode($splitChar, (string) $parameters['allWrap'], 2);
$wrapFirst = $wrapArr[0] . $splitChar;
$wrapLast = $splitChar . $wrapArr[1];
unset($parameters['allWrap']);
Expand All @@ -93,7 +86,7 @@ public function renderWebpackScriptTags(ScriptTag $scriptTag): void
}

$attributes = array_replace([
'file' => $this->removeLeadingSlash($file, $parameters) ? ltrim($file, '/') : $file,
'file' => $this->removeLeadingSlash($file, $parameters) ? ltrim((string) $file, '/') : $file,
'type' => $this->removeType($parameters) ? '' : 'text/javascript',
'compress' => false,
'forceOnTop' => false,
Expand All @@ -112,7 +105,7 @@ public function renderWebpackScriptTags(ScriptTag $scriptTag): void

if ($scriptTag->isLibrary()) {
$pageRendererMethodName .= 'Library';
$filename = basename($file);
$filename = basename((string) $file);
$pageRenderer->{$pageRendererMethodName}($filename, ...$attributes);
} else {
$pageRendererMethodName .= 'File';
Expand Down Expand Up @@ -146,7 +139,7 @@ public function renderWebpackLinkTags(LinkTag $linkTag): void
// To do this, it's split up into two parts. The first part wraps the first file
// and the second part wraps the last file.
$splitChar = ! empty($parameters['splitChar']) ? $parameters['splitChar'] : '|';
$wrapArr = explode($splitChar, $parameters['allWrap'], 2);
$wrapArr = explode($splitChar, (string) $parameters['allWrap'], 2);
$wrapFirst = $wrapArr[0] . $splitChar;
$wrapLast = $splitChar . $wrapArr[1];
unset($parameters['allWrap']);
Expand All @@ -165,7 +158,7 @@ public function renderWebpackLinkTags(LinkTag $linkTag): void
}

$attributes = array_replace([
'file' => $this->removeLeadingSlash($file, $parameters) ? ltrim($file, '/') : $file,
'file' => $this->removeLeadingSlash($file, $parameters) ? ltrim((string) $file, '/') : $file,
'rel' => 'stylesheet',
'media' => $linkTag->getMedia(),
'title' => '',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

final class RichtextEncoreConfiguration implements FormDataProviderInterface
{
private EntrypointLookupCollectionInterface $entrypointLookupCollection;
private readonly EntrypointLookupCollectionInterface $entrypointLookupCollection;

public function __construct(EntrypointLookupCollectionInterface $entrypointLookupCollection = null)
{
Expand Down
8 changes: 3 additions & 5 deletions Classes/Integration/AssetRegistry.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,9 @@ final class AssetRegistry implements AssetRegistryInterface

private array $defaultAttributes = [];

private SettingsServiceInterface $settingsService;

public function __construct(SettingsServiceInterface $settingsService)
{
$this->settingsService = $settingsService;
public function __construct(
private readonly SettingsServiceInterface $settingsService
) {
$this->reset();
}

Expand Down
15 changes: 3 additions & 12 deletions Classes/Integration/EntryLookupFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,16 @@

final class EntryLookupFactory implements EntryLookupFactoryInterface
{
private SettingsServiceInterface $settingsService;

private FilesystemInterface $filesystem;

/**
* @var array|EntrypointLookupInterface[]
*/
private static ?array $collection = null;

private JsonDecoderInterface $jsonDecoder;

public function __construct(
SettingsServiceInterface $settingsService,
FilesystemInterface $filesystem,
JsonDecoderInterface $jsonDecoder
private readonly SettingsServiceInterface $settingsService,
private readonly FilesystemInterface $filesystem,
private readonly JsonDecoderInterface $jsonDecoder
) {
$this->settingsService = $settingsService;
$this->filesystem = $filesystem;
$this->jsonDecoder = $jsonDecoder;
}

/**
Expand Down
8 changes: 3 additions & 5 deletions Classes/Integration/FixedIdGenerator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,9 @@

final class FixedIdGenerator implements IdGeneratorInterface
{
private string $id;

public function __construct(string $id)
{
$this->id = $id;
public function __construct(
private readonly string $id
) {
}

public function generate(): string
Expand Down
12 changes: 4 additions & 8 deletions Classes/Integration/PackageFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,10 @@

final class PackageFactory implements PackageFactoryInterface
{
private SettingsServiceInterface $settingsService;

private FilesystemInterface $filesystem;

public function __construct(SettingsServiceInterface $settingsService, FilesystemInterface $filesystem)
{
$this->settingsService = $settingsService;
$this->filesystem = $filesystem;
public function __construct(
private readonly SettingsServiceInterface $settingsService,
private readonly FilesystemInterface $filesystem
) {
}

public function getPackage(string $package): JsonPackage
Expand Down
8 changes: 3 additions & 5 deletions Classes/Integration/PageRendererHooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,9 @@ final class PageRendererHooks
*/
private const PART_FOOTER = 2;

private TagRendererInterface $tagRenderer;

public function __construct(TagRendererInterface $tagRenderer)
{
$this->tagRenderer = $tagRenderer;
public function __construct(
private readonly TagRendererInterface $tagRenderer
) {
}

public function renderPreProcess(array $params, PageRenderer $pageRenderer): void
Expand Down
8 changes: 3 additions & 5 deletions Classes/Integration/SettingsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,9 @@ final class SettingsService implements SettingsServiceInterface
{
private ?array $settings = null;

private ConfigurationManagerInterface $configurationManager;

public function __construct(ConfigurationManagerInterface $configurationManager)
{
$this->configurationManager = $configurationManager;
public function __construct(
private readonly ConfigurationManagerInterface $configurationManager
) {
}

public function getSettings(): array
Expand Down
38 changes: 38 additions & 0 deletions Classes/Integration/TypoScriptFrontendControllerEventListener.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

declare(strict_types=1);

/*
* This file is part of the "typo3_encore" Extension for TYPO3 CMS.
*
* For the full copyright and license information, please read the
* LICENSE.txt file that was distributed with this source code.
*/

namespace Ssch\Typo3Encore\Integration;

use TYPO3\CMS\Frontend\Event\AfterCacheableContentIsGeneratedEvent;

final class TypoScriptFrontendControllerEventListener
{
public function __construct(
private readonly AssetRegistryInterface $assetRegistry,
private readonly SettingsServiceInterface $settingsService
) {
}

public function __invoke(AfterCacheableContentIsGeneratedEvent $event): void
{
$registeredFiles = $this->assetRegistry->getRegisteredFiles();
if ($registeredFiles === []) {
return;
}

$event->getController()
->config['encore_asset_registry'] = [
'registered_files' => $this->assetRegistry->getRegisteredFiles(),
'default_attributes' => $this->assetRegistry->getDefaultAttributes(),
'settings' => $this->settingsService->getSettings(),
];
}
}
Loading