8000 Adding "toString" functions · symfony/symfony@d01c068 · GitHub
[go: up one dir, main page]

Skip to content

Commit d01c068

Browse files
committed
Adding "toString" functions
1 parent 4e705f1 commit d01c068

File tree

6 files changed

+51
-4
lines changed

6 files changed

+51
-4
lines changed

src/Symfony/Component/Dsn/Configuration/Dsn.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,4 +76,12 @@ public function getPassword(): ?string
7676
{
7777
return null;
7878
}
79+
80+
/**
81+
* @var string
82+
*/
83+
public function __toString()
84+
{
85+
return sprintf('%s://%s', $this->getScheme(), empty($this->parameters) ? '' : '?'.http_build_query($this->parameters));
86+
}
7987
}

src/Symfony/Component/Dsn/Configuration/DsnFunction.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,4 +75,12 @@ public function first()
7575
{
7676
return reset($this->arguments);
7777
}
78+
79+
/**
80+
* @return string
81+
*/
82+
public function __toString()
83+
{
84+
return sprintf('%s(%s)%s', $this->getName(), implode(' ', $this->getArguments()), empty($this->parameters) ? '' : '?'.http_build_query($this->parameters));
85+
}
7886
}

src/Symfony/Component/Dsn/Configuration/Path.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class Path extends Dsn
3030
*/
3131
private $path;
3232

33-
public function __construct(?string $scheme, string $path, array $parameters = [], array $authentication = [])
33+
public function __construct(string $scheme, string $path, array $parameters = [], array $authentication = [])
3434
{
3535
$this->path = $path;
3636
$this->setAuthentication($authentication);
@@ -41,4 +41,14 @@ public function getPath(): string
4141
{
4242
return $this->path;
4343
}
44+
45+
/**
46+
* @var string
47+
*/
48+
public function __toString()
49+
{
50+
$parameters = $this->getParameters();
51+
52+
return sprintf('%s://%s%s%s', $this->getScheme(), $this->getUserInfoString(), $this->getPath(), empty($parameters) ? '' : '?'.http_build_query($parameters));
53+
}
4454
}

src/Symfony/Component/Dsn/Configuration/Url.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,4 +63,14 @@ public function getPath(): ?string
6363
{
6464
return $this->path;
6565
}
66+
67+
/**
68+
* @var string
69+
*/
70+
public function __toString()
71+
{
72+
$parameters = $this->getParameters();
73+
74+
return sprintf('%s://%s%s%s%s', $this->getScheme(), $this->getUserInfoString(), $this->getHost(), empty($this->port) ? '' : ':'.$this->port, empty($parameters) ? '' : '?'.http_build_query($parameters));
75+
}
6676
}

src/Symfony/Component/Dsn/Configuration/UserPasswordTrait.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,16 @@ public function getPassword(): ?string
4747
{
4848
return $this->authentication['password'] ?? null;
4949
}
50+
51+
private function getUserInfoString(): string
52+
{
67ED
53+
$user = $this->getUser() ?? '';
54+
$password = $this->getPassword() ?? '';
55+
$userInfo = $user.(empty($password) ? '' : ':'.$password).'@';
56+
if (\strlen($userInfo) <= 2) {
57+
$userInfo = '';
58+
}
59+
60+
return $userInfo;
61+
}
5062
}

src/Symfony/Component/Mailer/Transport.php

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
use Symfony\Contracts\EventDispatcher\EventDispatcherInterface;
3636
use Symfony\Contracts\HttpClient\HttpClientInterface;
3737

38-
3938
/**
4039
* @author Fabien Potencier <fabien@symfony.com>
4140
* @author Konstantin Myakshin <molodchick@gmail.com>
@@ -90,7 +89,7 @@ public function fromString(string $dsn): TransportInterface
9089
return self::fromDsnComponent(DsnParser::parse($dsn));
9190
}
9291

93-
private function fromDsnComponent($dsn) : TransportInterface
92+
private function fromDsnComponent($dsn): TransportInterface
9493
{
9594
static $keywords = [
9695
'failover' => FailoverTransport::class,
@@ -102,7 +101,7 @@ private function fromDsnComponent($dsn) : TransportInterface
102101
}
103102

104103
if (!$dsn instanceof DsnFunction) {
105-
throw new \InvalidArgumentException(\sprintf('First argument to Transport::fromDsnComponent() must be a "%s" or %s', DsnFunction::class, Dsn::class));
104+
throw new \InvalidArgumentException(sprintf('First argument to Transport::fromDsnComponent() must be a "%s" or "%s".', DsnFunction::class, Dsn::class));
106105
}
107106

108107
if (!isset($keywords[$dsn->getName()])) {

0 commit comments

Comments
 (0)
0