8000 [String] leverage Stringable from PHP 8 by nicolas-grekas · Pull Request #36059 · symfony/symfony · GitHub
[go: up one dir, main page]

Skip to content

[String] leverage Stringable from PHP 8 #36059

New issue 8000

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"symfony/polyfill-intl-normalizer": "~1.0",
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php73": "^1.11",
"symfony/polyfill-php80": "^1.15",
"symfony/polyfill-uuid": "^1.15"
},
"replace": {
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Component/String/AbstractString.php
< 8000 tr class="js-expandable-line js-skip-tagsearch" data-position="0">
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
*
* @throws ExceptionInterface
*/
abstract class AbstractString implements \JsonSerializable
abstract class AbstractString implements \Stringable, \JsonSerializable
{
public const PREG_PATTERN_ORDER = PREG_PATTERN_ORDER;
public const PREG_SET_ORDER = PREG_SET_ORDER;
Expand Down
11 changes: 7 additions & 4 deletions src/Symfony/Component/String/LazyString.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
*
* @author Nicolas Grekas <p@tchwork.com>
*/
class LazyString implements \JsonSerializable
class LazyString implements \Stringable, \JsonSerializable
{
private $value;

Expand Down Expand Up @@ -50,14 +50,14 @@ public static function fromCallable($callback, ...$arguments): self
}

/**
* @param object|string|int|float|bool $value A scalar or an object that implements the __toString() magic method
* @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 an object that implements the __toString() magic method, %s given.', __METHOD__, \is_object($value) ? \get_class($value) : \gettype($value)));
throw new \TypeError(sprintf('Argument 1 passed to %s() must be a scalar or a stringable object, %s given.', __METHOD__, \is_object($value) ? \get_class($value) : \gettype($value)));
}

if (\is_object($value)) {
Expand All @@ -75,7 +75,7 @@ public static function fromStringable($value): self
*/
final public static function isStringable($value): bool
{
return \is_string($value) || $value instanceof self || (\is_object($value) ? \is_callable([$value, '__toString']) : is_scalar($value));
return \is_string($value) || $value instanceof self || (\is_object($value) ? method_exists($value, '__toString') : is_scalar($value));
}

/**
Expand All @@ -90,6 +90,9 @@ final public static function resolve($value): string
return $value;
}

/**
* @return string
*/
public function __toString()
{
if (\is_string($this->value)) {
Expand Down
3 changes: 2 additions & 1 deleti 8000 on src/Symfony/Component/String/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@
"php": "^7.2.5",
"symfony/polyfill-intl-grapheme": "~1.0",
"symfony/polyfill-intl-normalizer": "~1.0",
"symfony/polyfill-mbstring": "~1.0"
"symfony/polyfill-mbstring": "~1.0",
"symfony/polyfill-php80": "~1.15"
},
"require-dev": {
"symfony/error-handler": "^4.4|^5.0",
Expand Down
0