Skip to content

Removes some code for PHP versions we no longer support. #39202

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

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
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2024 Adobe
* All Rights Reserved.
*/
namespace Magento\Framework\Webapi\Rest\Request\Deserializer;

Expand Down Expand Up @@ -72,19 +72,11 @@ public function deserialize($xmlRequestBody)
sprintf('"%s" data type is invalid. String is expected.', gettype($xmlRequestBody))
);
}
/** Disable external entity loading to prevent possible vulnerability */
if (version_compare(PHP_VERSION, '8.0') < 0) {
// this function no longer has an effect in PHP 8.0, but it's required in earlier versions
$previousLoaderState = libxml_disable_entity_loader(true);
}

set_error_handler([$this, 'handleErrors']);
$xmlParser = $this->parserFactory->create();
$xmlParser->loadXML($xmlRequestBody);

restore_error_handler();
if (isset($previousLoaderState)) {
libxml_disable_entity_loader($previousLoaderState);
}

/** Process errors during XML parsing. */
if ($this->_errorMessage !== null) {
Expand Down
14 changes: 2 additions & 12 deletions lib/internal/Magento/Framework/Xml/Security.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2024 Adobe
* All Rights Reserved.
*/

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

$document = new DOMDocument();

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

/**
Expand Down Expand Up @@ -92,11 +87,6 @@ function ($errno, $errstr) {
}
}
restore_error_handler();
// Entity load to previous setting
if (isset($loadEntities)) {
// phpcs:ignore
libxml_disable_entity_loader($loadEntities);
}
libxml_use_internal_errors($useInternalXmlErrors);

if (!$result) {
Expand Down
51 changes: 2 additions & 49 deletions setup/src/Magento/Setup/Model/PhpReadinessCheck.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2024 Adobe
* All Rights Reserved.
*/
namespace Magento\Setup\Model;

Expand Down Expand Up @@ -102,7 +102,6 @@ public function checkPhpSettings()

$settings = array_merge(
$this->checkXDebugNestedLevel(),
$this->checkPopulateRawPostSetting(),
$this->checkFunctionsExistence()
);

Expand Down Expand Up @@ -270,52 +269,6 @@ private function checkXDebugNestedLevel()
return $data;
}

/**
* Checks if PHP version >= 5.6.0 and always_populate_raw_post_data is set to -1
*
* Beginning PHP 7.0, support for 'always_populate_raw_post_data' is going to removed.
* And beginning PHP 5.6, a deprecated message is displayed if 'always_populate_raw_post_data'
* is set to a value other than -1.
*
* @return array
*/
private function checkPopulateRawPostSetting()
{
// HHVM and PHP 7does not support 'always_populate_raw_post_data' to be set to -1
if (version_compare(PHP_VERSION, '7.0.0-beta') >= 0 || defined('HHVM_VERSION')) {
return [];
}

$data = [];
$error = false;
$iniSetting = (int)ini_get('always_populate_raw_post_data');

$checkVersionConstraint = $this->versionParser->parseConstraints('~5.6.0');
$normalizedPhpVersion = $this->getNormalizedCurrentPhpVersion(PHP_VERSION);
$currentVersion = $this->versionParser->parseConstraints($normalizedPhpVersion);
if ($checkVersionConstraint->matches($currentVersion) && $iniSetting !== -1) {
$error = true;
}

$message = sprintf(
'Your PHP Version is %s, but always_populate_raw_post_data = %d.
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
This will stop the installer from running.
Please open your php.ini file and set always_populate_raw_post_data to -1.
If you need more help please call your hosting provider.',
PHP_VERSION,
(int)ini_get('always_populate_raw_post_data')
);

$data['always_populate_raw_post_data'] = [
'message' => $message,
'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
'error' => $error
];

return $data;
}

/**
* Check whether all special functions exists
*
Expand Down
64 changes: 2 additions & 62 deletions setup/src/Magento/Setup/Test/Unit/Model/PhpReadinessCheckTest.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
* Copyright 2024 Adobe
* All Rights Reserved.
*/
declare(strict_types=1);

Expand Down Expand Up @@ -245,14 +245,6 @@ public function testCheckPhpSettings(): void
50
);

$rawPostMessage = sprintf(
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
This will stop the installer from running.
Please open your php.ini file and set always_populate_raw_post_data to -1.
If you need more help please call your hosting provider.',
PHP_VERSION
);
$expected = [
'responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS,
'data' => [
Expand All @@ -267,14 +259,6 @@ public function testCheckPhpSettings(): void
]
]
];
if (!$this->isPhp7OrHhvm()) {
$this->setUpNoPrettyVersionParser();
$expected['data']['always_populate_raw_post_data'] = [
'message' => $rawPostMessage,
'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
'error' => false
];
}
$this->assertEquals($expected, $this->phpReadinessCheck->checkPhpSettings());
}

Expand All @@ -293,14 +277,6 @@ public function testCheckPhpSettingsFailed(): void
200
);

$rawPostMessage = sprintf(
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
This will stop the installer from running.
Please open your php.ini file and set always_populate_raw_post_data to -1.
If you need more help please call your hosting provider.',
PHP_VERSION
);
$expected = [
'responseType' => ResponseTypeInterface::RESPONSE_TYPE_ERROR,
'data' => [
Expand All @@ -315,14 +291,6 @@ public function testCheckPhpSettingsFailed(): void
]
]
];
if (!$this->isPhp7OrHhvm()) {
$this->setUpNoPrettyVersionParser();
$expected['data']['always_populate_raw_post_data'] = [
'message' => $rawPostMessage,
'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
'error' => false
];
}
$this->assertEquals($expected, $this->phpReadinessCheck->checkPhpSettings());
}

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

$rawPostMessage = sprintf(
'Your PHP Version is %s, but always_populate_raw_post_data = -1.
$HTTP_RAW_POST_DATA is deprecated from PHP 5.6 onwards and will be removed in PHP 7.0.
This will stop the installer from running.
Please open your php.ini file and set always_populate_raw_post_data to -1.
If you need more help please call your hosting provider.',
PHP_VERSION
);
$expected = [
'responseType' => ResponseTypeInterface::RESPONSE_TYPE_SUCCESS,
'data' => []
];
if (!$this->isPhp7OrHhvm()) {
$this->setUpNoPrettyVersionParser();
$expected['data'] = [
'always_populate_raw_post_data' => [
'message' => $rawPostMessage,
'helpUrl' => 'http://php.net/manual/en/ini.core.php#ini.always-populate-settings-data',
'error' => false
]
];
}

$expected['data']['missed_function_imagecreatefromjpeg'] = [
'message' => 'You must have installed GD library with --with-jpeg-dir=DIR option.',
Expand Down Expand Up @@ -453,14 +403,6 @@ public function testCheckPhpExtensionsFailed(): void
];
$this->assertEquals($expected, $this->phpReadinessCheck->checkPhpExtensions());
}

/**
* @return bool
*/
protected function isPhp7OrHhvm(): bool
{
return version_compare(PHP_VERSION, '7.0.0-beta') >= 0 || defined('HHVM_VERSION');
}
}

namespace Magento\Setup\Model;
Expand All @@ -473,8 +415,6 @@ function ini_get($param)
{
if ($param === 'xdebug.max_nesting_level') {
return 100;
} elseif ($param === 'always_populate_raw_post_data') {
return -1;
} elseif ($param === 'memory_limit') {
return '512M';
}
Expand Down