Skip to content

Commit 47a237f

Browse files
committed
Renamed DsnParser::parse() to DsnParser::parseFunc() and DsnParser::parseSimple() to DsnParser::parse()
1 parent 6949081 commit 47a237f

File tree

8 files changed

+27
-24
lines changed

8 files changed

+27
-24
lines changed

src/Symfony/Component/Dsn/DsnParser.php

+7-4
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,12 @@ class DsnParser
3333
private const SUB_DELIMS = '!\$&\'\(\}\*\+,;=';
3434

3535
/**
36+
* Parse A DSN thay may contain functions. If no function is present in the
37+
* string, then a "dsn()" function will be added.
38+
*
3639
* @throws SyntaxException
3740
*/
38-
public static function parse(string $dsn): DsnFunction
41+
public static function parseFunc(string $dsn): DsnFunction
3942
{
4043
// Detect a function or add default function
4144
$parameters = [];
@@ -66,11 +69,11 @@ public static function parse(string $dsn): DsnFunction
6669
* @throws FunctionsNotAllowedException if the DSN contains a function
6770
* @throws SyntaxException
6871
*/
69-
public static function parseSimple(string $dsn): Dsn
72+
public static function parse(string $dsn): Dsn
7073
{
7174
if (1 === preg_match(self::FUNCTION_REGEX, $dsn, $matches)) {
7275
if ('dsn' === $matches[1]) {
73-
return self::parseSimple($matches[2]);
76+
return self::parse($matches[2]);
7477
}
7578
throw new FunctionsNotAllowedException($dsn);
7679
}
@@ -85,7 +88,7 @@ private static function parseArguments(string $dsn)
8588
{
8689
// Detect a function exists
8790
if (1 === preg_match(self::FUNCTION_REGEX, $dsn)) {
88-
return self::parse($dsn);
91+
return self::parseFunc($dsn);
8992
}
9093

9194
// Assert: $dsn does not contain any functions.

src/Symfony/Component/Dsn/Tests/DsnParserTest.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -105,23 +105,23 @@ public function testParse(string $dsn, $expected)
105105
$expected = new DsnFunction('dsn', [$expected]);
106106
}
107107

108-
$result = DsnParser::parse($dsn);
108+
$result = DsnParser::parseFunc($dsn);
109109
$this->assertEquals($expected, $result);
110110
}
111111

112112
public function testParseSimple()
113113
{
114-
$result = DsnParser::parseSimple('amqp://user:pass@localhost:5672/%2f/messages');
114+
$result = DsnParser::parse('amqp://user:pass@localhost:5672/%2f/messages');
115115
$this->assertEquals(new Url('amqp', 'localhost', 5672, '/%2f/messages', [], ['user' => 'user', 'password' => 'pass']), $result);
116116

117-
$result = DsnParser::parseSimple('dsn(amqp://localhost)');
117+
$result = DsnParser::parse('dsn(amqp://localhost)');
118118
$this->assertEquals(new Url('amqp', 'localhost'), $result);
119119
}
120120

121121
public function testParseSimpleWithFunction()
122122
{
123123
$this->expectException(FunctionsNotAllowedException::class);
124-
DsnParser::parseSimple('foo(amqp://localhost)');
124+
DsnParser::parse('foo(amqp://localhost)');
125125
}
126126

127127
/**
@@ -130,6 +130,6 @@ public function testParseSimpleWithFunction()
130130
public function testParseInvalid(string $dsn)
131131
{
132132
$this->expectException(SyntaxException::class);
133-
DsnParser::parse($dsn);
133+
DsnParser::parseFunc($dsn);
134134
}
135135
}

src/Symfony/Component/Dsn/documentation.md

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ roundrobin(dummy://a failover(dummy://b dummy://a) dummy://b)
2828

2929
## Parsing
3030

31-
There are two methods for parsing; `DsnParser::parse()` and `DsnParser::parseSimple()`.
32-
The latter is useful in situations where DSN functions are not needed.
31+
There are two methods for parsing; `DsnParser::parse()` and `DsnParser::parseFunc()`.
32+
The latter is for in situations where DSN functions are supported.
3333

3434
```php
35-
$dsn = DsnParser::parseSimple('scheme://127.0.0.1/foo/bar?key=value');
35+
$dsn = DsnParser::parse('scheme://127.0.0.1/foo/bar?key=value');
3636
echo get_class($dsn); // "Symfony\Component\Dsn\Configuration\Url"
3737
echo $dsn->getHost(); // "127.0.0.1"
3838
echo $dsn->getPath(); // "/foo/bar"
3939
echo $dsn->getPort(); // null
4040
```
4141

42-
If functions are supported (like in the Mailer component) we can use `DsnParser::parse()`:
42+
If functions are supported (like in the Mailer component) we can use `DsnParser::parseFunc()`:
4343

4444
```php
45-
$func = DsnParser::parse('failover(sendgrid://KEY@default smtp://127.0.0.1)');
45+
$func = DsnParser::parseFunc('failover(sendgrid://KEY@default smtp://127.0.0.1)');
4646
echo $func->getName(); // "failover"
4747
echo get_class($func->first()); // "Symfony\Component\Dsn\Configuration\Url"
4848
echo $func->first()->getHost(); // "default"
@@ -51,7 +51,7 @@ echo $func->first()->getUser(); // "KEY"
5151

5252
```php
5353

54-
$func = DsnParser::parse('foo(udp://localhost failover:(tcp://localhost:61616,tcp://remotehost:61616)?initialReconnectDelay=100)?start=now');
54+
$func = DsnParser::parseFunc('foo(udp://localhost failover:(tcp://localhost:61616,tcp://remotehost:61616)?initialReconnectDelay=100)?start=now');
5555
echo $func->getName(); // "foo"
5656
echo $func->getParameters()['start']; // "now"
5757
$args = $func->getArguments();
@@ -62,21 +62,21 @@ echo $args[0]->getHost(); // "localhost"
6262
echo get_class($args[1]); // "Symfony\Component\Dsn\Configuration\DsnFunction"
6363
```
6464

65-
When using `DsnParser::parse()` on a string that does not contain any DSN functions,
65+
When using `DsnParser::parseFunc()` on a string that does not contain any DSN functions,
6666
the parser will automatically add a default "dsn" function. This is added to provide
6767
a consistent return type of the method.
6868

6969
The string `redis://127.0.0.1` will automatically be converted to `dsn(redis://127.0.0.1)`
70-
when using `DsnParser::parse()`.
70+
when using `DsnParser::parseFunc()`.
7171

7272
```php
73-
$func = DsnParser::parse('smtp://127.0.0.1');
73+
$func = DsnParser::parseFunc('smtp://127.0.0.1');
7474
echo $func->getName(); // "dsn"
7575
echo get_class($func->first()); // "Symfony\Component\Dsn\Configuration\Url"
7676
echo $func->first()->getHost(); // "127.0.0.1"
7777

7878

79-
$func = DsnParser::parse('dsn(smtp://127.0.0.1)');
79+
$func = DsnParser::parseFunc('dsn(smtp://127.0.0.1)');
8080
echo $func->getName(); // "dsn"
8181
echo get_class($func->first()); // "Symfony\Component\Dsn\Configuration\Url"
8282
echo $func->first()->getHost(); // "127.0.0.1"

src/Symfony/Component/Mailer/Transport.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function fromStrings(array $dsns): Transports
8686

8787
public function fromString(string $dsn): TransportInterface
8888
{
89-
return self::fromDsnComponent(DsnParser::parse($dsn));
89+
return self::fromDsnComponent(DsnParser::parseFunc($dsn));
9090
}
9191

9292
private function fromDsnComponent($dsn): TransportInterface

src/Symfony/Component/Mailer/Transport/Dsn.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public function __construct(string $scheme, string $host, ?string $user = null,
4141

4242
public static function fromString(string $dsnString): self
4343
{
44-
$dsn = DsnParser::parseSimple($dsnString);
44+
$dsn = DsnParser::parse($dsnString);
4545
if (!$dsn instanceof Url) {
4646
throw new InvalidArgumentException(sprintf('The "%s" mailer DSN is invalid.', $dsnString), 0, DsnTypeNotSupported::onlyUrl($dsnString));
4747
}

src/Symfony/Component/Messenger/Bridge/AmazonSqs/Transport/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ public function __destruct()
8686
*/
8787
public static function fromDsn(string $dsnString, array $options = [], HttpClientInterface $client = null): self
8888
{
89-
$dsn = DsnParser::parseSimple($dsnString);
89+
$dsn = DsnParser::parse($dsnString);
9090
$query = $dsn->getParameters();
9191

9292
$configuration = [

src/Symfony/Component/Messenger/Bridge/Amqp/Transport/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public function __construct(array $connectionOptions, array $exchangeOptions, ar
164164
*/
165165
public static function fromDsn(string $dsnString, array $options = [], AmqpFactory $amqpFactory = null): self
166166
{
167-
$dsn = DsnParser::parseSimple($dsnString);
167+
$dsn = DsnParser::parse($dsnString);
168168
if ('amqp' !== $dsn->getScheme()) {
169169
throw new InvalidArgumentException(sprintf('The given AMQP DSN "%s" is invalid.', $dsn));
170170
}

src/Symfony/Component/Messenger/Bridge/Redis/Transport/Connection.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public function __construct(array $configuration, array $connectionCredentials =
9292

9393
public static function fromDsn(string $dsnString, array $redisOptions = [], \Redis $redis = null): self
9494
{
95-
$dsn = DsnParser::parseSimple($dsnString);
95+
$dsn = DsnParser::parse($dsnString);
9696
if (!empty($dsn->getParameters())) {
9797
$redisOptions = $dsn->getParameters();
9898
}

0 commit comments

Comments
 (0)