Skip to content

Commit

Permalink
Merge pull request #25 from AOEpeople/feature/typo3v12
Browse files Browse the repository at this point in the history
Feature/typo3v12
  • Loading branch information
soda-2005 authored Jul 31, 2024
2 parents bbc84ed + 34197fe commit 3ee6138
Show file tree
Hide file tree
Showing 47 changed files with 149 additions and 341 deletions.
36 changes: 2 additions & 34 deletions .code-quality/phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,6 @@ parameters:
message: "#^Comparison operation \"\\<\" between int\\<1, max\\> and 1 is always false\\.$#"
count: 1
path: ../Classes/System/Configuration/TypoScriptConfiguration.php
-
message: "#^Result of \\|\\| 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 @@ -32,31 +20,11 @@ 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 variable in a `\\$site\\-\\>getBase\\(\\)\\-\\>\\.\\.\\.\\(\\)` 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$#"
message: "#^Unable to resolve the template type T in call to method static method TYPO3\\\\CMS\\\\Core\\\\Utility\\\\GeneralUtility\\:\\:makeInstance\\(\\)$#"
count: 1
path: ../Classes/Api/Url.php
path: ../Classes/System/Factory/AbstractDeclarationBasedFactory.php
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
15 changes: 1 addition & 14 deletions .code-quality/rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,27 +12,21 @@
use Rector\CodingStyle\Rector\Encapsed\EncapsedStringsToSprintfRector;
use Rector\CodingStyle\Rector\Encapsed\WrapEncapsedVariableInCurlyBracesRector;
use Rector\CodingStyle\Rector\FuncCall\ConsistentPregDelimiterRector;
use Rector\CodingStyle\Rector\PostInc\PostIncDecToPreIncDecRector;
use Rector\CodingStyle\Rector\Property\AddFalseDefaultToBoolPropertyRector;
use Rector\Config\RectorConfig;
use Rector\Core\Configuration\Option;
use Rector\DeadCode\Rector\Cast\RecastingRemovalRector;
use Rector\DeadCode\Rector\ClassMethod\RemoveDelegatingParentCallRector;
use Rector\DeadCode\Rector\Property\RemoveUnusedPrivatePropertyRector;
use Rector\Defluent\Rector\Return_\ReturnFluentChainMethodCallToNormalMethodCallRector;
use Rector\EarlyReturn\Rector\If_\ChangeAndIfToEarlyReturnRector;
use Rector\EarlyReturn\Rector\If_\ChangeOrIfReturnToEarlyReturnRector;
use Rector\EarlyReturn\Rector\Return_\ReturnBinaryAndToEarlyReturnRector;
use Rector\Naming\Rector\ClassMethod\RenameVariableToMatchNewTypeRector;
use Rector\Naming\Rector\Foreach_\RenameForeachValueVariableToMatchMethodCallReturnTypeRector;
use Rector\Naming\Rector\Property\MakeBoolPropertyRespectIsHasWasMethodNamingRector;
use Rector\Php71\Rector\FuncCall\RemoveExtraParametersRector;
use Rector\Php74\Rector\LNumber\AddLiteralSeparatorToNumberRector;
use Rector\Php74\Rector\Property\TypedPropertyRector;
use Rector\Php80\Rector\Class_\ClassPropertyAssignToConstructorPromotionRector;
use Rector\PHPUnit\Set\PHPUnitSetList;
use Rector\Privatization\Rector\Class_\ChangeReadOnlyVariableWithDefaultValueToConstantRector;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenRector;
use Rector\Privatization\Rector\Class_\RepeatedLiteralToClassConstantRector;
use Rector\Privatization\Rector\Property\ChangeReadOnlyPropertyWithDefaultValueToConstantRector;
use Rector\Privatization\Rector\Property\PrivatizeLocalPropertyToPrivatePropertyRector;
Expand All @@ -58,7 +52,6 @@
SetList::EARLY_RETURN,
SetList::PRIVATIZATION,
SetList::TYPE_DECLARATION,
SetList::PHP_74,
SetList::PHP_80,
SetList::PHP_81,
SetList::PHP_82,
Expand All @@ -70,14 +63,8 @@
])
->withSkip([
RecastingRemovalRector::class,
PostIncDecToPreIncDecRector::class,
FinalizeClassesWithoutChildrenRector::class,
ChangeAndIfToEarlyReturnRector::class,
IssetOnPropertyObjectToPropertyExistsRector::class,
FlipTypeControlToUseExclusiveTypeRector::class,
RenameVariableToMatchNewTypeRector::class,
AddLiteralSeparatorToNumberRector::class,
RenameForeachValueVariableToMatchMethodCallReturnTypeRector::class,
ClassPropertyAssignToConstructorPromotionRector::class,
ArgumentAdderRector::class,
RemoveExtraParametersRector::class,
Expand All @@ -87,4 +74,4 @@
])
->withAutoloadPaths([__DIR__ . '/../Classes'])
->withCache('.cache/rector/default')
->withImportNames(false);
->withImportNames(false);
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
8 changes: 7 additions & 1 deletion Classes/Content/Scraper/Html/Image.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,17 @@ public function scrape(string $content): ?Collection
{
return $this->getAssets('img', 'src', $content)
->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',
'type' => 'image/gif',
]));
}
}
2 changes: 1 addition & 1 deletion Classes/Domain/Model/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function replaceAssets(): void
$distributionAlgorithmKey = '';
try {
$distributionAlgorithmKey = $this->configurationProvider->getDistributionAlgorithmKey();
} catch (Exception $exception) {
} catch (Exception) {
}

$distributionAlgorithm = $this->distributionAlgorithmFactory->buildDistributionAlgorithmFromKey($distributionAlgorithmKey);
Expand Down
23 changes: 7 additions & 16 deletions Classes/Domain/Model/Server.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,12 @@ private function getProtocolPrefix(): string
$protocol = $this->getRequestProtocol();
}

switch ($protocol) {
case self::PROTOCOL_MARKER:
$protocolPrefix = $this->protocolMarker;
break;
case self::PROTOCOL_WILDCARD:
$protocolPrefix = '//';
break;
case self::PROTOCOL_HTTP:
$protocolPrefix = 'http://';
break;
case self::PROTOCOL_HTTPS:
$protocolPrefix = 'https://';
break;
}

return $protocolPrefix;
return match ($protocol) {
self::PROTOCOL_MARKER => $this->protocolMarker,
self::PROTOCOL_WILDCARD => '//',
self::PROTOCOL_HTTP => 'http://',
self::PROTOCOL_HTTPS => 'https://',
default => $protocolPrefix,
};
}
}
10 changes: 2 additions & 8 deletions Classes/Domain/Model/Server/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,12 @@ public function injectConfigurationProvider(Provider $configurationProvider): vo
{
try {
$this->protocolMarker = $configurationProvider->getServerProtocolMarker();
} catch (Exception $exception) {
} catch (Exception) {
$this->protocolMarker = '';
}
}

/**
* @param string $identifier
* @param string $domain
* @param string $protocol
* @return \Aoe\Asdis\Domain\Model\Server
*/
public function createServer($identifier, $domain, $protocol)
public function createServer(string $identifier, string $domain, string $protocol): Server
{
$server = GeneralUtility::makeInstance(Server::class);
$server->setIdentifier($identifier);
Expand Down
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
23 changes: 20 additions & 3 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 All @@ -34,7 +36,7 @@ public function getSetting($key, $validateType = '', $hasSubkeys = false)
}

$parts = explode('.', $key);
if (!is_array($parts) || count($parts) < 1) {
if (count($parts) < 1) {
throw new TypoScriptSettingNotExists($key, 1_372_050_700_894);
}

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
Loading

0 comments on commit 3ee6138

Please sign in to comment.