<?php
/**
 * Created by PhpStorm.
 * User: eater
 * Date: 6/29/16
 * Time: 1:15 AM
 */

namespace Eater\Glim\Service;


use Eater\Glim\Core;
use Nette\Mail\IMailer;
use Nette\Mail\SendmailMailer;
use Nette\Mail\SmtpMailer;
use Slim\Container;

class MailSender
{
    /**
     * @param Container $c
     * @param string $name
     * @return IMailer
     */
    static public function init($c, $name) {
        /** @var Core $core */
        $core = $c->get('core');
        $config = $core->getConfig();
        
        if ($config->get('mail.type', 'sendmail') === 'smtp') {
            return new SmtpMailer([
                'host' => $config->get('mail.host', 'localhost'),
                'secure' => $config->get('mail.secure'),
                'username' => $config->get('mail.username'),
                'password' => $config->get('mail.password'),
            ]);
        } else {
            return new SendmailMailer();
        }
    }
}