reinstall dependencies on php 7.4

This commit is contained in:
Attila Jozsef Kerekes
2022-11-14 21:15:40 +01:00
parent 8972a11c0a
commit 98401f20a2
681 changed files with 65697 additions and 9274 deletions

View File

@@ -18,15 +18,17 @@ namespace Symfony\Component\String;
*/
class LazyString implements \Stringable, \JsonSerializable
{
private \Closure|string $value;
private $value;
/**
* @param callable|array $callback A callable or a [Closure, method] lazy-callable
*
* @return static
*/
public static function fromCallable(callable|array $callback, mixed ...$arguments): static
public static function fromCallable($callback, ...$arguments): self
{
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)).']'));
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)));
}
$lazyString = new static();
@@ -47,8 +49,17 @@ class LazyString implements \Stringable, \JsonSerializable
return $lazyString;
}
public static function fromStringable(string|int|float|bool|\Stringable $value): static
/**
* @param string|int|float|bool|\Stringable $value
*
* @return static
*/
public static function fromStringable($value): self
{
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']);
}
@@ -62,22 +73,27 @@ class LazyString implements \Stringable, \JsonSerializable
/**
* Tells whether the provided value can be cast to string.
*/
final public static function isStringable(mixed $value): bool
final public static function isStringable($value): bool
{
return \is_string($value) || $value instanceof \Stringable || \is_scalar($value);
return \is_string($value) || $value instanceof self || (\is_object($value) ? method_exists($value, '__toString') : \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(\Stringable|string|int|float|bool $value): string
final public static function resolve($value): string
{
return $value;
}
public function __toString(): string
/**
* @return string
*/
public function __toString()
{
if (\is_string($this->value)) {
return $this->value;
@@ -95,6 +111,11 @@ 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;
}
}
@@ -127,7 +148,7 @@ class LazyString implements \Stringable, \JsonSerializable
} elseif ($callback instanceof \Closure) {
$r = new \ReflectionFunction($callback);
if (str_contains($r->name, '{closure}') || !$class = $r->getClosureScopeClass()) {
if (false !== strpos($r->name, '{closure}') || !$class = $r->getClosureScopeClass()) {
return $r->name;
}