Files
piratepoet/mailpoet/tasks/fix-requests.php
Jan Lysý d86c59b606 Add fix script for rmccue/requests
[MAILPOET-4015]
2022-03-14 09:38:20 +01:00

57 lines
2.6 KiB
PHP

<?php
// throw exception if anything fails
set_error_handler(function ($severity, $message, $file, $line) {
throw new ErrorException($message, 0, $severity, $file, $line);
});
// Skip when requests library is missing
if (!file_exists(__DIR__ . '/../vendor/rmccue/requests/library/Requests/Cookie/Jar.php')) {
exit;
}
// Add the attribute #[\ReturnTypeWillChange] for compatibility with PHP8.1
$replacements = [
[
'file' => __DIR__ . '/../vendor/rmccue/requests/library/Requests/Cookie/Jar.php',
'find' => [
'*/' . PHP_EOL . ' public function offsetExists($key) {',
'*/' . PHP_EOL . ' public function offsetGet($key) {',
'*/' . PHP_EOL . ' public function offsetSet($key, $value) {',
'*/' . PHP_EOL . ' public function offsetUnset($key) {',
'*/' . PHP_EOL . ' public function getIterator() {',
],
'replace' => [
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function offsetExists($key) {',
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function offsetGet($key) {',
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function offsetSet($key, $value) {',
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function offsetUnset($key) {',
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function getIterator() {',
],
],
[
'file' => __DIR__ . '/../vendor/rmccue/requests/library/Requests/Utility/CaseInsensitiveDictionary.php',
'find' => [
'*/' . PHP_EOL . ' public function offsetExists($key) {',
'*/' . PHP_EOL . ' public function offsetGet($key) {',
'*/' . PHP_EOL . ' public function offsetSet($key, $value) {',
'*/' . PHP_EOL . ' public function offsetUnset($key) {',
'*/' . PHP_EOL . ' public function getIterator() {',
],
'replace' => [
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function offsetExists($key) {',
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function offsetGet($key) {',
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function offsetSet($key, $value) {',
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function offsetUnset($key) {',
'*/' . PHP_EOL . ' #[\ReturnTypeWillChange]' . PHP_EOL . ' public function getIterator() {',
],
],
];
// Apply replacements
foreach ($replacements as $singleFile) {
$data = file_get_contents($singleFile['file']);
$data = str_replace($singleFile['find'], $singleFile['replace'], $data);
file_put_contents($singleFile['file'], $data);
}