Skip to content

Commit

Permalink
Revert "Replace deprecated utf8_encode with mb_convert_encoding"
Browse files Browse the repository at this point in the history
This reverts commit d498e1e.
  • Loading branch information
mmenozzi committed Nov 22, 2024
1 parent 949024f commit bc87667
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ jobs:
run: composer install --no-interaction

- name: Composer Require Checker
run: composer-require-checker --config-file=composer-require-checker.json
run: composer-require-checker

- name: Run Easy Coding Standard
run: vendor/bin/ecs check
Expand Down
29 changes: 5 additions & 24 deletions src/NonUtf8Cleaner.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

namespace Webgriffe\Esb;

use Monolog\Utils;

/**
* @internal
*/
Expand All @@ -15,34 +17,13 @@ class NonUtf8Cleaner
*/
public static function clean(array $data): array
{
array_walk_recursive($data, [__CLASS__, 'cleanString']);
array_walk_recursive($data, [Utils::class, 'detectAndCleanUtf8']);
return $data;
}

public static function cleanString(string $data): string
{
// 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
);
Utils::detectAndCleanUtf8($data);
return $data;
}
}

0 comments on commit bc87667

Please sign in to comment.