mirror of
https://github.com/Combodo/iTop.git
synced 2026-05-20 15:52:24 +02:00
N°9319 increase php min. version to 8.2 (#887)
* Update minimum PHP version to 8.2 * Fix previous wrong resolution of merge conflict
This commit is contained in:
@@ -27,6 +27,7 @@ namespace Symfony\Polyfill\Intl\Grapheme;
|
||||
* - grapheme_strstr - Returns part of haystack string from the first occurrence of needle to the end of haystack
|
||||
* - grapheme_substr - Return part of a string
|
||||
* - grapheme_str_split - Splits a string into an array of individual or chunks of graphemes
|
||||
* - grapheme_levenshtein - Calculate the grapheme-unit Levenshtein distance between two strings
|
||||
*
|
||||
* @author Nicolas Grekas <p@tchwork.com>
|
||||
*
|
||||
@@ -51,7 +52,7 @@ final class Grapheme
|
||||
|
||||
if (!\is_scalar($s)) {
|
||||
$hasError = false;
|
||||
set_error_handler(function () use (&$hasError) { $hasError = true; });
|
||||
set_error_handler(static function () use (&$hasError) { $hasError = true; });
|
||||
$next = substr($s, $start);
|
||||
restore_error_handler();
|
||||
if ($hasError) {
|
||||
@@ -223,6 +224,54 @@ final class Grapheme
|
||||
return $chunks;
|
||||
}
|
||||
|
||||
public static function grapheme_levenshtein($s1, $s2, $insertion_cost = 1, $replacement_cost = 1, $deletion_cost = 1)
|
||||
{
|
||||
if (!preg_match('//u', $s1) || !preg_match('//u', $s2)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (0 > $insertion_cost || 0 > $replacement_cost || 0 > $deletion_cost) {
|
||||
if (80000 > \PHP_VERSION_ID) {
|
||||
return false;
|
||||
}
|
||||
|
||||
throw new \ValueError('grapheme_levenshtein(): Argument #3 ($insertion_cost), #4 ($replacement_cost), and #5 ($deletion_cost) must be greater than or equal to 0');
|
||||
}
|
||||
|
||||
preg_match_all('/'.SYMFONY_GRAPHEME_CLUSTER_RX.'/u', $s1, $s1);
|
||||
preg_match_all('/'.SYMFONY_GRAPHEME_CLUSTER_RX.'/u', $s2, $s2);
|
||||
|
||||
$s1 = $s1[0];
|
||||
$s2 = $s2[0];
|
||||
$l1 = \count($s1);
|
||||
$l2 = \count($s2);
|
||||
|
||||
if (0 === $l1) {
|
||||
return $l2 * $insertion_cost;
|
||||
}
|
||||
if (0 === $l2) {
|
||||
return $l1 * $deletion_cost;
|
||||
}
|
||||
|
||||
$dp = array_fill(0, $l1 + 1, array_fill(0, $l2 + 1, 0));
|
||||
|
||||
for ($i = 1; $i <= $l1; ++$i) {
|
||||
$dp[$i][0] = $dp[$i - 1][0] + $deletion_cost;
|
||||
}
|
||||
for ($j = 1; $j <= $l2; ++$j) {
|
||||
$dp[0][$j] = $dp[0][$j - 1] + $insertion_cost;
|
||||
}
|
||||
|
||||
for ($i = 1; $i <= $l1; ++$i) {
|
||||
for ($j = 1; $j <= $l2; ++$j) {
|
||||
$cost = ($s1[$i - 1] === $s2[$j - 1]) ? 0 : $replacement_cost;
|
||||
$dp[$i][$j] = min($dp[$i - 1][$j] + $deletion_cost, $dp[$i][$j - 1] + $insertion_cost, $dp[$i - 1][$j - 1] + $cost);
|
||||
}
|
||||
}
|
||||
|
||||
return $dp[$l1][$l2];
|
||||
}
|
||||
|
||||
private static function grapheme_position($s, $needle, $offset, $mode)
|
||||
{
|
||||
$needle = (string) $needle;
|
||||
|
||||
@@ -53,5 +53,8 @@ if (!function_exists('grapheme_substr')) {
|
||||
function grapheme_substr($string, $offset, $length = null) { return p\Grapheme::grapheme_substr($string, $offset, $length); }
|
||||
}
|
||||
if (!function_exists('grapheme_str_split')) {
|
||||
function grapheme_str_split($string, $length = 1) { return p\Grapheme::grapheme_str_split($string, $length); }
|
||||
function grapheme_str_split(string $string, int $length = 1) { return p\Grapheme::grapheme_str_split($string, $length); }
|
||||
}
|
||||
if (!function_exists('grapheme_levenshtein')) {
|
||||
function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1, string $locale = '') { return p\Php85::grapheme_levenshtein($string1, $string2, $insertion_cost, $replacement_cost, $deletion_cost); }
|
||||
}
|
||||
|
||||
@@ -14,6 +14,9 @@ use Symfony\Polyfill\Intl\Grapheme as p;
|
||||
if (!function_exists('grapheme_str_split')) {
|
||||
function grapheme_str_split(string $string, int $length = 1): array|false { return p\Grapheme::grapheme_str_split($string, $length); }
|
||||
}
|
||||
if (!function_exists('grapheme_levenshtein')) {
|
||||
function grapheme_levenshtein(string $string1, string $string2, int $insertion_cost = 1, int $replacement_cost = 1, int $deletion_cost = 1, string $locale = ''): int|false { return p\Grapheme::grapheme_levenshtein($string1, $string2, $insertion_cost, $replacement_cost, $deletion_cost); }
|
||||
}
|
||||
|
||||
if (extension_loaded('intl')) {
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user