mirror of
https://github.com/Combodo/iTop.git
synced 2026-04-25 19:48:49 +02:00
N°5122 - Update libs to new PHP requirements
This commit is contained in:
@@ -1,15 +1,24 @@
|
||||
<?php
|
||||
<?php // phpcs:disable WebimpressCodingStandard.NamingConventions.AbstractClass.Prefix
|
||||
|
||||
/**
|
||||
* @see https://github.com/laminas/laminas-stdlib for the canonical source repository
|
||||
* @copyright https://github.com/laminas/laminas-stdlib/blob/master/COPYRIGHT.md
|
||||
* @license https://github.com/laminas/laminas-stdlib/blob/master/LICENSE.md New BSD License
|
||||
*/
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace Laminas\Stdlib;
|
||||
|
||||
use Laminas\Stdlib\StringWrapper\Iconv;
|
||||
use Laminas\Stdlib\StringWrapper\Intl;
|
||||
use Laminas\Stdlib\StringWrapper\MbString;
|
||||
use Laminas\Stdlib\StringWrapper\Native;
|
||||
use Laminas\Stdlib\StringWrapper\StringWrapperInterface;
|
||||
|
||||
use function array_search;
|
||||
use function defined;
|
||||
use function extension_loaded;
|
||||
use function in_array;
|
||||
use function is_string;
|
||||
use function preg_match;
|
||||
use function strtoupper;
|
||||
|
||||
/**
|
||||
* Utility class for handling strings of different character encodings
|
||||
* using available PHP extensions.
|
||||
@@ -21,9 +30,9 @@ abstract class StringUtils
|
||||
/**
|
||||
* Ordered list of registered string wrapper instances
|
||||
*
|
||||
* @var StringWrapperInterface[]
|
||||
* @var list<class-string<StringWrapperInterface>>|null
|
||||
*/
|
||||
protected static $wrapperRegistry = null;
|
||||
protected static $wrapperRegistry;
|
||||
|
||||
/**
|
||||
* A list of known single-byte character encodings (upper-case)
|
||||
@@ -31,11 +40,26 @@ abstract class StringUtils
|
||||
* @var string[]
|
||||
*/
|
||||
protected static $singleByteEncodings = [
|
||||
'ASCII', '7BIT', '8BIT',
|
||||
'ISO-8859-1', 'ISO-8859-2', 'ISO-8859-3', 'ISO-8859-4', 'ISO-8859-5',
|
||||
'ISO-8859-6', 'ISO-8859-7', 'ISO-8859-8', 'ISO-8859-9', 'ISO-8859-10',
|
||||
'ISO-8859-11', 'ISO-8859-13', 'ISO-8859-14', 'ISO-8859-15', 'ISO-8859-16',
|
||||
'CP-1251', 'CP-1252',
|
||||
'ASCII',
|
||||
'7BIT',
|
||||
'8BIT',
|
||||
'ISO-8859-1',
|
||||
'ISO-8859-2',
|
||||
'ISO-8859-3',
|
||||
'ISO-8859-4',
|
||||
'ISO-8859-5',
|
||||
'ISO-8859-6',
|
||||
'ISO-8859-7',
|
||||
'ISO-8859-8',
|
||||
'ISO-8859-9',
|
||||
'ISO-8859-10',
|
||||
'ISO-8859-11',
|
||||
'ISO-8859-13',
|
||||
'ISO-8859-14',
|
||||
'ISO-8859-15',
|
||||
'ISO-8859-16',
|
||||
'CP-1251',
|
||||
'CP-1252',
|
||||
// TODO
|
||||
];
|
||||
|
||||
@@ -44,12 +68,13 @@ abstract class StringUtils
|
||||
*
|
||||
* @var bool
|
||||
**/
|
||||
protected static $hasPcreUnicodeSupport = null;
|
||||
protected static $hasPcreUnicodeSupport;
|
||||
|
||||
/**
|
||||
* Get registered wrapper classes
|
||||
*
|
||||
* @return string[]
|
||||
* @psalm-return list<class-string<StringWrapperInterface>>
|
||||
*/
|
||||
public static function getRegisteredWrappers()
|
||||
{
|
||||
@@ -57,18 +82,18 @@ abstract class StringUtils
|
||||
static::$wrapperRegistry = [];
|
||||
|
||||
if (extension_loaded('intl')) {
|
||||
static::$wrapperRegistry[] = 'Laminas\Stdlib\StringWrapper\Intl';
|
||||
static::$wrapperRegistry[] = Intl::class;
|
||||
}
|
||||
|
||||
if (extension_loaded('mbstring')) {
|
||||
static::$wrapperRegistry[] = 'Laminas\Stdlib\StringWrapper\MbString';
|
||||
static::$wrapperRegistry[] = MbString::class;
|
||||
}
|
||||
|
||||
if (extension_loaded('iconv')) {
|
||||
static::$wrapperRegistry[] = 'Laminas\Stdlib\StringWrapper\Iconv';
|
||||
static::$wrapperRegistry[] = Iconv::class;
|
||||
}
|
||||
|
||||
static::$wrapperRegistry[] = 'Laminas\Stdlib\StringWrapper\Native';
|
||||
static::$wrapperRegistry[] = Native::class;
|
||||
}
|
||||
|
||||
return static::$wrapperRegistry;
|
||||
@@ -77,13 +102,14 @@ abstract class StringUtils
|
||||
/**
|
||||
* Register a string wrapper class
|
||||
*
|
||||
* @param string $wrapper
|
||||
* @param class-string<StringWrapperInterface> $wrapper
|
||||
* @return void
|
||||
*/
|
||||
public static function registerWrapper($wrapper)
|
||||
{
|
||||
$wrapper = (string) $wrapper;
|
||||
if (! in_array($wrapper, static::$wrapperRegistry, true)) {
|
||||
// using getRegisteredWrappers() here to ensure that the list is initialized
|
||||
if (! in_array($wrapper, static::getRegisteredWrappers(), true)) {
|
||||
static::$wrapperRegistry[] = $wrapper;
|
||||
}
|
||||
}
|
||||
@@ -91,12 +117,13 @@ abstract class StringUtils
|
||||
/**
|
||||
* Unregister a string wrapper class
|
||||
*
|
||||
* @param string $wrapper
|
||||
* @param class-string<StringWrapperInterface> $wrapper
|
||||
* @return void
|
||||
*/
|
||||
public static function unregisterWrapper($wrapper)
|
||||
{
|
||||
$index = array_search((string) $wrapper, static::$wrapperRegistry, true);
|
||||
// using getRegisteredWrappers() here to ensure that the list is initialized
|
||||
$index = array_search((string) $wrapper, static::getRegisteredWrappers(), true);
|
||||
if ($index !== false) {
|
||||
unset(static::$wrapperRegistry[$index]);
|
||||
}
|
||||
@@ -119,7 +146,7 @@ abstract class StringUtils
|
||||
* @param string $encoding Character encoding to support
|
||||
* @param string|null $convertEncoding OPTIONAL character encoding to convert in
|
||||
* @return StringWrapperInterface
|
||||
* @throws Exception\RuntimeException If no wrapper supports given character encodings
|
||||
* @throws Exception\RuntimeException If no wrapper supports given character encodings.
|
||||
*/
|
||||
public static function getWrapper($encoding = 'UTF-8', $convertEncoding = null)
|
||||
{
|
||||
@@ -133,7 +160,7 @@ abstract class StringUtils
|
||||
|
||||
throw new Exception\RuntimeException(
|
||||
'No wrapper found supporting "' . $encoding . '"'
|
||||
. (($convertEncoding !== null) ? ' and "' . $convertEncoding . '"' : '')
|
||||
. ($convertEncoding !== null ? ' and "' . $convertEncoding . '"' : '')
|
||||
);
|
||||
}
|
||||
|
||||
@@ -166,7 +193,7 @@ abstract class StringUtils
|
||||
*/
|
||||
public static function isValidUtf8($str)
|
||||
{
|
||||
return is_string($str) && ($str === '' || preg_match('/^./su', $str) == 1);
|
||||
return is_string($str) && ($str === '' || preg_match('/^./su', $str) === 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -178,7 +205,7 @@ abstract class StringUtils
|
||||
{
|
||||
if (static::$hasPcreUnicodeSupport === null) {
|
||||
ErrorHandler::start();
|
||||
static::$hasPcreUnicodeSupport = defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') == 1;
|
||||
static::$hasPcreUnicodeSupport = defined('PREG_BAD_UTF8_OFFSET_ERROR') && preg_match('/\pL/u', 'a') === 1;
|
||||
ErrorHandler::stop();
|
||||
}
|
||||
return static::$hasPcreUnicodeSupport;
|
||||
|
||||
Reference in New Issue
Block a user