Skip to content

Commit

Permalink
DkimSigner::__construct() $options changed to parameters (BC break)
Browse files Browse the repository at this point in the history
  • Loading branch information
dg committed Jan 26, 2023
1 parent 1943767 commit 4904546
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/Bridges/MailDI/MailExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public function getConfigSchema(): Nette\Schema\Schema
'dkim' => Expect::anyOf(
Expect::null(),
Expect::structure([
'domain' => Expect::string()->dynamic(),
'selector' => Expect::string()->dynamic(),
'domain' => Expect::string()->required()->dynamic(),
'selector' => Expect::string()->required()->dynamic(),
'privateKey' => Expect::string()->required(),
'passPhrase' => Expect::string()->dynamic(),
])->castTo('array'),
Expand All @@ -59,7 +59,7 @@ public function loadConfiguration()

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

$mailer->addSetup('setSigner', [$signer]);
}
Expand Down
22 changes: 7 additions & 15 deletions src/Mail/DkimSigner.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,27 +27,19 @@ class DkimSigner implements Signer
];

private const DkimSignature = 'DKIM-Signature';
private string $domain;
private array $signHeaders;
private string $selector;
private string $privateKey;
private string $passPhrase;


/** @throws Nette\NotSupportedException */
public function __construct(array $options, array $signHeaders = self::DefaultSignHeaders)
{
public function __construct(
private string $domain,
private string $selector,
private string $privateKey,
private ?string $passPhrase = null,
private array $signHeaders = self::DefaultSignHeaders,
) {
if (!extension_loaded('openssl')) {
throw new Nette\NotSupportedException('DkimSigner requires PHP extension openssl which is not loaded.');
}

$this->domain = $options['domain'] ?? '';
$this->selector = $options['selector'] ?? '';
$this->privateKey = $options['privateKey'] ?? '';
$this->passPhrase = $options['passPhrase'] ?? '';
$this->signHeaders = count($signHeaders) > 0
? $signHeaders
: self::DefaultSignHeaders;
}


Expand Down
2 changes: 2 additions & 0 deletions tests/Mail.DI/Mail.extension.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ mail:
smtp: true
dkim:
privateKey: fixtures/private.key
domain: nette.org
selector: s
');
Assert::type(Nette\Mail\DkimSigner::class, $container3->getService('mail.signer'));
2 changes: 1 addition & 1 deletion tests/Mail/Mail.dkim.headers.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (!extension_loaded('openssl')) {
Tester\Environment::skip('OpenSSL not installed');
}

$signer = new class ([], ['From', 'To', 'Date', 'Subject', 'Message-ID', 'X-Mailer', 'Content-Type']) extends DkimSigner {
$signer = new class ('', '', '', null, ['From', 'To', 'Date', 'Subject', 'Message-ID', 'X-Mailer', 'Content-Type']) extends DkimSigner {
public function getSignedHeaders(Message $message): array
{
return parent::getSignedHeaders($message);
Expand Down
2 changes: 1 addition & 1 deletion tests/Mail/Mail.dkim.invalidKey.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ if (!extension_loaded('openssl')) {
Tester\Environment::skip('OpenSSL not installed');
}

$signer = new DkimSigner([]);
$signer = new DkimSigner('', '', '');

$mail = new Message;
$mail->setFrom('John Doe <[email protected]>');
Expand Down
2 changes: 1 addition & 1 deletion tests/Mail/Mail.dkim.process.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ if (!extension_loaded('openssl')) {
Tester\Environment::skip('OpenSSL not installed');
}

$signer = new class ([], ['From', 'To', 'Subject', 'X-Mailer', 'Content-Type']) extends DkimSigner {
$signer = new class ('', '', '', null, ['From', 'To', 'Subject', 'X-Mailer', 'Content-Type']) extends DkimSigner {
public function computeSignature(string $rawHeader, string $signature): string
{
$headers = parent::computeSignature($rawHeader, $signature);
Expand Down
2 changes: 1 addition & 1 deletion tests/Mail/Mail.dkim.sign.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ $mail->addTo('Lady Jane <[email protected]>');
$mail->setSubject('Hello Jane!');
$mail->setBody('Příliš žluťoučký kůň');

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

0 comments on commit 4904546

Please sign in to comment.