Skip to content
Permalink
Browse files

MailExtension: added getConfigSchema()

  • Loading branch information...
dg committed Mar 11, 2019
1 parent c9c2935 commit d891fba26ae19855bb9f2d60dc83bed038c9362b
Showing with 22 additions and 16 deletions.
  1. +3 −0 composer.json
  2. +19 −16 src/Bridges/MailDI/MailExtension.php
@@ -24,6 +24,9 @@
"nette/tester": "^2.0",
"tracy/tracy": "^2.4"
},
"conflict": {
"nette/di": "<3.0"
},
"suggest": {
"ext-fileinfo": "to detect type of attached files"
},
@@ -10,39 +10,42 @@
namespace Nette\Bridges\MailDI;
use Nette;
use Nette\DI\Config\Expect;
/**
* Mail extension for Nette DI.
*/
class MailExtension extends Nette\DI\CompilerExtension
{
public $defaults = [
'smtp' => false,
'host' => null,
'port' => null,
'username' => null,
'password' => null,
'secure' => null,
'timeout' => null,
'context' => null,
'clientHost' => null,
'persistent' => false,
];
public function getConfigSchema(): Nette\DI\Config\Schema
{
return Expect::struct([
'smtp' => Expect::bool(false),
'host' => Expect::string()->dynamic(),
'port' => Expect::int()->dynamic(),
'username' => Expect::string()->dynamic(),
'password' => Expect::string()->dynamic(),
'secure' => Expect::enum(null, 'ssl', 'tls')->dynamic(),
'timeout' => Expect::int()->dynamic(),
'context' => Expect::arrayOf('array')->dynamic(),
'clientHost' => Expect::string()->dynamic(),
'persistent' => Expect::bool(false)->dynamic(),
]);
}
public function loadConfiguration()
{
$builder = $this->getContainerBuilder();
$config = $this->validateConfig($this->defaults);
$mailer = $builder->addDefinition($this->prefix('mailer'))
->setType(Nette\Mail\IMailer::class);
if (empty($config['smtp'])) {
$mailer->setFactory(Nette\Mail\SendmailMailer::class);
if ($this->config['smtp']) {
$mailer->setFactory(Nette\Mail\SmtpMailer::class, [$this->config]);
} else {
$mailer->setFactory(Nette\Mail\SmtpMailer::class, [$config]);
$mailer->setFactory(Nette\Mail\SendmailMailer::class);
}
if ($this->name === 'mail') {

0 comments on commit d891fba

Please sign in to comment.
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.