8000 [Mailer][Notifier] Add and use `Dsn::getBooleanOption()` · symfony/symfony@67514f8 · GitHub
[go: up one dir, main page]

Skip to content

Commit 67514f8

Browse files
OskarStarkfabpot
authored andcommitted
[Mailer][Notifier] Add and use Dsn::getBooleanOption()
1 parent dfcc142 commit 67514f8

File tree

16 files changed

+78
-12
lines changed

16 files changed

+78
-12
lines changed

src/Symfony/Component/Mailer/Bridge/Mailjet/Transport/MailjetTransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public function create(Dsn $dsn): TransportInterface
2424
$user = $this->getUser($dsn);
2525
$password = $this->getPassword($dsn);
2626
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
27-
$sandbox = filter_var($dsn->getOption('sandbox', false), \FILTER_VALIDATE_BOOL);
27+
$sandbox = $dsn->getBooleanOption('sandbox');
2828

2929
if ('mailjet+api' === $scheme) {
3030
return (new MailjetApiTransport($user, $password, $this->client, $this->dispatcher, $this->logger, $sandbox))->setHost($host);

src/Symfony/Component/Mailer/Bridge/Mailjet/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
],
1818
"require": {
1919
"php": ">=8.2",
20-
"symfony/mailer": "^7.2"
20+
"symfony/mailer": "^7.3"
2121
},
2222
"require-dev": {
2323
"symfony/http-client": "^6.4|^7.0",

src/Symfony/Component/Mailer/CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ CHANGELOG
55
---
66

77
* Add DSN param `retry_period` to override default email transport retry period
8+
* Add `Dsn::getBooleanOption()`
89

910
7.2
1011
---

src/Symfony/Component/Mailer/Tests/Transport/DsnTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,4 +105,29 @@ public static function invalidDsnProvider(): iterable
105105
'The mailer DSN must contain a host (use "default" by default).',
106106
];
107107
}
108+
109+
/**
110+
* @dataProvider getBooleanOptionProvider
111+
*/
112+
public function testGetBooleanOption(bool $expected, string $dsnString, string $option, bool $default)
113+
{
114+
$dsn = Dsn::fromString($dsnString);
115+
116+
$this->assertSame($expected, $dsn->getBooleanOption($option, $default));
117+
}
118+
119+
public static function getBooleanOptionProvider(): iterable
120+
{
121+
yield [true, 'scheme://localhost?enabled=1', 'enabled', false];
122+
yield [true, 'scheme://localhost?enabled=true', 'enabled', false];
123+
yield [true, 'scheme://localhost?enabled=on', 'enabled', false];
124+
yield [true, 'scheme://localhost?enabled=yes', 'enabled', false];
125+
yield [false, 'scheme://localhost?enabled=0', 'enabled', false];
126+
yield [false, 'scheme://localhost?enabled=false', 'enabled', false];
127+
yield [false, 'scheme://localhost?enabled=off', 'enabled', false];
128+
yield [false, 'scheme://localhost?enabled=no', 'enabled', false];
129+
130+
yield [false, 'scheme://localhost', 'not_existant', false];
131+
yield [true, 'scheme://localhost', 'not_existant', true];
132+
}
108133
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,4 +79,9 @@ public function getOption(string $key, mixed $default = null): mixed
7979
{
8080
return $this->options[$key] ?? $default;
8181
}
82+
83+
public function getBooleanOption(string $key, bool $default = false): bool
84+
{
85+
return filter_var($this->getOption($key, $default), \FILTER_VALIDATE_BOOLEAN);
86+
}
8287
}

src/Symfony/Component/Notifier/Bridge/Isendpro/IsendproTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ public function create(Dsn $dsn): IsendproTransport
2525

2626
$keyid = $this->getUser($dsn);
2727
$from = $dsn->getOption('from', null);
28-
$noStop = filter_var($dsn->getOption('no_stop', false), \FILTER_VALIDATE_BOOLEAN);
29-
$sandbox = filter_var($dsn->getOption('sandbox', false), \FILTER_VALIDATE_BOOLEAN);
28+
$noStop = $dsn->getBooleanOption('no_stop');
29+
$sandbox = $dsn->getBooleanOption('sandbox');
3030
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
3131
$port = $dsn->getPort();
3232

src/Symfony/Component/Notifier/Bridge/Isendpro/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require": {
2323
"php": ">=8.2",
2424
"symfony/http-client": "^6.4|^7.0",
25-
"symfony/notifier": "^7.2"
25+
"symfony/notifier": "^7.3"
2626
},
2727
"require-dev": {
2828
"symfony/event-dispatcher": "^6.4|^7.0"

src/Symfony/Component/Notifier/Bridge/OvhCloud/OvhCloudTransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function create(Dsn $dsn): OvhCloudTransport
3333
$consumerKey = $dsn->getRequiredOption('consumer_key');
3434
$serviceName = $dsn->getRequiredOption('service_name');
3535
$sender = $dsn->getOption('sender');
36-
$noStopClause = filter_var($dsn->getOption('no_stop_clause', false), \FILTER_VALIDATE_BOOL);
36+
$noStopClause = $dsn->getBooleanOption('no_stop_clause');
3737
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
3838
$port = $dsn->getPort();
3939

src/Symfony/Component/Notifier/Bridge/OvhCloud/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=8.2",
2020
"symfony/http-client": "^6.4|^7.0",
21-
"symfony/notifier": "^7.2"
21+
"symfony/notifier": "^7.3"
2222
},
2323
"autoload": {
2424
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },

src/Symfony/Component/Notifier/Bridge/SmsBiuras/SmsBiurasTransportFactory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function create(Dsn $dsn): SmsBiurasTransport
3131
$uid = $this->getUser($dsn);
3232
$apiKey = $this->getPassword($dsn);
3333
$from = $dsn->getRequiredOption('from');
34-
$testMode = filter_var($dsn->getOption('test_mode', false), \FILTER_VALIDATE_BOOL);
34+
$testMode = $dsn->getBooleanOption('test_mode');
3535
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
3636
$port = $dsn->getPort();
3737

src/Symfony/Component/Notifier/Bridge/SmsBiuras/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=8.2",
2020
"symfony/http-client": "^6.4|^7.0",
21-
"symfony/notifier": "^7.2"
21+
"symfony/notifier": "^7.3"
2222
},
2323
"autoload": {
2424
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\SmsBiuras\\": "" },

src/Symfony/Component/Notifier/Bridge/Smsapi/SmsapiTransportFactory.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@ public function create(Dsn $dsn): SmsapiTransport
3131
$authToken = $this->getUser($dsn);
3232
$from = $dsn->getOption('from', '');
3333
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
34-
$fast = filter_var($dsn->getOption('fast', F438 false), \FILTER_VALIDATE_BOOL);
35-
$test = filter_var($dsn->getOption('test', false), \FILTER_VALIDATE_BOOL);
34+
$fast = $dsn->getBooleanOption('fast');
35+
$test = $dsn->getBooleanOption('test');
3636
$port = $dsn->getPort();
3737

3838
return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))->setFast($fast)->setHost($host)->setPort($port)->setTest($test);

src/Symfony/Component/Notifier/Bridge/Smsapi/composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"require": {
1919
"php": ">=8.2",
2020
"symfony/http-client": "^6.4|^7.0",
21-
"symfony/notifier": "^7.2"
21+
"symfony/notifier": "^7.3"
2222
},
2323
"autoload": {
2424
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsapi\\": "" },

src/Symfony/Component/Notifier/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+
7.3
5+
---
6+
7+
* Add `Dsn::getBooleanOption()`
8+
49
7.2
510
---
611

src/Symfony/Component/Notifier/Tests/Transport/DsnTest.php

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,4 +259,29 @@ public static function getRequiredOptionThrowsMissingRequiredOptionExceptionProv
259259
'with_empty_string',
260260
];
261261
}
262+
263+
/**
264+
* @dataProvider getBooleanOptionProvider
265+
*/
266+
public function testGetBooleanOption(bool $expected, string $dsnString, string $option, bool $default)
267+
{
268+
$dsn = new Dsn($dsnString);
269+
270+
$this->assertSame($expected, $dsn->getBooleanOption($option, $default));
271+
}
272+
273+
public static function getBooleanOptionProvider(): iterable
274+
{
275+
yield [true, 'scheme://localhost?enabled=1', 'enabled', false];
276+
yield [true, 'scheme://localhost?enabled=true', 'enabled', false];
277+
yield [true, 'scheme://localhost?enabled=on', 'enabled', false];
278+
yield [true, 'scheme://localhost?enabled=yes', 'enabled', false];
279+
yield [false, 'scheme://localhost?enabled=0', 'enabled', false];
280+
yield [false, 'scheme://localhost?enabled=false', 'enabled', false];
281+
yield [false, 'scheme://localhost?enabled=off', 'enabled', false];
282+
yield [false, 'scheme://localhost?enabled=no', 'enabled', false];
283+
284+
yield [false, 'scheme://localhost', 'not_existant', false];
285+
yield [true, 'scheme://localhost', 'not_existant', true];
286+
}
262287
}

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ public function getRequiredOption(string $key): mixed
9393
return $this->options[$key];
9494
}
9595

96+
public function getBooleanOption(string $key, bool $default = false): bool
97+
{
98+
return filter_var($this->getOption($key, $default), \FILTER_VALIDATE_BOOLEAN);
99+
}
100+
96101
public function getOptions(): array
97102
{
98103
return $this->options;

0 commit comments

Comments
 (0)
0