update patch 1

This commit is contained in:
fiqhpratama
2024-12-02 01:18:34 +07:00
parent 453d9bb470
commit 25026b0a85
3380 changed files with 103529 additions and 363623 deletions
+24 -8
View File
@@ -263,7 +263,7 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
public function endsWith(string|iterable $suffix): bool
{
if (\is_string($suffix)) {
throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
}
foreach ($suffix as $s) {
@@ -312,7 +312,7 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
public function equalsTo(string|iterable $string): bool
{
if (\is_string($string)) {
throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
}
foreach ($string as $s) {
@@ -340,7 +340,7 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
public function indexOf(string|iterable $needle, int $offset = 0): ?int
{
if (\is_string($needle)) {
throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
}
$i = \PHP_INT_MAX;
@@ -362,7 +362,7 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
public function indexOfLast(string|iterable $needle, int $offset = 0): ?int
{
if (\is_string($needle)) {
throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
}
$i = null;
@@ -414,7 +414,7 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
public function repeat(int $multiplier): static
{
if (0 > $multiplier) {
throw new InvalidArgumentException(sprintf('Multiplier must be positive, %d given.', $multiplier));
throw new InvalidArgumentException(\sprintf('Multiplier must be positive, %d given.', $multiplier));
}
$str = clone $this;
@@ -433,6 +433,11 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
abstract public function snake(): static;
public function kebab(): static
{
return $this->snake()->replace('_', '-');
}
abstract public function splice(string $replacement, int $start = 0, ?int $length = null): static;
/**
@@ -481,7 +486,7 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
public function startsWith(string|iterable $prefix): bool
{
if (\is_string($prefix)) {
throw new \TypeError(sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
throw new \TypeError(\sprintf('Method "%s()" must be overridden by class "%s" to deal with non-iterable values.', __FUNCTION__, static::class));
}
foreach ($prefix as $prefix) {
@@ -605,7 +610,7 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
return $str;
}
public function truncate(int $length, string $ellipsis = '', bool $cut = true): static
public function truncate(int $length, string $ellipsis = '', bool|TruncateMode $cut = TruncateMode::Char): static
{
$stringLength = $this->length();
@@ -619,16 +624,27 @@ abstract class AbstractString implements \Stringable, \JsonSerializable
$ellipsisLength = 0;
}
if (!$cut) {
$desiredLength = $length;
if (TruncateMode::WordAfter === $cut || !$cut) {
if (null === $length = $this->indexOf([' ', "\r", "\n", "\t"], ($length ?: 1) - 1)) {
return clone $this;
}
$length += $ellipsisLength;
} elseif (TruncateMode::WordBefore === $cut && null !== $this->indexOf([' ', "\r", "\n", "\t"], ($length ?: 1) - 1)) {
$length += $ellipsisLength;
}
$str = $this->slice(0, $length - $ellipsisLength);
if (TruncateMode::WordBefore === $cut) {
if (0 === $ellipsisLength && $desiredLength === $this->indexOf([' ', "\r", "\n", "\t"], $length)) {
return $str;
}
$str = $str->beforeLast([' ', "\r", "\n", "\t"]);
}
return $ellipsisLength ? $str->trimEnd()->append($ellipsis) : $str;
}
+2 -2
View File
@@ -124,7 +124,7 @@ abstract class AbstractUnicodeString extends AbstractString
}
if (null === $transliterator) {
throw new InvalidArgumentException(sprintf('Unknown transliteration rule "%s".', $rule));
throw new InvalidArgumentException(\sprintf('Unknown transliteration rule "%s".', $rule));
}
self::$transliterators['any-latin/bgn'] = $transliterator;
@@ -139,7 +139,7 @@ abstract class AbstractUnicodeString extends AbstractString
$c = (string) iconv('UTF-8', 'ASCII//TRANSLIT', $c[0]);
if ('' === $c && '' === iconv('UTF-8', 'ASCII//TRANSLIT', '²')) {
throw new \LogicException(sprintf('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you\'re using Alpine Linux.', static::class));
throw new \LogicException(\sprintf('"%s" requires a translit-able iconv implementation, try installing "gnu-libiconv" if you\'re using Alpine Linux.', static::class));
}
return 1 < \strlen($c) ? ltrim($c, '\'`"^~') : ('' !== $c ? $c : '?');
+3 -3
View File
@@ -46,7 +46,7 @@ class ByteString extends AbstractString
public static function fromRandom(int $length = 16, ?string $alphabet = null): self
{
if ($length <= 0) {
throw new InvalidArgumentException(sprintf('A strictly positive length is expected, "%d" given.', $length));
throw new InvalidArgumentException(\sprintf('A strictly positive length is expected, "%d" given.', $length));
}
$alphabet ??= self::ALPHABET_ALPHANUMERIC;
@@ -340,7 +340,7 @@ class ByteString extends AbstractString
public function slice(int $start = 0, ?int $length = null): static
{
$str = clone $this;
$str->string = (string) substr($this->string, $start, $length ?? \PHP_INT_MAX);
$str->string = substr($this->string, $start, $length ?? \PHP_INT_MAX);
return $str;
}
@@ -441,7 +441,7 @@ class ByteString extends AbstractString
}
if (!$validEncoding) {
throw new InvalidArgumentException(sprintf('Invalid "%s" string.', $fromEncoding ?? 'Windows-1252'));
throw new InvalidArgumentException(\sprintf('Invalid "%s" string.', $fromEncoding ?? 'Windows-1252'));
}
$u->string = mb_convert_encoding($this->string, 'UTF-8', $fromEncoding ?? 'Windows-1252');
+6
View File
@@ -1,6 +1,12 @@
CHANGELOG
=========
7.2
---
* Add `TruncateMode` enum to handle more truncate methods
* Add the `AbstractString::kebab()` method
7.1
---
+2 -2
View File
@@ -26,7 +26,7 @@ class LazyString implements \Stringable, \JsonSerializable
public static function fromCallable(callable|array $callback, mixed ...$arguments): static
{
if (\is_array($callback) && !\is_callable($callback) && !(($callback[0] ?? null) instanceof \Closure || 2 < \count($callback))) {
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a callable or a [Closure, method] lazy-callable, "%s" given.', __METHOD__, '['.implode(', ', array_map('get_debug_type', $callback)).']'));
throw new \TypeError(\sprintf('Argument 1 passed to "%s()" must be a callable or a [Closure, method] lazy-callable, "%s" given.', __METHOD__, '['.implode(', ', array_map('get_debug_type', $callback)).']'));
}
$lazyString = new static();
@@ -94,7 +94,7 @@ class LazyString implements \Stringable, \JsonSerializable
$r = new \ReflectionFunction($this->value);
$callback = $r->getStaticVariables()['callback'];
$e = new \TypeError(sprintf('Return value of %s() passed to %s::fromCallable() must be of the type string, %s returned.', $callback, static::class, $type));
$e = new \TypeError(\sprintf('Return value of %s() passed to %s::fromCallable() must be of the type string, %s returned.', $callback, static::class, $type));
}
throw $e;
+1 -1
View File
@@ -92,7 +92,7 @@ class AsciiSlugger implements SluggerInterface, LocaleAwareInterface
public function withEmoji(bool|string $emoji = true): static
{
if (false !== $emoji && !class_exists(EmojiTransliterator::class)) {
throw new \LogicException(sprintf('You cannot use the "%s()" method as the "symfony/emoji" package is not installed. Try running "composer require symfony/emoji".', __METHOD__));
throw new \LogicException(\sprintf('You cannot use the "%s()" method as the "symfony/emoji" package is not installed. Try running "composer require symfony/emoji".', __METHOD__));
}
$new = clone $this;
+1 -1
View File
@@ -286,7 +286,7 @@ class UnicodeString extends AbstractUnicodeString
$str = clone $this;
$start = $start ? \strlen(grapheme_substr($this->string, 0, $start)) : 0;
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length ?? 2147483647)) : $length;
$length = $length ? \strlen(grapheme_substr($this->string, $start, $length)) : $length;
$str->string = substr_replace($this->string, $replacement, $start, $length ?? 2147483647);
if (normalizer_is_normalized($str->string)) {