Skip to content

Commit 8cb04e3

Browse files
committed
Merge remote-tracking branch '39202/cleanup-old-php-versions-code' into novcommpr-2
2 parents 6acfd6a + 6fb5c6f commit 8cb04e3

File tree

4 files changed

+9
-134
lines changed

4 files changed

+9
-134
lines changed

lib/internal/Magento/Framework/Webapi/Rest/Request/Deserializer/Xml.php

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Framework\Webapi\Rest\Request\Deserializer;
77

@@ -72,19 +72,11 @@ public function deserialize($xmlRequestBody)
7272
sprintf('"%s" data type is invalid. String is expected.', gettype($xmlRequestBody))
7373
);
7474
}
75-
/** Disable external entity loading to prevent possible vulnerability */
76-
if (version_compare(PHP_VERSION, '8.0') < 0) {
77-
// this function no longer has an effect in PHP 8.0, but it's required in earlier versions
78-
$previousLoaderState = libxml_disable_entity_loader(true);
79-
}
75+
8076
set_error_handler([$this, 'handleErrors']);
8177
$xmlParser = $this->parserFactory->create();
8278
$xmlParser->loadXML($xmlRequestBody);
83-
8479
restore_error_handler();
85-
if (isset($previousLoaderState)) {
86-
libxml_disable_entity_loader($previousLoaderState);
87-
}
8880

8981
/** Process errors during XML parsing. */
9082
if ($this->_errorMessage !== null) {

lib/internal/Magento/Framework/Xml/Security.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66

77
namespace Magento\Framework\Xml;
@@ -58,11 +58,6 @@ public function scan($xmlContent)
5858

5959
$document = new DOMDocument();
6060

61-
if (version_compare(PHP_VERSION, '8.0') < 0) {
62-
// this function no longer has an effect in PHP 8.0, but it's required in earlier versions
63-
// phpcs:ignore
64-
$loadEntities = libxml_disable_entity_loader(true);
65-
}
6661
$useInternalXmlErrors = libxml_use_internal_errors(true);
6762

6863
/**
@@ -92,11 +87,6 @@ function ($errno, $errstr) {
9287
}
9388
}
9489
restore_error_handler();
95-
// Entity load to previous setting
96-
if (isset($loadEntities)) {
97-
// phpcs:ignore
98-
libxml_disable_entity_loader($loadEntities);
99-
}
10090
libxml_use_internal_errors($useInternalXmlErrors);
10191

10292
if (!$result) {

setup/src/Magento/Setup/Model/PhpReadinessCheck.php

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\Setup\Model;
77

@@ -102,7 +102,6 @@ public function checkPhpSettings()
102102

103103
$settings = array_merge(
104104
$this->checkXDebugNestedLevel(),
105-
$this->checkPopulateRawPostSetting(),
106105
$this->checkFunctionsExistence()
107106
);
108107

@@ -270,52 +269,6 @@ private function checkXDebugNestedLevel()
270269
return $data;
271270
}
272271

273-
/**
274-
* Checks if PHP version >= 5.6.0 and always_populate_raw_post_data is set to -1
275-
*
276-
* Beginning PHP 7.0, support for 'always_populate_raw_post_data' is going to removed.
277-
* And beginning PHP 5.6, a deprecated message is displayed if 'always_populate_raw_post_data'
278-
* is set to a value other than -1.
279-
*
280-
* @return array
281-
*/
282-
private function checkPopulateRawPostSetting()
283-
{
284-
// HHVM and PHP 7does not support 'always_populate_raw_post_data' to be set to -1
285-
if (version_compare(PHP_VERSION, '7.0.0-beta') >= 0 || defined('HHVM_VERSION')) {
286-
return [];
287-
}
288-
289-
$data = [];
290-
$error = false;
291-
$iniSetting = (int)ini_get('always_populate_raw_post_data');
292-
293-
$checkVersionConstraint = $this->versionParser->parseConstraints('~5.6.0');
294-
$normalizedPhpVersion = $this->getNormalizedCurrentPhpVersion(PHP_VERSION);
295-
$currentVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
296-
if ($checkVersionConstraint->matches($currentVersion) && $iniSetting !== -1) {
297-
$error = true;
298-
}
299-
300-
$message = sprintf(
301-
'Your PHP Version is %s, but always_populate_raw_post_data = %d.
302-
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
303-
This will stop the installer from running.
304-
Please open your php.ini file and set always_populate_raw_post_data to -1.
305-
If you need more help please call your hosting provider.',
306-
PHP_VERSION,
307-
(int)ini_get('always_populate_raw_post_data')
308-
);
309-
310-
$data['always_populate_raw_post_data'] = [
311-
'message' => $message,
312-
'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
313-
'error' => $error
314-
];
315-
316-
return $data;
317-
}
318-
319272
/**
320273
* Check whether all special functions exists
321274
*

setup/src/Magento/Setup/Test/Unit/Model/PhpReadinessCheckTest.php

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2024 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -245,14 +245,6 @@ public function testCheckPhpSettings(): void
245245
50
246246
);
247247

248-
$rawPostMessage = sprintf(
249-
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
250-
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
251-
This will stop the installer from running.
252-
Please open your php.ini file and set always_populate_raw_post_data to -1.
253-
If you need more help please call your hosting provider.',
254-
PHP_VERSION
255-
);
256248
$expected = [
257249
'responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS,
258250
'data' => [
@@ -267,14 +259,6 @@ public function testCheckPhpSettings(): void
267259
]
268260
]
269261
];
270-
if (!$this->isPhp7OrHhvm()) {
271-
$this->setUpNoPrettyVersionParser();
272-
$expected['data']['always_populate_raw_post_data'] = [
273-
'message' => $rawPostMessage,
274-
'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
275-
'error' => false
276-
];
277-
}
278262
$this->assertEquals($expected, $this->phpReadinessCheck->checkPhpSettings());
279263
}
280264

@@ -293,14 +277,6 @@ public function testCheckPhpSettingsFailed(): void
293277
200
294278
);
295279

296-
$rawPostMessage = sprintf(
297-
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
298-
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
299-
This will stop the installer from running.
300-
Please open your php.ini file and set always_populate_raw_post_data to -1.
301-
If you need more help please call your hosting provider.',
302-
PHP_VERSION
303-
);
304280
$expected = [
305281
'responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR,
306282
'data' => [
@@ -315,14 +291,6 @@ public function testCheckPhpSettingsFailed(): void
315291
]
316292
]
317293
];
318-
if (!$this->isPhp7OrHhvm()) {
319-
$this->setUpNoPrettyVersionParser();
320-
$expected['data']['always_populate_raw_post_data'] = [
321-
'message' => $rawPostMessage,
322-
'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
323-
'error' => false
324-
];
325-
}
326294
$this->assertEquals($expected, $this->phpReadinessCheck->checkPhpSettings());
327295
}
328296

@@ -333,28 +301,10 @@ public function testCheckPhpSettingsNoXDebug(): void
333301
{
334302
$this->phpInfo->expects($this->once())->method('getCurrent')->willReturn([]);
335303

336-
$rawPostMessage = sprintf(
337-
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
338-
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
339-
This will stop the installer from running.
340-
Please open your php.ini file and set always_populate_raw_post_data to -1.
341-
If you need more help please call your hosting provider.',
342-
PHP_VERSION
343-
);
344304
$expected = [
345305
'responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS,
346306
'data' => []
347307
];
348-
if (!$this->isPhp7OrHhvm()) {
349-
$this->setUpNoPrettyVersionParser();
350-
$expected['data'] = [
351-
'always_populate_raw_post_data' => [
352-
'message' => $rawPostMessage,
353-
'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
354-
'error' => false
355-
]
356-
];
357-
}
358308

359309
$expected['data']['missed_function_imagecreatefromjpeg'] = [
360310
'message' => 'You must have installed GD library with --with-jpeg-dir=DIR option.',
@@ -453,14 +403,6 @@ public function testCheckPhpExtensionsFailed(): void
453403
];
454404
$this->assertEquals($expected, $this->phpReadinessCheck->checkPhpExtensions());
455405
}
456-
457-
/**
458-
* @return bool
459-
*/
460-
protected function isPhp7OrHhvm(): bool
461-
{
462-
return version_compare(PHP_VERSION, '7.0.0-beta') >= 0 || defined('HHVM_VERSION');
463-
}
464406
}
465407

466408
namespace Magento\Setup\Model;
@@ -473,8 +415,6 @@ function ini_get($param)
473415
{
474416
if ($param === 'xdebug.max_nesting_level') {
475417
return 100;
476-
} elseif ($param === 'always_populate_raw_post_data') {
477-
return -1;
478418
} elseif ($param === 'memory_limit') {
479419
return '512M';
480420
}

0 commit comments

Comments
 (0)