1: <?php
2:
3: 4: 5: 6:
7:
8: namespace Nette\Bridges\MailDI;
9:
10: use Nette;
11:
12:
13: 14: 15:
16: class MailExtension extends Nette\DI\CompilerExtension
17: {
18: public $defaults = [
19: 'smtp' => false,
20: 'host' => null,
21: 'port' => null,
22: 'username' => null,
23: 'password' => null,
24: 'secure' => null,
25: 'timeout' => null,
26: 'clientHost' => null,
27: ];
28:
29:
30: public function loadConfiguration()
31: {
32: $builder = $this->getContainerBuilder();
33: $config = $this->validateConfig($this->defaults);
34:
35: $mailer = $builder->addDefinition($this->prefix('mailer'))
36: ->setClass(Nette\Mail\IMailer::class);
37:
38: if (empty($config['smtp'])) {
39: $mailer->setFactory(Nette\Mail\SendmailMailer::class);
40: } else {
41: $mailer->setFactory(Nette\Mail\SmtpMailer::class, [$config]);
42: }
43:
44: if ($this->name === 'mail') {
45: $builder->addAlias('nette.mailer', $this->prefix('mailer'));
46: }
47: }
48: }
49: