Skip to content

Commit c0831f9

Browse files
committed
feature #37175 [Mime] Deprecate Address::fromString() (fabpot)
This PR was merged into the 5.2-dev branch. Discussion ---------- [Mime] Deprecate Address::fromString() | Q | A | ------------- | --- | Branch? | master <!-- see below --> | Bug fix? | no | New feature? | no <!-- please update src/**/CHANGELOG.md files --> | Deprecations? | yes <!-- please update UPGRADE-*.md and src/**/CHANGELOG.md files --> | Tickets | n/a <!-- prefix each issue number with "Fix #", if any --> | License | MIT | Doc PR | n/a Follow-up of #37167 Commits ------- 6e28fda [Mime] Deprecate Address::fromString()
2 parents 61d79e1 + 6e28fda commit c0831f9

File tree

6 files changed

+48
-2
lines changed

6 files changed

+48
-2
lines changed

UPGRADE-5.2.md

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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

Lines 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)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy