package and depencies
This commit is contained in:
45
vendor/symfony/mime/Address.php
vendored
45
vendor/symfony/mime/Address.php
vendored
@@ -33,11 +33,11 @@ final class Address
|
||||
*/
|
||||
private const FROM_STRING_PATTERN = '~(?<displayName>[^<]*)<(?<addrSpec>.*)>[^>]*~';
|
||||
|
||||
private static $validator;
|
||||
private static $encoder;
|
||||
private static EmailValidator $validator;
|
||||
private static IdnAddressEncoder $encoder;
|
||||
|
||||
private $address;
|
||||
private $name;
|
||||
private string $address;
|
||||
private string $name;
|
||||
|
||||
public function __construct(string $address, string $name = '')
|
||||
{
|
||||
@@ -45,9 +45,7 @@ final class Address
|
||||
throw new LogicException(sprintf('The "%s" class cannot be used as it needs "%s"; try running "composer require egulias/email-validator".', __CLASS__, EmailValidator::class));
|
||||
}
|
||||
|
||||
if (null === self::$validator) {
|
||||
self::$validator = new EmailValidator();
|
||||
}
|
||||
self::$validator ??= new EmailValidator();
|
||||
|
||||
$this->address = trim($address);
|
||||
$this->name = trim(str_replace(["\n", "\r"], '', $name));
|
||||
@@ -69,9 +67,7 @@ final class Address
|
||||
|
||||
public function getEncodedAddress(): string
|
||||
{
|
||||
if (null === self::$encoder) {
|
||||
self::$encoder = new IdnAddressEncoder();
|
||||
}
|
||||
self::$encoder ??= new IdnAddressEncoder();
|
||||
|
||||
return self::$encoder->encodeString($this->address);
|
||||
}
|
||||
@@ -90,20 +86,13 @@ final class Address
|
||||
return sprintf('"%s"', preg_replace('/"/u', '\"', $this->getName()));
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Address|string $address
|
||||
*/
|
||||
public static function create($address): self
|
||||
public static function create(self|string $address): self
|
||||
{
|
||||
if ($address instanceof self) {
|
||||
return $address;
|
||||
}
|
||||
|
||||
if (!\is_string($address)) {
|
||||
throw new InvalidArgumentException(sprintf('An address can be an instance of Address or a string ("%s" given).', get_debug_type($address)));
|
||||
}
|
||||
|
||||
if (false === strpos($address, '<')) {
|
||||
if (!str_contains($address, '<')) {
|
||||
return new self($address);
|
||||
}
|
||||
|
||||
@@ -128,22 +117,4 @@ final class Address
|
||||
|
||||
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 (!str_contains($string, '<')) {
|
||||
return new self($string, '');
|
||||
}
|
||||
|
||||
if (!preg_match(self::FROM_STRING_PATTERN, $string, $matches)) {
|
||||
throw new InvalidArgumentException(sprintf('Could not parse "%s" to a "%s" instance.', $string, self::class));
|
||||
}
|
||||
|
||||
return new self($matches['addrSpec'], trim($matches['displayName'], ' \'"'));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user