Skip to content

Navigation Menu

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

[Mailer][Notifier] Add and use Dsn::getBooleanOption() #59477

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
Jan 12, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function create(Dsn $dsn): TransportInterface
$user = $this->getUser($dsn);
$password = $this->getPassword($dsn);
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$sandbox = filter_var($dsn->getOption('sandbox', false), \FILTER_VALIDATE_BOOL);
$sandbox = $dsn->getBooleanOption('sandbox');

if ('mailjet+api' === $scheme) {
return (new MailjetApiTransport($user, $password, $this->client, $this->dispatcher, $this->logger, $sandbox))->setHost($host);
Expand Down
2 changes: 1 addition & 1 deletion 2 src/Symfony/Component/Mailer/Bridge/Mailjet/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
],
"require": {
"php": ">=8.2",
"symfony/mailer": "^7.2"
"symfony/mailer": "^7.3"
},
"require-dev": {
"symfony/http-client": "^6.4|^7.0",
Expand Down
1 change: 1 addition & 0 deletions 1 src/Symfony/Component/Mailer/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ CHANGELOG
---

* Add DSN param `retry_period` to override default email transport retry period
* Add `Dsn::getBooleanOption()`
fabpot marked this conversation as resolved.
Show resolved Hide resolved

7.2
---
Expand Down
25 changes: 25 additions & 0 deletions 25 src/Symfony/Component/Mailer/Tests/Transport/DsnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -105,4 +105,29 @@ public static function invalidDsnProvider(): iterable
'The mailer DSN must contain a host (use "default" by default).',
];
}

/**
* @dataProvider getBooleanOptionProvider
*/
public function testGetBooleanOption(bool $expected, string $dsnString, string $option, bool $default)
{
$dsn = Dsn::fromString($dsnString);

$this->assertSame($expected, $dsn->getBooleanOption($option, $default));
}

public static function getBooleanOptionProvider(): iterable
{
yield [true, 'scheme://localhost?enabled=1', 'enabled', false];
yield [true, 'scheme://localhost?enabled=true', 'enabled', false];
yield [true, 'scheme://localhost?enabled=on', 'enabled', false];
yield [true, 'scheme://localhost?enabled=yes', 'enabled', false];
yield [false, 'scheme://localhost?enabled=0', 'enabled', false];
yield [false, 'scheme://localhost?enabled=false', 'enabled', false];
yield [false, 'scheme://localhost?enabled=off', 'enabled', false];
yield [false, 'scheme://localhost?enabled=no', 'enabled', false];

yield [false, 'scheme://localhost', 'not_existant', false];
yield [true, 'scheme://localhost', 'not_existant', true];
}
}
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/Mailer/Transport/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,9 @@ public function getOption(string $key, mixed $default = null): mixed
{
return $this->options[$key] ?? $default;
}

public function getBooleanOption(string $key, bool $default = false): bool
{
return filter_var($this->getOption($key, $default), \FILTER_VALIDATE_BOOLEAN);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ public function create(Dsn $dsn): IsendproTransport

$keyid = $this->getUser($dsn);
$from = $dsn->getOption('from', null);
$noStop = filter_var($dsn->getOption('no_stop', false), \FILTER_VALIDATE_BOOLEAN);
$sandbox = filter_var($dsn->getOption('sandbox', false), \FILTER_VALIDATE_BOOLEAN);
$noStop = $dsn->getBooleanOption('no_stop');
$sandbox = $dsn->getBooleanOption('sandbox');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
"require": {
"php": ">=8.2",
"symfony/http-client": "^6.4|^7.0",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"require-dev": {
"symfony/event-dispatcher": "^6.4|^7.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function create(Dsn $dsn): OvhCloudTransport
$consumerKey = $dsn->getRequiredOption('consumer_key');
$serviceName = $dsn->getRequiredOption('service_name');
$sender = $dsn->getOption('sender');
$noStopClause = filter_var($dsn->getOption('no_stop_clause', false), \FILTER_VALIDATE_BOOL);
$noStopClause = $dsn->getBooleanOption('no_stop_clause');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.2",
"symfony/http-client": "^6.4|^7.0",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\OvhCloud\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public function create(Dsn $dsn): SmsBiurasTransport
$uid = $this->getUser($dsn);
$apiKey = $this->getPassword($dsn);
$from = $dsn->getRequiredOption('from');
$testMode = filter_var($dsn->getOption('test_mode', false), \FILTER_VALIDATE_BOOL);
$testMode = $dsn->getBooleanOption('test_mode');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$port = $dsn->getPort();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.2",
"symfony/http-client": "^6.4|^7.0",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\SmsBiuras\\": "" },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ public function create(Dsn $dsn): SmsapiTransport
$authToken = $this->getUser($dsn);
$from = $dsn->getOption('from', '');
$host = 'default' === $dsn->getHost() ? null : $dsn->getHost();
$fast = filter_var($dsn->getOption('fast', false), \FILTER_VALIDATE_BOOL);
$test = filter_var($dsn->getOption('test', false), \FILTER_VALIDATE_BOOL);
$fast = $dsn->getBooleanOption('fast');
$test = $dsn->getBooleanOption('test');
$port = $dsn->getPort();

return (new SmsapiTransport($authToken, $from, $this->client, $this->dispatcher))->setFast($fast)->setHost($host)->setPort($port)->setTest($test);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"require": {
"php": ">=8.2",
"symfony/http-client": "^6.4|^7.0",
"symfony/notifier": "^7.2"
"symfony/notifier": "^7.3"
},
"autoload": {
"psr-4": { "Symfony\\Component\\Notifier\\Bridge\\Smsapi\\": "" },
Expand Down
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/Notifier/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
CHANGELOG
=========

7.3
---

* Add `Dsn::getBooleanOption()`
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* Add `Dsn::getBooleanOption()`
* Add `Dsn::getBooleanOption()` method

Copy link
Member

Choose a reason for hiding this comment

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

No need, the current wording is more correct


7.2
---

Expand Down
25 changes: 25 additions & 0 deletions 25 src/Symfony/Component/Notifier/Tests/Transport/DsnTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,4 +259,29 @@ public static function getRequiredOptionThrowsMissingRequiredOptionExceptionProv
'with_empty_string',
];
}

/**
* @dataProvider getBooleanOptionProvider
*/
public function testGetBooleanOption(bool $expected, string $dsnString, string $option, bool $default)
{
$dsn = new Dsn($dsnString);

$this->assertSame($expected, $dsn->getBooleanOption($option, $default));
}

public static function getBooleanOptionProvider(): iterable
{
yield [true, 'scheme://localhost?enabled=1', 'enabled', false];
yield [true, 'scheme://localhost?enabled=true', 'enabled', false];
yield [true, 'scheme://localhost?enabled=on', 'enabled', false];
yield [true, 'scheme://localhost?enabled=yes', 'enabled', false];
yield [false, 'scheme://localhost?enabled=0', 'enabled', false];
yield [false, 'scheme://localhost?enabled=false', 'enabled', false];
yield [false, 'scheme://localhost?enabled=off', 'enabled', false];
yield [false, 'scheme://localhost?enabled=no', 'enabled', false];

yield [false, 'scheme://localhost', 'not_existant', false];
yield [true, 'scheme://localhost', 'not_existant', true];
}
}
5 changes: 5 additions & 0 deletions 5 src/Symfony/Component/Notifier/Transport/Dsn.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,11 @@ public function getRequiredOption(string $key): mixed
return $this->options[$key];
}

public function getBooleanOption(string $key, bool $default = false): bool
{
return filter_var($this->getOption($key, $default), \FILTER_VALIDATE_BOOLEAN);
}

public function getOptions(): array
{
return $this->options;
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.