Skip to content

Commit

Permalink
[REF][PHP8.1] Apply patches and a wrapper for Guzzle v6 to make it ru…
Browse files Browse the repository at this point in the history
…n in php8.1
  • Loading branch information
seamuslee001 committed Jul 29, 2022
1 parent 8449e89 commit 9584d5d
Show file tree
Hide file tree
Showing 4 changed files with 63 additions and 4 deletions.
11 changes: 8 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@
},
"psr-4": {
"Civi\\": [".", "Civi/", "setup/src/"]
}
},
"files": [
"guzzle_php81_shim.php"
]
},
"include-path": ["vendor/tecnickcom"],
"config": {
Expand Down Expand Up @@ -107,15 +110,17 @@
"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",
"bash tools/scripts/composer/tcpdf-cleanup.sh",
"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": {
Expand Down
2 changes: 1 addition & 1 deletion distmaker/dists/common.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
33 changes: 33 additions & 0 deletions guzzle_php81_shim.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

namespace GuzzleHttp;

if (!function_exists('\GuzzleHttp\http_build_query')) {

/**
* Generates URL-encoded query string.
*
* This shim exists to make Guzzle 6 PHP 8.1 compatible.
*
* @link https://php.net/manual/en/function.http-build-query.php
*
* @param object|array $data
* May be an array or object containing properties.
* @param string|null $numeric_prefix
* (optional) If numeric indices are used in the base array and this parameter
* is provided, it will be prepended to the numeric index for elements in
* the base array only.
* @param string|null $arg_separator [optional] <p>
* (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);
}

}
21 changes: 21 additions & 0 deletions tools/scripts/composer/guzzle-mockhandler-fix.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9584d5d

Please sign in to comment.