N°5122 - Update libs to new PHP requirements

This commit is contained in:
Molkobain
2022-08-08 14:10:26 +02:00
parent 30021d9236
commit 57c36d0e51
585 changed files with 62279 additions and 20427 deletions

View File

@@ -1,26 +1,36 @@
<?php
/**
* @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\StringWrapper;
use Laminas\Stdlib\Exception;
use Laminas\Stdlib\StringUtils;
use function floor;
use function in_array;
use function sprintf;
use function str_pad;
use function str_repeat;
use function strtoupper;
use function wordwrap;
use const STR_PAD_BOTH;
use const STR_PAD_LEFT;
use const STR_PAD_RIGHT;
abstract class AbstractStringWrapper implements StringWrapperInterface
{
/**
* The character encoding working on
*
* @var string|null
*/
protected $encoding = 'UTF-8';
/**
* An optionally character encoding to convert to
*
* @var string|null
*/
protected $convertEncoding;
@@ -86,8 +96,8 @@ abstract class AbstractStringWrapper implements StringWrapperInterface
/**
* Get the defined character encoding to work with
*
* @return string
* @throws Exception\LogicException If no encoding was defined
* @return null|string
* @throws Exception\LogicException If no encoding was defined.
*/
public function getEncoding()
{
@@ -98,7 +108,7 @@ abstract class AbstractStringWrapper implements StringWrapperInterface
* Get the defined character encoding to convert to
*
* @return string|null
*/
*/
public function getConvertEncoding()
{
return $this->convertEncoding;
@@ -129,8 +139,8 @@ abstract class AbstractStringWrapper implements StringWrapperInterface
$to = $reverse ? $encoding : $convertEncoding;
throw new Exception\RuntimeException(sprintf(
'Converting from "%s" to "%s" isn\'t supported by this string wrapper',
$from,
$to
$from ?? '',
$to ?? ''
));
}
@@ -160,7 +170,7 @@ abstract class AbstractStringWrapper implements StringWrapperInterface
throw new Exception\InvalidArgumentException('Cannot force cut when width is zero');
}
if (StringUtils::isSingleByteEncoding($this->getEncoding())) {
if (null === $this->getEncoding() || StringUtils::isSingleByteEncoding($this->getEncoding())) {
return wordwrap($string, $width, $break, $cut);
}
@@ -179,16 +189,16 @@ abstract class AbstractStringWrapper implements StringWrapperInterface
}
if ($possibleBreak === $break) {
$result .= $this->substr($string, $lastStart, $current - $lastStart + $breakWidth);
$current += $breakWidth - 1;
$lastStart = $lastSpace = $current + 1;
$result .= $this->substr($string, $lastStart, $current - $lastStart + $breakWidth);
$current += $breakWidth - 1;
$lastStart = $lastSpace = $current + 1;
continue;
}
if ($char === ' ') {
if ($current - $lastStart >= $width) {
$result .= $this->substr($string, $lastStart, $current - $lastStart) . $break;
$lastStart = $current + 1;
$result .= $this->substr($string, $lastStart, $current - $lastStart) . $break;
$lastStart = $current + 1;
}
$lastSpace = $current;
@@ -196,14 +206,14 @@ abstract class AbstractStringWrapper implements StringWrapperInterface
}
if ($current - $lastStart >= $width && $cut && $lastStart >= $lastSpace) {
$result .= $this->substr($string, $lastStart, $current - $lastStart) . $break;
$lastStart = $lastSpace = $current;
$result .= $this->substr($string, $lastStart, $current - $lastStart) . $break;
$lastStart = $lastSpace = $current;
continue;
}
if ($current - $lastStart >= $width && $lastStart < $lastSpace) {
$result .= $this->substr($string, $lastStart, $lastSpace - $lastStart) . $break;
$lastStart = $lastSpace = $lastSpace + 1;
$result .= $this->substr($string, $lastStart, $lastSpace - $lastStart) . $break;
$lastStart = $lastSpace += 1;
continue;
}
}
@@ -226,7 +236,7 @@ abstract class AbstractStringWrapper implements StringWrapperInterface
*/
public function strPad($input, $padLength, $padString = ' ', $padType = STR_PAD_RIGHT)
{
if (StringUtils::isSingleByteEncoding($this->getEncoding())) {
if (null === $this->getEncoding() || StringUtils::isSingleByteEncoding($this->getEncoding())) {
return str_pad($input, $padLength, $padString, $padType);
}
@@ -240,13 +250,13 @@ abstract class AbstractStringWrapper implements StringWrapperInterface
return $input;
}
$repeatCount = floor($lengthOfPadding / $padStringLength);
$repeatCount = (int) floor($lengthOfPadding / $padStringLength);
if ($padType === STR_PAD_BOTH) {
$repeatCountLeft = $repeatCountRight = ($repeatCount - $repeatCount % 2) / 2;
$lastStringLength = $lengthOfPadding - 2 * $repeatCountLeft * $padStringLength;
$lastStringLeftLength = $lastStringRightLength = floor($lastStringLength / 2);
$lastStringLeftLength = $lastStringRightLength = (int) floor($lastStringLength / 2);
$lastStringRightLength += $lastStringLength % 2;
$lastStringLeft = $this->substr($padString, 0, $lastStringLeftLength);

View File

@@ -1,22 +1,26 @@
<?php
/**
* @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\StringWrapper;
use Laminas\Stdlib\Exception;
use function assert;
use function extension_loaded;
use function iconv;
use function iconv_strlen;
use function iconv_strpos;
use function iconv_substr;
class Iconv extends AbstractStringWrapper
{
/**
* List of supported character sets (upper case)
*
* @var string[]
* @link http://www.gnu.org/software/libiconv/
*
* @var string[]
*/
protected static $encodings = [
// European languages
@@ -241,6 +245,9 @@ class Iconv extends AbstractStringWrapper
*/
public function substr($str, $offset = 0, $length = null)
{
$length = $length ?? $this->strlen($str);
assert($length !== false);
return iconv_substr($str, $offset, $length, $this->getEncoding());
}
@@ -254,7 +261,10 @@ class Iconv extends AbstractStringWrapper
*/
public function strpos($haystack, $needle, $offset = 0)
{
return iconv_strpos($haystack, $needle, $offset, $this->getEncoding());
$encoding = $this->getEncoding();
assert($encoding !== null);
return iconv_strpos($haystack, $needle, $offset, $encoding);
}
/**
@@ -281,6 +291,10 @@ class Iconv extends AbstractStringWrapper
$fromEncoding = $reverse ? $convertEncoding : $encoding;
$toEncoding = $reverse ? $encoding : $convertEncoding;
if (null === $toEncoding || null === $fromEncoding) {
return $str;
}
// automatically add "//IGNORE" to not stop converting on invalid characters
// invalid characters triggers a notice anyway
return iconv($fromEncoding, $toEncoding . '//IGNORE', $str);

View File

@@ -1,15 +1,16 @@
<?php
/**
* @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\StringWrapper;
use Laminas\Stdlib\Exception;
use function extension_loaded;
use function grapheme_strlen;
use function grapheme_strpos;
use function grapheme_substr;
class Intl extends AbstractStringWrapper
{
/**
@@ -47,11 +48,12 @@ class Intl extends AbstractStringWrapper
* Returns the length of the given string
*
* @param string $str
* @return int|false
* @return false|int
*/
public function strlen($str)
{
return grapheme_strlen($str);
$len = grapheme_strlen($str);
return $len ?? false;
}
/**

View File

@@ -1,24 +1,30 @@
<?php
/**
* @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\StringWrapper;
use Laminas\Stdlib\Exception;
use function array_map;
use function array_search;
use function extension_loaded;
use function mb_convert_encoding;
use function mb_list_encodings;
use function mb_strlen;
use function mb_strpos;
use function mb_substr;
class MbString extends AbstractStringWrapper
{
/**
* List of supported character sets (upper case)
*
* @var null|string[]
* @link http://php.net/manual/mbstring.supported-encodings.php
*
* @var null|string[]
*/
protected static $encodings = null;
protected static $encodings;
/**
* Get a list of supported character encodings
@@ -115,6 +121,7 @@ class MbString extends AbstractStringWrapper
$fromEncoding = $reverse ? $convertEncoding : $encoding;
$toEncoding = $reverse ? $encoding : $convertEncoding;
return mb_convert_encoding($str, $toEncoding, $fromEncoding);
return mb_convert_encoding($str, $toEncoding ?? '', $fromEncoding ?? '');
}
}

View File

@@ -1,16 +1,18 @@
<?php
/**
* @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\StringWrapper;
use Laminas\Stdlib\Exception;
use Laminas\Stdlib\StringUtils;
use function in_array;
use function strlen;
use function strpos;
use function strtoupper;
use function substr;
class Native extends AbstractStringWrapper
{
/**
@@ -74,7 +76,7 @@ class Native extends AbstractStringWrapper
);
}
if ($encodingUpper !== strtoupper($convertEncoding)) {
if (null !== $convertEncoding && $encodingUpper !== strtoupper($convertEncoding)) {
$this->convertEncoding = $encodingUpper;
}

View File

@@ -1,13 +1,11 @@
<?php
/**
* @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\StringWrapper;
use const STR_PAD_RIGHT;
interface StringWrapperInterface
{
/**
@@ -38,7 +36,7 @@ interface StringWrapperInterface
/**
* Get the defined character encoding to work with (upper case)
*
* @return string
* @return string|null
*/
public function getEncoding();