/** * Creates a SwiftMailer instance. * * @return object Swift object */ public static function mailer() { if (!static::$mailer) { // Load email configuration, make sure minimum defaults are set $config = Kohana::$config->load('email')->as_array() + array('driver' => 'native', 'options' => array()); // Extract configured options extract($config, EXTR_SKIP); if ($driver === 'smtp') { // Create SMTP transport $transport = Swift_SmtpTransport::newInstance($options['hostname']); if (isset($options['port'])) { // Set custom port number $transport->setPort($options['port']); } if (isset($options['encryption'])) { // Set encryption $transport->setEncryption($options['encryption']); } if (isset($options['username'])) { // Require authentication, username $transport->setUsername($options['username']); } if (isset($options['password'])) { // Require authentication, password $transport->setPassword($options['password']); } if (isset($options['timeout'])) { // Use custom timeout setting $transport->setTimeout($options['timeout']); } } elseif ($driver === 'sendmail') { // Create sendmail transport $transport = Swift_SendmailTransport::newInstance(); if (isset($options['command'])) { // Use custom sendmail command $transport->setCommand($options['command']); } } else { // Create native transport $transport = Swift_MailTransport::newInstance(); if (isset($options['params'])) { // Set extra parameters for mail() $transport->setExtraParams($options['params']); } } // Create the SwiftMailer instance static::$mailer = Swift_Mailer::newInstance($transport); } return static::$mailer; }
/** * @param \Swift_Mailer $mailer */ public static function setMailer(Swift_Mailer $mailer) { static::$mailer = $mailer; }
/** * Returns mailer instance * * @return \XLite\View\Mailer */ protected static function getMailer() { if (!isset(static::$mailer)) { static::$mailer = new \XLite\View\Mailer(); } return static::$mailer; }
/** * Returns mailer instance * * @return \XLite\View\Mailer */ protected static function getMailer() { if (null === static::$mailer) { static::$mailer = new \XLite\View\Mailer(); } return static::$mailer; }
/** * Replace mailer with in memory mailer * @param $config * @param $app */ protected function mockMailer($config) { if (static::$mailer) { $this->app->set('mailer', static::$mailer); return; } // options that make sense for mailer mock $allowedOptions = ['htmlLayout', 'textLayout', 'messageConfig', 'messageClass', 'useFileTransport', 'fileTransportPath', 'fileTransportCallback', 'view', 'viewPath']; $mailerConfig = ['class' => 'Codeception\\Lib\\Connector\\Yii2\\TestMailer']; if (isset($config['components']['mailer']) && is_array($config['components']['mailer'])) { foreach ($config['components']['mailer'] as $name => $value) { if (in_array($name, $allowedOptions, true)) { $mailerConfig[$name] = $value; } } } $this->app->set('mailer', $mailerConfig); static::$mailer = $this->app->get('mailer'); }