diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 945df14..7e5cc62 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -17,7 +17,7 @@ jobs: strategy: fail-fast: false matrix: - php: [7.4, 8.0] + php: [7.4, 8.0, 8.1, 8.2, 8.3] env: ESB_CONSOLE_PORT: 8080 @@ -68,7 +68,7 @@ jobs: run: composer install --no-interaction - name: Composer Require Checker - run: composer-require-checker + run: composer-require-checker --config-file=composer-require-checker.json - name: Run Easy Coding Standard run: vendor/bin/ecs check @@ -84,7 +84,10 @@ jobs: run: sudo bash ./upload-textfiles "/var/log/elasticsearch/*.log" - name: Install roave/backward-compatibility-check. - run: composer require -W --dev roave/backward-compatibility-check --no-plugins + run: | + # Install BC check tool in separate directory to avoid dependency conflicts + mkdir -p test-tools/bc-check + composer require --working-dir="test-tools/bc-check" roave/backward-compatibility-check --no-plugins - name: Run roave/backward-compatibility-check. - run: vendor/bin/roave-backward-compatibility-check --format=github-actions + run: test-tools/bc-check/vendor/bin/roave-backward-compatibility-check --format=github-actions diff --git a/Dockerfile b/Dockerfile index c3ab0fa..1183000 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -ARG PHP_VERSION=8.0 +ARG PHP_VERSION=8.3 FROM php:${PHP_VERSION}-cli-alpine diff --git a/README.md b/README.md index 4f92fcb..9425545 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Webgriffe ESB is designed to use a single binary which is used as the main entry Requirements ------------ -* PHP 7.2, 7.3 or 7.4 +* PHP 7.4, 8.0, 8.1, 8.2, 8.3 * Beanstalk * Elasticsearch 7.* diff --git a/composer-require-checker.json b/composer-require-checker.json index 6d5bb51..7dfd157 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -1,3 +1,9 @@ { - "scan-files" : ["bin/esb"] + "scan-files" : ["bin/esb"], + "symbol-whitelist": [ + "null", "true", "false", "static", "self", "parent", + "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", "mixed", "never", + + "mb_convert_encoding" + ] } diff --git a/composer.json b/composer.json index 7e7334e..4a10cf7 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ } ], "require": { - "php": "~7.4.0|~8.0.0", + "php": "~7.4.0|~8.0.0|~8.1.0|~8.2.0|~8.3.0", "ext-pcntl": "*", "ext-json": "*", "symfony/dependency-injection": "^4.3", @@ -33,11 +33,14 @@ "symfony/property-info": "^4.3", "doctrine/annotations": "^1.8", "ramsey/uuid": "^3.8", - "webgriffe/amp-elasticsearch": "^2.0", + "webgriffe/amp-elasticsearch": "dev-php-8.3-support#6b26a581fc99c6aba5b06fc2eabfe2dec98578c9 as 2.1", "pagerfanta/pagerfanta": "^2.4", "symfony/deprecation-contracts": "^2.1", "amphp/http-server-form-parser": "^1.1" }, + "suggest": { + "ext-mbstring": "*" + }, "autoload": { "psr-4": { "Webgriffe\\Esb\\": ["src/"] @@ -65,5 +68,11 @@ "phpstan": "vendor/bin/phpstan analyse --no-progress -l max -c phpstan.neon src/", "phpunit": "vendor/bin/phpunit", "tests": ["@ecs", "@phpstan", "@phpunit"] + }, + "repositories": { + "amp-elasticsearch-from-src": { + "type": "vcs", + "url": "git@github.com:youwe-petervanderwal/amp-elasticsearch.git" + } } } diff --git a/src/NonUtf8Cleaner.php b/src/NonUtf8Cleaner.php index 88a9b1b..b1e296d 100644 --- a/src/NonUtf8Cleaner.php +++ b/src/NonUtf8Cleaner.php @@ -4,8 +4,6 @@ namespace Webgriffe\Esb; -use Monolog\Utils; - /** * @internal */ @@ -17,13 +15,34 @@ class NonUtf8Cleaner */ public static function clean(array $data): array { - array_walk_recursive($data, [Utils::class, 'detectAndCleanUtf8']); + array_walk_recursive($data, [__CLASS__, 'cleanString']); return $data; } public static function cleanString(string $data): string { - Utils::detectAndCleanUtf8($data); - return $data; + // Implementation borrowed from Monolog\Utils::detectAndCleanUtf8() which is no longer a public method as of version 2 + + if (preg_match('//u', $data)) { + return $data; + } + + $data = preg_replace_callback( + '/[\x80-\xFF]+/', + function ($m) { + return function_exists('mb_convert_encoding') ? mb_convert_encoding($m[0], 'UTF-8', 'ISO-8859-1') : utf8_encode($m[0]); + }, + $data + ); + + if (!is_string($data)) { + throw new \RuntimeException('Failed to preg_replace_callback: ' . preg_last_error()); + } + + return str_replace( + ['¤', '¦', '¨', '´', '¸', '¼', '½', '¾'], + ['€', 'Š', 'š', 'Ž', 'ž', 'Œ', 'œ', 'Ÿ'], + $data + ); } }