Skip to content

Commit 4904546

Browse files
committed
DkimSigner::__construct() $options changed to parameters (BC break)
1 parent 1943767 commit 4904546

7 files changed

+16
-22
lines changed

src/Bridges/MailDI/MailExtension.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public function getConfigSchema(): Nette\Schema\Schema
3535
'dkim' => Expect::anyOf(
3636
Expect::null(),
3737
Expect::structure([
38-
'domain' => Expect::string()->dynamic(),
39-
'selector' => Expect::string()->dynamic(),
38+
'domain' => Expect::string()->required()->dynamic(),
39+
'selector' => Expect::string()->required()->dynamic(),
4040
'privateKey' => Expect::string()->required(),
4141
'passPhrase' => Expect::string()->dynamic(),
4242
])->castTo('array'),
@@ -59,7 +59,7 @@ public function loadConfiguration()
5959

6060
$signer = $builder->addDefinition($this->prefix('signer'))
6161
->setType(Nette\Mail\Signer::class)
62-
->setFactory(Nette\Mail\DkimSigner::class, [$dkim]);
62+
->setFactory(Nette\Mail\DkimSigner::class, $dkim);
6363

6464
$mailer->addSetup('setSigner', [$signer]);
6565
}

src/Mail/DkimSigner.php

+7-15
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,19 @@ class DkimSigner implements Signer
2727
];
2828

2929
private const DkimSignature = 'DKIM-Signature';
30-
private string $domain;
31-
private array $signHeaders;
32-
private string $selector;
33-
private string $privateKey;
34-
private string $passPhrase;
3530

3631

3732
/** @throws Nette\NotSupportedException */
38-
public function __construct(array $options, array $signHeaders = self::DefaultSignHeaders)
39-
{
33+
public function __construct(
34+
private string $domain,
35+
private string $selector,
36+
private string $privateKey,
37+
private ?string $passPhrase = null,
38+
private array $signHeaders = self::DefaultSignHeaders,
39+
) {
4040
if (!extension_loaded('openssl')) {
4141
throw new Nette\NotSupportedException('DkimSigner requires PHP extension openssl which is not loaded.');
4242
}
43-
44-
$this->domain = $options['domain'] ?? '';
45-
$this->selector = $options['selector'] ?? '';
46-
$this->privateKey = $options['privateKey'] ?? '';
47-
$this->passPhrase = $options['passPhrase'] ?? '';
48-
$this->signHeaders = count($signHeaders) > 0
49-
? $signHeaders
50-
: self::DefaultSignHeaders;
5143
}
5244

5345

tests/Mail.DI/Mail.extension.phpt

+2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ mail:
4545
smtp: true
4646
dkim:
4747
privateKey: fixtures/private.key
48+
domain: nette.org
49+
selector: s
4850
4951
');
5052
Assert::type(Nette\Mail\DkimSigner::class, $container3->getService('mail.signer'));

tests/Mail/Mail.dkim.headers.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (!extension_loaded('openssl')) {
1717
Tester\Environment::skip('OpenSSL not installed');
1818
}
1919

20-
$signer = new class ([], ['From', 'To', 'Date', 'Subject', 'Message-ID', 'X-Mailer', 'Content-Type']) extends DkimSigner {
20+
$signer = new class ('', '', '', null, ['From', 'To', 'Date', 'Subject', 'Message-ID', 'X-Mailer', 'Content-Type']) extends DkimSigner {
2121
public function getSignedHeaders(Message $message): array
2222
{
2323
return parent::getSignedHeaders($message);

tests/Mail/Mail.dkim.invalidKey.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ if (!extension_loaded('openssl')) {
1818
Tester\Environment::skip('OpenSSL not installed');
1919
}
2020

21-
$signer = new DkimSigner([]);
21+
$signer = new DkimSigner('', '', '');
2222

2323
$mail = new Message;
2424
$mail->setFrom('John Doe <[email protected]>');

tests/Mail/Mail.dkim.process.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ if (!extension_loaded('openssl')) {
1717
Tester\Environment::skip('OpenSSL not installed');
1818
}
1919

20-
$signer = new class ([], ['From', 'To', 'Subject', 'X-Mailer', 'Content-Type']) extends DkimSigner {
20+
$signer = new class ('', '', '', null, ['From', 'To', 'Subject', 'X-Mailer', 'Content-Type']) extends DkimSigner {
2121
public function computeSignature(string $rawHeader, string $signature): string
2222
{
2323
$headers = parent::computeSignature($rawHeader, $signature);

tests/Mail/Mail.dkim.sign.phpt

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ $mail->addTo('Lady Jane <[email protected]>');
2525
$mail->setSubject('Hello Jane!');
2626
$mail->setBody('Příliš žluťoučký kůň');
2727

28-
$signer = new class (['privateKey' => $privateKey, 'domain' => 'nette.org', 'selector' => 'selector'], ['From', 'To', 'Subject']) extends DkimSigner {
28+
$signer = new class ('nette.org', 'selector', $privateKey, null, ['From', 'To', 'Subject']) extends DkimSigner {
2929
protected function getTime(): int
3030
{
3131
return 0;

0 commit comments

Comments
 (0)