Skip to content

Commit

Permalink
chore: preparations for typo3 v12
Browse files Browse the repository at this point in the history
  • Loading branch information
Jürgen Kußmann committed Jul 31, 2024
1 parent dd96faf commit 34197fe
Show file tree
Hide file tree
Showing 20 changed files with 80 additions and 276 deletions.
24 changes: 0 additions & 24 deletions .code-quality/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,6 @@ parameters:
message: "#^Comparison operation \"\\<\" between int\\<1, max\\> and 1 is always false\\.$#"
count: 1
path: ../Classes/System/Configuration/TypoScriptConfiguration.php
-
message: "#^Call to an undefined static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:sysLog\\(\\)\\.$#"
count: 1
path: ../Classes/System/Log/Logger.php
-
message: "#^Relative file path \"tslib/class\\.tslib_fe\\.php\" is not allowed, use absolute one with __DIR__$#"
count: 4
path: ../Classes/Backend/Utility/HookUtility.php
-
message: "#^Use value object over return of values$#"
count: 2
Expand All @@ -28,26 +20,10 @@ parameters:
message: "#^Anonymous variable in a `\\$GLOBALS\\['TYPO3_REQUEST'\\]\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 1
path: ../Classes/System/Configuration/TypoScriptConfiguration.php
-
message: "#^Anonymous variables in a \"\\$GLOBALS\\['TSFE'\\]\\-\\>\\.\\.\\.\" property fetch can lead to false dead property\\. Make sure the variable type is known$#"
count: 1
path: ../Classes/System/Configuration/TypoScriptConfiguration.php
-
message: "#^Anonymous variables in a \"\\$GLOBALS\\['TSFE'\\]\\-\\>tmpl\\-\\>\\.\\.\\.\" property fetch can lead to false dead property\\. Make sure the variable type is known$#"
count: 1
path: ../Classes/System/Configuration/TypoScriptConfiguration.php
-
message: "#^Anonymous variable in a `\\$GLOBALS\\['TSFE'\\]\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 2
path: ../Classes/Typo3/Hook/ContentPostProcAll.php
-
message: "#^Anonymous variable in a `\\$this\\[\\$found\\]\\-\\>\\.\\.\\.\\(\\)` method call can lead to false dead methods\\. Make sure the variable type is known$#"
count: 3
path: ../Classes/Domain/Model/Asset/Collection.php
-
message: "#^On passing a constant, the method should have an enum type\\. See https\\://phpstan\\.org/writing\\-php\\-code/phpdoc\\-types\\#literals\\-and\\-constants$#"
count: 1
path: ../Classes/Api/Url.php
-
message: "#^Unable to resolve the template type T in call to method static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:makeInstance\\(\\)$#"
count: 1
Expand Down
5 changes: 3 additions & 2 deletions .code-quality/phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@ parameters:
paths:
- "../Classes/"

ignoreErrors:
- identifier: missingType.iterableValue
- identifier: missingType.generics
inferPrivatePropertyTypeFromConstructor: true
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false

services:
-
Expand Down
54 changes: 0 additions & 54 deletions Classes/Backend/Utility/HookUtility.php

This file was deleted.

27 changes: 27 additions & 0 deletions Classes/Bootstrap/Typo3Configurator.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

declare(strict_types=1);

namespace Aoe\Asdis\Bootstrap;

use TYPO3\CMS\Core\Context\Context;
use TYPO3\CMS\Core\Context\TypoScriptAspect;
use TYPO3\CMS\Core\Core\Event\BootCompletedEvent;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

class Typo3Configurator
{
public function forceTemplateParsingInFrontend(BootCompletedEvent $event): void
{
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '12.4.0', '>')) {
/**
* We must force templateParsing - otherwise the TypoScript (which configures this
* extension) is not available in the frontend, so we can't get the TypoScript here:
* @see \Aoe\Asdis\System\Configuration\TypoScriptConfiguration::getTypoScriptConfigurationArray
*/
$context = GeneralUtility::makeInstance(Context::class);
$context->setAspect('typoscript', GeneralUtility::makeInstance(TypoScriptAspect::class, true));
}
}
}
12 changes: 0 additions & 12 deletions Classes/Content/Scraper/Html/AbstractHtmlScraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,6 @@ public function __construct(XmlTagAttribute $xmlTagAttributeExtractor, Factory $
$this->assetFactory = $assetFactory;
}

/*
public function injectXmlTagAttributeExtractor(XmlTagAttribute $xmlTagAttributeExtractor): void
{
$this->xmlTagAttributeExtractor = $xmlTagAttributeExtractor;
}
public function injectAssetFactory(Factory $assetFactory): void
{
$this->assetFactory = $assetFactory;
}
*/

protected function getAssets(string $tagName, string $attributeName, string $content, array $requiredOtherAttributes = []): ?Collection
{
$attributes = $this->xmlTagAttributeExtractor->getAttributeFromTag(
Expand Down
9 changes: 9 additions & 0 deletions Classes/Content/Scraper/Html/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ public function scrape(string $content): ?Collection
->merge($this->getAssets('image', 'href', $content))
->merge($this->getAssets('link', 'href', $content, [
'type' => 'image/gif',
]))
->merge($this->getAssets('link', 'href', $content, [
'type' => 'image/webp',
]))
->merge($this->getAssets('link', 'href', $content, [
'type' => 'image/png',
]))
->merge($this->getAssets('link', 'href', $content, [
'type' => 'image/jpeg',
]));
}
}
9 changes: 8 additions & 1 deletion Classes/Middleware/ContentPostProcAll.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
$status = $response->getStatusCode();

try {
$this->setPageObject($GLOBALS['TSFE']);
$this->setPageObject($this->getTsfe());
$this->scrapeAndReplace();

$header['Content-Length'] = strlen($this->page->getPageObject()->content);
Expand All @@ -58,6 +58,13 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
return $response;
}

protected function getTsfe(): TypoScriptFrontendController
{
/** @var ServerRequestInterface $typo3Request */
$typo3Request = $GLOBALS['TYPO3_REQUEST'];
return $typo3Request->getAttribute('frontend.controller');
}

protected function scrapeAssets(): void
{
$this->page->scrapeAssets();
Expand Down
7 changes: 0 additions & 7 deletions Classes/System/Configuration/Provider.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,6 @@ public function __construct(TypoScriptConfiguration $typoScriptConfiguration)
$this->typoScriptConfiguration = $typoScriptConfiguration;
}

/*
public function injectTypoScriptConfiguration(TypoScriptConfiguration $typoScriptConfiguration): void
{
$this->typoScriptConfiguration = $typoScriptConfiguration;
}
*/

/**
* Tells if the assets on the current page should be replaced.
*/
Expand Down
21 changes: 19 additions & 2 deletions Classes/System/Configuration/TypoScriptConfiguration.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,11 @@
use Aoe\Asdis\System\Configuration\Exception\InvalidTypoScriptSetting;
use Aoe\Asdis\System\Configuration\Exception\SiteNotFoundException;
use Aoe\Asdis\System\Configuration\Exception\TypoScriptSettingNotExists;
use Psr\Http\Message\ServerRequestInterface;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Site\Entity\Site;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\TypoScript\FrontendTypoScript;
use TYPO3\CMS\Core\TypoScript\TemplateService;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\RootlineUtility;
Expand Down Expand Up @@ -69,10 +71,25 @@ public function getSetting($key, $validateType = '', $hasSubkeys = false)
*/
protected function getTypoScriptConfigurationArray()
{
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.5.0', '<')) {
return $GLOBALS['TSFE']->tmpl->setup['config.']['tx_asdis.'];
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '12.4.0', '>')) {
if (isset($GLOBALS['TYPO3_REQUEST']) &&
$GLOBALS['TYPO3_REQUEST'] instanceof ServerRequestInterface &&
$GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript') instanceof FrontendTypoScript) {
/**
* We can get the TypoScript in the frontend, because we force templateParsing (without
* forcing of templateParsing, we can't get the complete TypoScript in frontend) here:
* @see \Aoe\Asdis\Bootstrap\Typo3Configurator::forceTemplateParsingInFrontend
*/
$fullTypoScript = $GLOBALS['TYPO3_REQUEST']->getAttribute('frontend.typoscript')->getSetupArray();
return $fullTypoScript['config.']['tx_asdis.'];
}

return [];
}

/**
* This code is for TYPO3v11 - we can remove it, when we don't support TYPO3v11 anymore!
*/
$site = $this->getCurrentSite();

/** @var RootlineUtility $rootlineUtility */
Expand Down
17 changes: 0 additions & 17 deletions Classes/System/Log/Logger.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
use TYPO3\CMS\Core\Log\LogManager;
use TYPO3\CMS\Core\SingletonInterface;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Core\Utility\VersionNumberUtility;

/**
* System logger.
Expand All @@ -18,26 +17,10 @@ class Logger implements SingletonInterface

public function logException(string $context, Exception $e): void
{
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '9.5.0', '<')) {
$this->syslog(
'Exception occured ' . PHP_EOL .
' Code: ' . $e->getCode() . PHP_EOL .
' Message: "' . $e->getMessage() . '"' . PHP_EOL .
' Trace:' . PHP_EOL . $e->getTraceAsString(),
4
);
return;
}

$this->logger = GeneralUtility::makeInstance(LogManager::class)->getLogger(self::class);
$this->logger->error(
$context . ': ' . $e->getMessage(),
$e->getTrace()
);
}

private function syslog(string $message, int $severity): void
{
GeneralUtility::sysLog($message, 'asdis', $severity);
}
}
66 changes: 0 additions & 66 deletions Classes/Typo3/Hook/AbstractHook.php

This file was deleted.

Loading

0 comments on commit 34197fe

Please sign in to comment.