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:
19: public $defaults = array(
20: 'smtp' => FALSE,
21: 'host' => NULL,
22: 'port' => NULL,
23: 'username' => NULL,
24: 'password' => NULL,
25: 'secure' => NULL,
26: 'timeout' => NULL,
27: );
28:
29:
30: public function loadConfiguration()
31: {
32: $container = $this->getContainerBuilder();
33: $config = $this->validateConfig($this->defaults);
34:
35: $mailer = $container->addDefinition($this->prefix('mailer'))
36: ->setClass('Nette\Mail\IMailer');
37:
38: if (empty($config['smtp'])) {
39: $mailer->setFactory('Nette\Mail\SendmailMailer');
40: } else {
41: $mailer->setFactory('Nette\Mail\SmtpMailer', array($config));
42: }
43:
44: if ($this->name === 'mail') {
45: $container->addAlias('nette.mailer', $this->prefix('mailer'));
46: }
47: }
48:
49: }
50: