8000 feature #36059 [String] leverage Stringable from PHP 8 (nicolas-grekas) · symfony/symfony@6f206c5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 6f206c5

Browse files
feature #36059 [String] leverage Stringable from PHP 8 (nicolas-grekas)
This PR was merged into the 5.1-dev branch. Discussion ---------- [String] leverage Stringable from PHP 8 | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | yes | Deprecations? | no | Tickets | - | License | MIT | Doc PR | - Commits ------- 53b0f63 [String] leverage Stringable from PHP 8
2 parents 5428fef + 53b0f63 commit 6f206c5

File tree

4 files changed

+11
-6
lines changed

4 files changed

+11
-6
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
"symfony/polyfill-intl-normalizer": "~1.0",
3535
"symfony/polyfill-mbstring": "~1.0",
3636
"symfony/polyfill-php73": "^1.11",
37+
"symfony/polyfill-php80": "^1.15",
3738
"symfony/polyfill-uuid": "^1.15"
3839
},
3940
"replace": {

src/Symfony/Component/String/AbstractString.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @throws ExceptionInterface
2929
*/
30-
abstract class AbstractString implements \JsonSerializable
30+
abstract class AbstractString implements \Stringable, \JsonSerializable
3131
{
3232
public const PREG_PATTERN_ORDER = PREG_PATTERN_ORDER;
3333
public const PREG_SET_ORDER = PREG_SET_ORDER;

src/Symfony/Component/String/LazyString.php

Lines changed: 7 additions & 4 deletions
8000
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
*
1717
* @author Nicolas Grekas <p@tchwork.com>
1818
*/
19-
class LazyString implements \JsonSerializable
19+
class LazyString implements \Stringable, \JsonSerializable
2020
{
2121
private $value;
2222

@@ -50,14 +50,14 @@ public static function fromCallable($callback, ...$arguments): self
5050
}
5151

5252
/**
53-
* @param object|string|int|float|bool $value A scalar or an object that implements the __toString() magic method
53+
* @param string|int|float|bool|\Stringable $value
5454
*
5555
* @return static
5656
*/
5757
public static function fromStringable($value): self
5858
{
5959
if (!self::isStringable($value)) {
60-
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)));
60+
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)));
6161
}
6262

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

8181
/**
@@ -90,6 +90,9 @@ final public static function resolve($value): string
9090
return $value;
9191
}
9292

93+
/**
94+
* @return string
95+
*/
9396
public function __toString()
9497
{
9598
if (\is_string($this->value)) {

src/Symfony/Component/String/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@
1919
"php": "^7.2.5",
2020
"symfony/polyfill-intl-grapheme": "~1.0",
2121
"symfony/polyfill-intl-normalizer": "~1.0",
22-
"symfony/polyfill-mbstring": "~1.0"
22+
"symfony/polyfill-mbstring": "~1.0",
23+
"symfony/polyfill-php80": "~1.15"
2324
},
2425
"require-dev": {
2526
"symfony/error-handler": "^4.4|^5.0",

0 commit comments

Comments
 (0)
0