-
Notifications
You must be signed in to change notification settings - Fork 653
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TASK] Avoid last usage of GU::_GPmerged() and deprecate
After years of refactoring, TYPO3 core finally removes a last usage of GeneralUtility::_GPmerged() which is an anti-pattern method, since it accesses $_GET and $_POST instead of retrieving things from PSR-7 ServerRequestInterface $request. Resolves: #99615 Releases: main Change-Id: I3cb6f3a0cee0a7654dce331dc40ab51f2efe41f4 Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/77477 Tested-by: Stefan Bürk <stefan@buerk.tech> Reviewed-by: Benni Mack <benni@typo3.org> Tested-by: Christian Kuhn <lolli@schwarzbu.ch> Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch> Tested-by: core-ci <typo3@b13.com> Tested-by: Benni Mack <benni@typo3.org> Reviewed-by: Stefan Bürk <stefan@buerk.tech>
- Loading branch information
Showing
6 changed files
with
152 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
.../core/Documentation/Changelog/12.2/Deprecation-99615-GeneralUtilityGPMerged.rst
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
.. include:: /Includes.rst.txt | ||
|
||
.. _deprecation-99615-1674056024: | ||
|
||
================================================= | ||
Deprecation: #99615 - GeneralUtility::_GPmerged() | ||
================================================= | ||
|
||
See :issue:`99615` | ||
|
||
Description | ||
=========== | ||
|
||
Method :php:`\TYPO3\CMS\Backend\Utility\GeneralUtility::_GPmerged()` has | ||
been marked as deprecated and should not be used any longer. | ||
|
||
Modern code should access GET and POST data from the PSR-7 :php:`ServerRequestInterface`, | ||
and should avoid accessing superglobals :php:`$_GET` and :php:`$_POST` | ||
directly. This helps creating controller classes with a clean architecture. Some | ||
:php:`GeneralUtility` related helper methods like :php:`_GPmerged()` violate this, | ||
using them is considered a technical debt. They are being phased out. | ||
|
||
|
||
Impact | ||
====== | ||
|
||
Calling the method will raise a deprecation level log error and will | ||
stop working with TYPO3 v13. | ||
|
||
|
||
Affected installations | ||
====================== | ||
|
||
Instances with extensions using :php:`GeneralUtility::_GPmerged()` are affected. | ||
The extension scanner will find usages with a strong match. | ||
|
||
|
||
Migration | ||
========= | ||
|
||
:php:`GeneralUtility::_GPmerged()` is a helper method that retrieves | ||
request parameters and returns the value, while POST parameters take | ||
precedence over GET parameters, if both exist. | ||
|
||
The same result can be achieved by retrieving arguments from the request object. | ||
An instance of the PSR-7 :php:`ServerRequestInterface` is hand over to | ||
controllers by TYPO3 core PSR-15 :php:`RequestHandlerInterface` and Middleware | ||
implementations, and is available in various related scopes like the Frontend | ||
:php:`ContentObjectRenderer`. | ||
|
||
Typical code: | ||
|
||
.. code-block:: php | ||
// Before | ||
$getMergedWithPost = GeneralUtility::_GPmerged('tx_scheduler'); | ||
// After | ||
$getMergedWithPost = $request->getQueryString()['tx_scheduler']; | ||
ArrayUtility::mergeRecursiveWithOverrule($getMergedWithPost, $request->getParsedBody()['tx_scheduler']); | ||
.. index:: Backend, PHP-API, FullyScanned, ext:backend |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
typo3/sysext/core/Tests/UnitDeprecated/Utility/GeneralUtilityTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/* | ||
* This file is part of the TYPO3 CMS project. | ||
* | ||
* It is free software; you can redistribute it and/or modify it under | ||
* the terms of the GNU General Public License, either version 2 | ||
* of the License, or any later version. | ||
* | ||
* For the full copyright and license information, please read the | ||
* LICENSE.txt file that was distributed with this source code. | ||
* | ||
* The TYPO3 project - inspiring people to share! | ||
*/ | ||
|
||
namespace TYPO3\CMS\Core\Tests\UnitDeprecated\Utility; | ||
|
||
use TYPO3\CMS\Core\Utility\GeneralUtility; | ||
use TYPO3\TestingFramework\Core\Unit\UnitTestCase; | ||
|
||
class GeneralUtilityTest extends UnitTestCase | ||
{ | ||
/** | ||
* @test | ||
* @dataProvider gpMergedDataProvider | ||
*/ | ||
public function gpMergedWillMergeArraysFromGetAndPost($get, $post, $expected): void | ||
{ | ||
$_POST = $post; | ||
$_GET = $get; | ||
self::assertEquals($expected, GeneralUtility::_GPmerged('cake')); | ||
} | ||
|
||
/** | ||
* Data provider for gpMergedWillMergeArraysFromGetAndPost | ||
*/ | ||
public function gpMergedDataProvider(): array | ||
{ | ||
$fullDataArray = ['cake' => ['a' => 'is a', 'b' => 'lie']]; | ||
$postPartData = ['cake' => ['b' => 'lie']]; | ||
$getPartData = ['cake' => ['a' => 'is a']]; | ||
$getPartDataModified = ['cake' => ['a' => 'is not a']]; | ||
return [ | ||
'Key doesn\' exist' => [['foo'], ['bar'], []], | ||
'No POST data' => [$fullDataArray, [], $fullDataArray['cake']], | ||
'No GET data' => [[], $fullDataArray, $fullDataArray['cake']], | ||
'POST and GET are merged' => [$getPartData, $postPartData, $fullDataArray['cake']], | ||
'POST is preferred over GET' => [$getPartDataModified, $fullDataArray, $fullDataArray['cake']], | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters