From 9584d5d567eee10cacef55bad2cdff28c8013f8c Mon Sep 17 00:00:00 2001 From: Seamus Lee Date: Fri, 29 Jul 2022 10:47:36 +1000 Subject: [PATCH] [REF][PHP8.1] Apply patches and a wrapper for Guzzle v6 to make it run in php8.1 --- composer.json | 11 +++++-- distmaker/dists/common.sh | 2 +- guzzle_php81_shim.php | 33 +++++++++++++++++++ .../composer/guzzle-mockhandler-fix.sh | 21 ++++++++++++ 4 files changed, 63 insertions(+), 4 deletions(-) create mode 100644 guzzle_php81_shim.php create mode 100755 tools/scripts/composer/guzzle-mockhandler-fix.sh diff --git a/composer.json b/composer.json index 5f95f8bebe..93b34f886d 100644 --- a/composer.json +++ b/composer.json @@ -33,7 +33,10 @@ }, "psr-4": { "Civi\\": [".", "Civi/", "setup/src/"] - } + }, + "files": [ + "guzzle_php81_shim.php" + ] }, "include-path": ["vendor/tecnickcom"], "config": { @@ -107,7 +110,8 @@ "bash tools/scripts/composer/pear-exception-fix.sh", "bash tools/scripts/composer/net-smtp-fix.sh", "bash tools/scripts/composer/pear-mail-fix.sh", - "bash tools/scripts/composer/phpword-jquery.sh" + "bash tools/scripts/composer/phpword-jquery.sh", + "bash tools/scripts/composer/guzzle-mockhandler-fix.sh" ], "post-update-cmd": [ "bash tools/scripts/composer/dompdf-cleanup.sh", @@ -115,7 +119,8 @@ "bash tools/scripts/composer/pear-exception-fix.sh", "bash tools/scripts/composer/net-smtp-fix.sh", "bash tools/scripts/composer/pear-mail-fix.sh", - "bash tools/scripts/composer/phpword-jquery.sh" + "bash tools/scripts/composer/phpword-jquery.sh", + "bash tools/scripts/composer/guzzle-mockhandler-fix.sh" ] }, "repositories": { diff --git a/distmaker/dists/common.sh b/distmaker/dists/common.sh index 99a69a757b..1f704f9bd9 100644 --- a/distmaker/dists/common.sh +++ b/distmaker/dists/common.sh @@ -82,7 +82,7 @@ function dm_install_core() { done dm_install_files "$repo" "$to" {agpl-3.0,agpl-3.0.exception,gpl,CONTRIBUTORS}.txt - dm_install_files "$repo" "$to" composer.json composer.lock package.json Civi.php README.md release-notes.md extension-compatibility.json + dm_install_files "$repo" "$to" composer.json composer.lock package.json Civi.php README.md release-notes.md extension-compatibility.json guzzle_php81_shim.php mkdir -p "$to/sql" pushd "$repo" >> /dev/null diff --git a/guzzle_php81_shim.php b/guzzle_php81_shim.php new file mode 100644 index 0000000000..1c2eae37d3 --- /dev/null +++ b/guzzle_php81_shim.php @@ -0,0 +1,33 @@ + + * (optional) arg_separator.output is used to separate arguments, unless this + * parameter is specified, and is then used. + * @param int $encoding_type + * (optional) By default, PHP_QUERY_RFC1738. + * + * @return string + * A URL-encoded string. + */ + function http_build_query($data, $numeric_prefix = '', $arg_separator = '&', $encoding_type = \PHP_QUERY_RFC1738) { + return \http_build_query($data, is_null($numeric_prefix) ? '' : $numeric_prefix, $arg_separator, $encoding_type); + } + +} diff --git a/tools/scripts/composer/guzzle-mockhandler-fix.sh b/tools/scripts/composer/guzzle-mockhandler-fix.sh new file mode 100755 index 0000000000..bb28563973 --- /dev/null +++ b/tools/scripts/composer/guzzle-mockhandler-fix.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +## Cleanup the vendor tree. The main issue here is that civi Civi is +## deployed as a module inside a CMS, so all its source-code gets published. +## Some libraries distribute admin tools and sample files which should not +## be published. +## +## This script should be idempotent -- if you rerun it several times, it +## should always produce the same post-condition. + +## Replace a line in a file +## This is a bit like 'sed -i', but dumber and more cross-platform. +function simple_replace() { + php -r 'file_put_contents($argv[1], preg_replace($argv[2], $argv[3], file_get_contents($argv[1])));' "$@" +} + + +# add in class_exists test as per CRM-8921. +if ! grep -q ':int' vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php; then + simple_replace vendor/guzzlehttp/guzzle/src/Handler/MockHandler.php '/public function count\(\)$/m' 'public function count() :int' +fi -- 2.25.1