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

[Mime] Deprecate Address::fromString() #37175

New issue

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
Jun 9, 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
5 changes: 5 additions & 0 deletions 5 UPGRADE-5.2.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
UPGRADE FROM 5.1 to 5.2
=======================

Mime
----

* Deprecated `Address::fromString()`, use `Address::create()` instead

Validator
---------

Expand Down
5 changes: 5 additions & 0 deletions 5 UPGRADE-6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ Messenger
* The signature of method `RetryStrategyInterface::isRetryable()` has been updated to `RetryStrategyInterface::isRetryable(Envelope $message, \Throwable $throwable = null)`.
* The signature of method `RetryStrategyInterface::getWaitingTime()` has been updated to `RetryStrategyInterface::getWaitingTime(Envelope $message, \Throwable $throwable = null)`.

Mime
----

* Removed `Address::fromString()`, use `Address::create()` instead

OptionsResolver
---------------

Expand Down
17 changes: 15 additions & 2 deletions 17 src/Symfony/Component/Mime/Address.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,15 @@ public static function create($address): self
return $address;
}
if (\is_string($address)) {
return self::fromString($address);
if (false === strpos($address, '<')) {
return new self($address);
}

if (!preg_match(self::FROM_STRING_PATTERN, $address, $matches)) {
throw new InvalidArgumentException(sprintf('Could not parse "%s" to a "%s" instance.', $address, self::class));
}

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

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

/**
* @deprecated since Symfony 5.2, use "create()" instead.
*/
public static function fromString(string $string): self
{
trigger_deprecation('symfony/mime', '5.2', '"%s()" is deprecated, use "%s::create()" instead.', __METHOD__, __CLASS__);

if (false === strpos($string, '<')) {
return new self($string, '');
}

if (!preg_match(self::FROM_STRING_PATTERN, $string, $matches)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we change this to call ::create instead of duplicating the logic ?

throw new InvalidArgumentException(sprintf('Could not parse "%s" to a "%s" instance.', $string, static::class));
throw new InvalidArgumentException(sprintf('Could not parse "%s" to a "%s" instance.', $string, self::class));
}

return new self($matches['addrSpec'], trim($matches['displayName'], ' \'"'));
Expand Down
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/Mime/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

5.2.0
-----

* Deprecated `Address::fromString()`, use `Address::create()` instead

4.4.0
-----

Expand Down
17 changes: 17 additions & 0 deletions 17 src/Symfony/Component/Mime/Tests/AddressTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ public function testCreate()
$this->assertEquals($a, Address::create('fabien@symfony.com'));
}

/**
* @dataProvider fromStringProvider
*/
public function testCreateWithString($string, $displayName, $addrSpec)
{
$address = Address::create($string);
$this->assertEquals($displayName, $address->getName());
$this->assertEquals($addrSpec, $address->getAddress());
$fromToStringAddress = Address::create($address->toString());
$this->assertEquals($displayName, $fromToStringAddress->getName());
$this->assertEquals($addrSpec, $fromToStringAddress->getAddress());
}

public function testCreateWrongArg()
{
$this->expectException(\InvalidArgumentException::class);
Expand Down Expand Up @@ -81,6 +94,7 @@ public function nameEmptyDataProvider(): array

/**
* @dataProvider fromStringProvider
* @group legacy
*/
public function testFromString($string, $displayName, $addrSpec)
{
Expand All @@ -92,6 +106,9 @@ public function testFromString($string, $displayName, $addrSpec)
$this->assertEquals($addrSpec, $fromToStringAddress->getAddress());
}

/**
* @group legacy
*/
public function testFromStringFailure()
{
$this->expectException(InvalidArgumentException::class);
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/Mime/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
],
"require": {
"php": ">=7.2.5",
"symfony/deprecation-contracts": "^2.1",
"symfony/polyfill-intl-idn": "^1.10",
"symfony/polyfill-mbstring": "^1.0",
"symfony/polyfill-php80": "^1.15"
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.