Skip to content
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

Add PHP 8.3 support #32

Closed
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
11 changes: 7 additions & 4 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ARG PHP_VERSION=8.0
ARG PHP_VERSION=8.3

FROM php:${PHP_VERSION}-cli-alpine

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.*

Expand Down
8 changes: 7 additions & 1 deletion composer-require-checker.json
Original file line number Diff line number Diff line change
@@ -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",
Comment on lines +4 to +5
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are those core symbols whitelisted? There weren't the need to whitelist them previously...


"mb_convert_encoding"
]
}
13 changes: 11 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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": "*"
},
Comment on lines +41 to +43
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should move this to the requirements so we can remove the mb_convert_encoding symbol from the composer require checker whitelist.

"autoload": {
"psr-4": {
"Webgriffe\\Esb\\": ["src/"]
Expand Down Expand Up @@ -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": "[email protected]:youwe-petervanderwal/amp-elasticsearch.git"
}
}
}
29 changes: 24 additions & 5 deletions src/NonUtf8Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

namespace Webgriffe\Esb;

use Monolog\Utils;

/**
* @internal
*/
Expand All @@ -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
);
}
}
Loading