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 6e28fda

Browse filesBrowse files
committed
[Mime] Deprecate Address::fromString()
1 parent 61d79e1 commit 6e28fda
Copy full SHA for 6e28fda

File tree

6 files changed

+48
-2
lines changed
Filter options

6 files changed

+48
-2
lines changed

‎UPGRADE-5.2.md

Copy file name to clipboardExpand all lines: UPGRADE-5.2.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
UPGRADE FROM 5.1 to 5.2
22
=======================
33

4+
Mime
5+
----
6+
7+
* Deprecated `Address::fromString()`, use `Address::create()` instead
8+
49
Validator
510
---------
611

‎UPGRADE-6.0.md

Copy file name to clipboardExpand all lines: UPGRADE-6.0.md
+5Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ Messenger
8989
* The signature of method `RetryStrategyInterface::isRetryable()` has been updated to `RetryStrategyInterface::isRetryable(Envelope $message, \Throwable $throwable = null)`.
9090
* The signature of method `RetryStrategyInterface::getWaitingTime()` has been updated to `RetryStrategyInterface::getWaitingTime(Envelope $message, \Throwable $throwable = null)`.
9191

92+
Mime
93+
----
94+
95+
* Removed `Address::fromString()`, use `Address::create()` instead
96+
9297
OptionsResolver
9398
---------------
9499

‎src/Symfony/Component/Mime/Address.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Address.php
+15-2Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,15 @@ public static function create($address): self
8989
return $address;
9090
}
9191
if (\is_string($address)) {
92-
return self::fromString($address);
92+
if (false === strpos($address, '<')) {
93+
return new self($address);
94+
}
95+
96+
if (!preg_match(self::FROM_STRING_PATTERN, $address, $matches)) {
97+
throw new InvalidArgumentException(sprintf('Could not parse "%s" to a "%s" instance.', $address, self::class));
98+
}
99+
100+
return new self($matches['addrSpec'], trim($matches['displayName'], ' \'"'));
93101
}
94102

95103
throw new InvalidArgumentException(sprintf('An address can be an instance of Address or a string ("%s" given).', get_debug_type($address)));
@@ -110,14 +118,19 @@ public static function createArray(array $addresses): array
110118
return $addrs;
111119
}
112120

121+
/**
122+
* @deprecated since Symfony 5.2, use "create()" instead.
123+
*/
113124
public static function fromString(string $string): self
114125
{
126+
trigger_deprecation('symfony/mime', '5.2', '"%s()" is deprecated, use "%s::create()" instead.', __METHOD__, __CLASS__);
127+
115128
if (false === strpos($string, '<')) {
116129
return new self($string, '');
117130
}
118131

119132
if (!preg_match(self::FROM_STRING_PATTERN, $string, $matches)) {
120-
throw new InvalidArgumentException(sprintf('Could not parse "%s" to a "%s" instance.', $string, static::class));
133+
throw new InvalidArgumentException(sprintf('Could not parse "%s" to a "%s" instance.', $string, self::class));
121134
}
122135

123136
return new self($matches['addrSpec'], trim($matches['displayName'], ' \'"'));

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/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+
5.2.0
5+
-----
6+
7+
* Deprecated `Address::fromString()`, use `Address::create()` instead
8+
49
4.4.0
510
-----
611

‎src/Symfony/Component/Mime/Tests/AddressTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/Tests/AddressTest.php
+17Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,19 @@ public function testCreate()
4444
$this->assertEquals($a, Address::create('fabien@symfony.com'));
4545
}
4646

47+
/**
48+
* @dataProvider fromStringProvider
49+
*/
50+
public function testCreateWithString($string, $displayName, $addrSpec)
51+
{
52+
$address = Address::create($string);
53+
$this->assertEquals($displayName, $address->getName());
54+
$this->assertEquals($addrSpec, $address->getAddress());
55+
$fromToStringAddress = Address::create($address->toString());
56+
$this->assertEquals($displayName, $fromToStringAddress->getName());
57+
$this->assertEquals($addrSpec, $fromToStringAddress->getAddress());
58+
}
59+
4760
public function testCreateWrongArg()
4861
{
4962
$this->expectException(\InvalidArgumentException::class);
@@ -81,6 +94,7 @@ public function nameEmptyDataProvider(): array
8194

8295
/**
8396
* @dataProvider fromStringProvider
97+
* @group legacy
8498
*/
8599
public function testFromString($string, $displayName, $addrSpec)
86100
{
@@ -92,6 +106,9 @@ public function testFromString($string, $displayName, $addrSpec)
92106
$this->assertEquals($addrSpec, $fromToStringAddress->getAddress());
93107
}
94108

109+
/**
110+
* @group legacy
111+
*/
95112
public function testFromStringFailure()
96113
{
97114
$this->expectException(InvalidArgumentException::class);

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Mime/composer.json
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=7.2.5",
20+
"symfony/deprecation-contracts": "^2.1",
2021
"symfony/polyfill-intl-idn": "^1.10",
2122
"symfony/polyfill-mbstring": "^1.0",
2223
"symfony/polyfill-php80": "^1.15"

0 commit comments

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