package and depencies
This commit is contained in:
102
vendor/symfony/string/ByteString.php
vendored
102
vendor/symfony/string/ByteString.php
vendored
@@ -48,7 +48,7 @@ class ByteString extends AbstractString
|
||||
throw new InvalidArgumentException(sprintf('A strictly positive length is expected, "%d" given.', $length));
|
||||
}
|
||||
|
||||
$alphabet = $alphabet ?? self::ALPHABET_ALPHANUMERIC;
|
||||
$alphabet ??= self::ALPHABET_ALPHANUMERIC;
|
||||
$alphabetSize = \strlen($alphabet);
|
||||
$bits = (int) ceil(log($alphabetSize, 2.0));
|
||||
if ($bits <= 0 || $bits > 56) {
|
||||
@@ -92,7 +92,7 @@ class ByteString extends AbstractString
|
||||
return '' === $str ? [] : [\ord($str)];
|
||||
}
|
||||
|
||||
public function append(string ...$suffix): parent
|
||||
public function append(string ...$suffix): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string .= 1 >= \count($suffix) ? ($suffix[0] ?? '') : implode('', $suffix);
|
||||
@@ -100,7 +100,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function camel(): parent
|
||||
public function camel(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
@@ -132,27 +132,23 @@ class ByteString extends AbstractString
|
||||
return $chunks;
|
||||
}
|
||||
|
||||
public function endsWith($suffix): bool
|
||||
public function endsWith(string|iterable|AbstractString $suffix): bool
|
||||
{
|
||||
if ($suffix instanceof parent) {
|
||||
if ($suffix instanceof AbstractString) {
|
||||
$suffix = $suffix->string;
|
||||
} elseif (\is_array($suffix) || $suffix instanceof \Traversable) {
|
||||
} elseif (!\is_string($suffix)) {
|
||||
return parent::endsWith($suffix);
|
||||
} else {
|
||||
$suffix = (string) $suffix;
|
||||
}
|
||||
|
||||
return '' !== $suffix && \strlen($this->string) >= \strlen($suffix) && 0 === substr_compare($this->string, $suffix, -\strlen($suffix), null, $this->ignoreCase);
|
||||
}
|
||||
|
||||
public function equalsTo($string): bool
|
||||
public function equalsTo(string|iterable|AbstractString $string): bool
|
||||
{
|
||||
if ($string instanceof parent) {
|
||||
if ($string instanceof AbstractString) {
|
||||
$string = $string->string;
|
||||
} elseif (\is_array($string) || $string instanceof \Traversable) {
|
||||
} elseif (!\is_string($string)) {
|
||||
return parent::equalsTo($string);
|
||||
} else {
|
||||
$string = (string) $string;
|
||||
}
|
||||
|
||||
if ('' !== $string && $this->ignoreCase) {
|
||||
@@ -162,7 +158,7 @@ class ByteString extends AbstractString
|
||||
return $string === $this->string;
|
||||
}
|
||||
|
||||
public function folded(): parent
|
||||
public function folded(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = strtolower($str->string);
|
||||
@@ -170,14 +166,12 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function indexOf($needle, int $offset = 0): ?int
|
||||
public function indexOf(string|iterable|AbstractString $needle, int $offset = 0): ?int
|
||||
{
|
||||
if ($needle instanceof parent) {
|
||||
if ($needle instanceof AbstractString) {
|
||||
$needle = $needle->string;
|
||||
} elseif (\is_array($needle) || $needle instanceof \Traversable) {
|
||||
} elseif (!\is_string($needle)) {
|
||||
return parent::indexOf($needle, $offset);
|
||||
} else {
|
||||
$needle = (string) $needle;
|
||||
}
|
||||
|
||||
if ('' === $needle) {
|
||||
@@ -189,14 +183,12 @@ class ByteString extends AbstractString
|
||||
return false === $i ? null : $i;
|
||||
}
|
||||
|
||||
public function indexOfLast($needle, int $offset = 0): ?int
|
||||
public function indexOfLast(string|iterable|AbstractString $needle, int $offset = 0): ?int
|
||||
{
|
||||
if ($needle instanceof parent) {
|
||||
if ($needle instanceof AbstractString) {
|
||||
$needle = $needle->string;
|
||||
} elseif (\is_array($needle) || $needle instanceof \Traversable) {
|
||||
} elseif (!\is_string($needle)) {
|
||||
return parent::indexOfLast($needle, $offset);
|
||||
} else {
|
||||
$needle = (string) $needle;
|
||||
}
|
||||
|
||||
if ('' === $needle) {
|
||||
@@ -213,7 +205,7 @@ class ByteString extends AbstractString
|
||||
return '' === $this->string || preg_match('//u', $this->string);
|
||||
}
|
||||
|
||||
public function join(array $strings, string $lastGlue = null): parent
|
||||
public function join(array $strings, string $lastGlue = null): static
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
@@ -228,7 +220,7 @@ class ByteString extends AbstractString
|
||||
return \strlen($this->string);
|
||||
}
|
||||
|
||||
public function lower(): parent
|
||||
public function lower(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = strtolower($str->string);
|
||||
@@ -248,15 +240,7 @@ class ByteString extends AbstractString
|
||||
|
||||
try {
|
||||
if (false === $match($regexp, $this->string, $matches, $flags | \PREG_UNMATCHED_AS_NULL, $offset)) {
|
||||
$lastError = preg_last_error();
|
||||
|
||||
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
|
||||
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
|
||||
throw new RuntimeException('Matching failed with '.$k.'.');
|
||||
}
|
||||
}
|
||||
|
||||
throw new RuntimeException('Matching failed with unknown error code.');
|
||||
throw new RuntimeException('Matching failed with error: '.preg_last_error_msg());
|
||||
}
|
||||
} finally {
|
||||
restore_error_handler();
|
||||
@@ -265,7 +249,7 @@ class ByteString extends AbstractString
|
||||
return $matches;
|
||||
}
|
||||
|
||||
public function padBoth(int $length, string $padStr = ' '): parent
|
||||
public function padBoth(int $length, string $padStr = ' '): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = str_pad($this->string, $length, $padStr, \STR_PAD_BOTH);
|
||||
@@ -273,7 +257,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function padEnd(int $length, string $padStr = ' '): parent
|
||||
public function padEnd(int $length, string $padStr = ' '): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = str_pad($this->string, $length, $padStr, \STR_PAD_RIGHT);
|
||||
@@ -281,7 +265,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function padStart(int $length, string $padStr = ' '): parent
|
||||
public function padStart(int $length, string $padStr = ' '): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = str_pad($this->string, $length, $padStr, \STR_PAD_LEFT);
|
||||
@@ -289,7 +273,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function prepend(string ...$prefix): parent
|
||||
public function prepend(string ...$prefix): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = (1 >= \count($prefix) ? ($prefix[0] ?? '') : implode('', $prefix)).$str->string;
|
||||
@@ -297,7 +281,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function replace(string $from, string $to): parent
|
||||
public function replace(string $from, string $to): static
|
||||
{
|
||||
$str = clone $this;
|
||||
|
||||
@@ -308,21 +292,13 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function replaceMatches(string $fromRegexp, $to): parent
|
||||
public function replaceMatches(string $fromRegexp, string|callable $to): static
|
||||
{
|
||||
if ($this->ignoreCase) {
|
||||
$fromRegexp .= 'i';
|
||||
}
|
||||
|
||||
if (\is_array($to)) {
|
||||
if (!\is_callable($to)) {
|
||||
throw new \TypeError(sprintf('Argument 2 passed to "%s::replaceMatches()" must be callable, array given.', static::class));
|
||||
}
|
||||
|
||||
$replace = 'preg_replace_callback';
|
||||
} else {
|
||||
$replace = $to instanceof \Closure ? 'preg_replace_callback' : 'preg_replace';
|
||||
}
|
||||
$replace = \is_array($to) || $to instanceof \Closure ? 'preg_replace_callback' : 'preg_replace';
|
||||
|
||||
set_error_handler(static function ($t, $m) { throw new InvalidArgumentException($m); });
|
||||
|
||||
@@ -331,7 +307,7 @@ class ByteString extends AbstractString
|
||||
$lastError = preg_last_error();
|
||||
|
||||
foreach (get_defined_constants(true)['pcre'] as $k => $v) {
|
||||
if ($lastError === $v && '_ERROR' === substr($k, -6)) {
|
||||
if ($lastError === $v && str_ends_with($k, '_ERROR')) {
|
||||
throw new RuntimeException('Matching failed with '.$k.'.');
|
||||
}
|
||||
}
|
||||
@@ -348,7 +324,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function reverse(): parent
|
||||
public function reverse(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = strrev($str->string);
|
||||
@@ -356,7 +332,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function slice(int $start = 0, int $length = null): parent
|
||||
public function slice(int $start = 0, int $length = null): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = (string) substr($this->string, $start, $length ?? \PHP_INT_MAX);
|
||||
@@ -364,7 +340,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function snake(): parent
|
||||
public function snake(): static
|
||||
{
|
||||
$str = $this->camel();
|
||||
$str->string = strtolower(preg_replace(['/([A-Z]+)([A-Z][a-z])/', '/([a-z\d])([A-Z])/'], '\1_\2', $str->string));
|
||||
@@ -372,7 +348,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function splice(string $replacement, int $start = 0, int $length = null): parent
|
||||
public function splice(string $replacement, int $start = 0, int $length = null): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = substr_replace($this->string, $replacement, $start, $length ?? \PHP_INT_MAX);
|
||||
@@ -382,7 +358,7 @@ class ByteString extends AbstractString
|
||||
|
||||
public function split(string $delimiter, int $limit = null, int $flags = null): array
|
||||
{
|
||||
if (1 > $limit = $limit ?? \PHP_INT_MAX) {
|
||||
if (1 > $limit ??= \PHP_INT_MAX) {
|
||||
throw new InvalidArgumentException('Split limit must be a positive integer.');
|
||||
}
|
||||
|
||||
@@ -407,9 +383,9 @@ class ByteString extends AbstractString
|
||||
return $chunks;
|
||||
}
|
||||
|
||||
public function startsWith($prefix): bool
|
||||
public function startsWith(string|iterable|AbstractString $prefix): bool
|
||||
{
|
||||
if ($prefix instanceof parent) {
|
||||
if ($prefix instanceof AbstractString) {
|
||||
$prefix = $prefix->string;
|
||||
} elseif (!\is_string($prefix)) {
|
||||
return parent::startsWith($prefix);
|
||||
@@ -418,7 +394,7 @@ class ByteString extends AbstractString
|
||||
return '' !== $prefix && 0 === ($this->ignoreCase ? strncasecmp($this->string, $prefix, \strlen($prefix)) : strncmp($this->string, $prefix, \strlen($prefix)));
|
||||
}
|
||||
|
||||
public function title(bool $allWords = false): parent
|
||||
public function title(bool $allWords = false): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = $allWords ? ucwords($str->string) : ucfirst($str->string);
|
||||
@@ -468,7 +444,7 @@ class ByteString extends AbstractString
|
||||
return $u;
|
||||
}
|
||||
|
||||
public function trim(string $chars = " \t\n\r\0\x0B\x0C"): parent
|
||||
public function trim(string $chars = " \t\n\r\0\x0B\x0C"): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = trim($str->string, $chars);
|
||||
@@ -476,7 +452,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function trimEnd(string $chars = " \t\n\r\0\x0B\x0C"): parent
|
||||
public function trimEnd(string $chars = " \t\n\r\0\x0B\x0C"): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = rtrim($str->string, $chars);
|
||||
@@ -484,7 +460,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function trimStart(string $chars = " \t\n\r\0\x0B\x0C"): parent
|
||||
public function trimStart(string $chars = " \t\n\r\0\x0B\x0C"): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = ltrim($str->string, $chars);
|
||||
@@ -492,7 +468,7 @@ class ByteString extends AbstractString
|
||||
return $str;
|
||||
}
|
||||
|
||||
public function upper(): parent
|
||||
public function upper(): static
|
||||
{
|
||||
$str = clone $this;
|
||||
$str->string = strtoupper($str->string);
|
||||
|
Reference in New Issue
Block a user