Update dependencies

This commit is contained in:
Chris Hunt
2022-11-14 19:35:16 +00:00
parent 0966639699
commit ee77d09c58
677 changed files with 9253 additions and 65635 deletions

View File

@@ -18,17 +18,15 @@ namespace Symfony\Component\String;
*/
class LazyString implements \Stringable, \JsonSerializable
{
private $value;
private \Closure|string $value;
/**
* @param callable|array $callback A callable or a [Closure, method] lazy-callable
*
* @return static
*/
public static function fromCallable($callback, ...$arguments): self
public static function fromCallable(callable|array $callback, mixed ...$arguments): static
{
if (!\is_callable($callback) && !(\is_array($callback) && isset($callback[0]) && $callback[0] 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__, get_debug_type($callback)));
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)).']'));
}
$lazyString = new static();
@@ -49,17 +47,8 @@ class LazyString implements \Stringable, \JsonSerializable
return $lazyString;
}
/**
* @param string|int|float|bool|\Stringable $value
*
* @return static
*/
public static function fromStringable($value): self
public static function fromStringable(string|int|float|bool|\Stringable $value): static
{
if (!self::isStringable($value)) {
throw new \TypeError(sprintf('Argument 1 passed to "%s()" must be a scalar or a stringable object, "%s" given.', __METHOD__, get_debug_type($value)));
}
if (\is_object($value)) {
return static::fromCallable([$value, '__toString']);
}
@@ -73,27 +62,22 @@ class LazyString implements \Stringable, \JsonSerializable
/**
* Tells whether the provided value can be cast to string.
*/
final public static function isStringable($value): bool
final public static function isStringable(mixed $value): bool
{
return \is_string($value) || $value instanceof self || (\is_object($value) ? method_exists($value, '__toString') : \is_scalar($value));
return \is_string($value) || $value instanceof \Stringable || \is_scalar($value);
}
/**
* Casts scalars and stringable objects to strings.
*
* @param object|string|int|float|bool $value
*
* @throws \TypeError When the provided value is not stringable
*/
final public static function resolve($value): string
final public static function resolve(\Stringable|string|int|float|bool $value): string
{
return $value;
}
/**
* @return string
*/
public function __toString()
public function __toString(): string
{
if (\is_string($this->value)) {
return $this->value;
@@ -111,11 +95,6 @@ class LazyString implements \Stringable, \JsonSerializable
$e = new \TypeError(sprintf('Return value of %s() passed to %s::fromCallable() must be of the type string, %s returned.', $callback, static::class, $type));
}
if (\PHP_VERSION_ID < 70400) {
// leverage the ErrorHandler component with graceful fallback when it's not available
return trigger_error($e, \E_USER_ERROR);
}
throw $e;
}
}
@@ -148,7 +127,7 @@ class LazyString implements \Stringable, \JsonSerializable
} elseif ($callback instanceof \Closure) {
$r = new \ReflectionFunction($callback);
if (false !== strpos($r->name, '{closure}') || !$class = $r->getClosureScopeClass()) {
if (str_contains($r->name, '{closure}') || !$class = $r->getClosureScopeClass()) {
return $r->name;
}