Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit cd1dcf3

Browse filesBrowse files
[Contracts/Service] add LazyString with new fromStringable(), isStringable() and resolve() methods
1 parent cc357ad commit cd1dcf3
Copy full SHA for cd1dcf3

File tree

13 files changed

+59
-14
lines changed
Filter options

13 files changed

+59
-14
lines changed

‎composer.json

Copy file name to clipboardExpand all lines: composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"psr/container": "^1.0",
2626
"psr/link": "^1.0",
2727
"psr/log": "~1.0",
28-
"symfony/contracts": "^1.1.7|^2",
28+
"symfony/contracts": "^1.2|^2",
2929
"symfony/polyfill-ctype": "~1.8",
3030
"symfony/polyfill-intl-icu": "~1.0",
3131
"symfony/polyfill-intl-idn": "^1.10",

‎src/Symfony/Component/DependencyInjection/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/CHANGELOG.md
-1Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ CHANGELOG
1313
* made singly-implemented interfaces detection be scoped by file
1414
* added ability to define a static priority method for tagged service
1515
* added support for improved syntax to define method calls in Yaml
16-
* added `LazyString` for lazy computation of string values injected into services
1716
* made the `%env(base64:...)%` processor able to decode base64url
1817

1918
4.3.0

‎src/Symfony/Component/DependencyInjection/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/composer.json
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,11 @@
1818
"require": {
1919
"php": "^7.1.3",
2020
"psr/container": "^1.0",
21-
"symfony/service-contracts": "^1.1.6|^2"
21+
"symfony/service-contracts": "^1.2|^2"
2222
},
2323
"require-dev": {
2424
"symfony/yaml": "^3.4|^4.0|^5.0",
2525
"symfony/config": "^4.3|^5.0",
26-
"symfony/error-handler": "^4.4|^5.0",
2726
"symfony/expression-language": "^3.4|^4.0|^5.0"
2827
},
2928
"suggest": {

‎src/Symfony/Component/HttpClient/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Component/HttpClient/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require": {
2323
"php": "^7.1.3",
2424
"psr/log": "^1.0",
25-
"symfony/http-client-contracts": "^1.1.8|^2",
25+
"symfony/http-client-contracts": "^1.2|^2",
2626
"symfony/polyfill-php73": "^1.11"
2727
},
2828
"require-dev": {

‎src/Symfony/Contracts/CHANGELOG.md

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/CHANGELOG.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
CHANGELOG
22
=========
33

4+
1.2.0
5+
-----
6+
7+
* added `LazyString` for lazy computation of string values injected into services
8+
49
1.1.0
510
-----
611

‎src/Symfony/Contracts/Cache/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Cache/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.1-dev"
31+
"dev-master": "1.2-dev"
3232
}
3333
}
3434
}

‎src/Symfony/Contracts/EventDispatcher/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/EventDispatcher/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.1-dev"
31+
"dev-master": "1.2-dev"
3232
}
3333
}
3434
}

‎src/Symfony/Contracts/HttpClient/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/HttpClient/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"minimum-stability": "dev",
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "1.1-dev"
30+
"dev-master": "1.2-dev"
3131
}
3232
}
3333
}

‎src/Symfony/Component/DependencyInjection/LazyString.php renamed to ‎src/Symfony/Contracts/Service/LazyString.php

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Service/LazyString.php
+42-1Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\DependencyInjection;
12+
namespace Symfony\Contracts\Service;
1313

1414
/**
1515
* A string whose value is computed lazily by a callback.
@@ -49,6 +49,47 @@ public static function fromCallable($callback, ...$arguments): self
4949
return $lazyString;
5050
}
5151

52+
/**
53+
* @param object|string|int|float|bool $value A scalar or an object that implements the __toString() magic method
54+
*
55+
* @return static
56+
*/
57+
public static function fromStringable($value): self
58+
{
59+
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)));
61+
}
62+
63+
if (\is_object($value)) {
64+
return static::fromCallable([$value, '__toString']);
65+
}
66+
67+
$lazyString = new static();
68+
$lazyString->value = (string) $value;
69+
70+
return $lazyString;
71+
}
72+
73+
/**
74+
* Tells whether the provided value can be cast to string.
75+
*/
76+
final public static function isStringable($value): bool
77+
{
78+
return \is_string($value) || $value instanceof self || (\is_object($value) && method_exists($value, '__toString')) || is_scalar($value);
79+
}
80+
81+
/**
82+
* Casts scalars and stringable objects to strings.
83+
*
84+
* @param object|string|int|float|bool $value
85+
*
86+
* @throws \TypeError When the provided value is not stringable
87+
*/
88+
final public static function resolve($value): string
89+
{
90+
return $value;
91+
}
92+
5293
public function __toString()
5394
{
5495
if (\is_string($this->value)) {

‎src/Symfony/Contracts/Service/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Service/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
"minimum-stability": "dev",
2929
"extra": {
3030
"branch-alias": {
31-
"dev-master": "1.1-dev"
31+
"dev-master": "1.2-dev"
3232
}
3333
}
3434
}

‎src/Symfony/Component/DependencyInjection/Tests/LazyStringTest.php renamed to ‎src/Symfony/Contracts/Tests/Service/LazyStringTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Tests/Service/LazyStringTest.php
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\Component\DependencyInjection\Tests;
12+
namespace Symfony\Contracts\Service\Tests;
1313

1414
use PHPUnit\Framework\TestCase;
15-
use Symfony\Component\DependencyInjection\LazyString;
1615
use Symfony\Component\ErrorHandler\ErrorHandler;
16+
use Symfony\Contracts\Service\LazyString;
1717

1818
class LazyStringTest extends TestCase
1919
{

‎src/Symfony/Contracts/Translation/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/Translation/composer.json
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
"minimum-stability": "dev",
2828
"extra": {
2929
"branch-alias": {
30-
"dev-master": "1.1-dev"
30+
"dev-master": "1.2-dev"
3131
}
3232
}
3333
}

‎src/Symfony/Contracts/composer.json

Copy file name to clipboardExpand all lines: src/Symfony/Contracts/composer.json
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"psr/container": "^1.0"
2222
},
2323
"require-dev": {
24+
"symfony/error-handler": "^4.4|^5.0",
2425
"symfony/polyfill-intl-idn": "^1.10"
2526
},
2627
"replace": {
@@ -47,7 +48,7 @@
4748
"minimum-stability": "dev",
4849
"extra": {
4950
"branch-alias": {
50-
"dev-master": "1.1-dev"
51+
"dev-master": "1.2-dev"
5152
}
5253
}
5354
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.