/** * Returns the current instance of the log, or lazy-loads the default one. * @return Swift_Log */ function &getLog() { if ($GLOBALS["_SWIFT_LOG"] === null) { Swift_LogContainer::setLog(new Swift_Log_DefaultLog()); } return $GLOBALS["_SWIFT_LOG"]; }
/** * Connect mailer instance * * @param void * @return boolean */ function connect() { if ($this->connected) { return true; } // if require_once ANGIE_PATH . '/classes/swiftmailer/init.php'; $mailing = ConfigOptions::getValue('mailing'); // Create native connection if ($mailing == MAILING_NATIVE) { require_once SWIFTMAILER_LIB_PATH . '/Swift/Connection/NativeMail.php'; $options = trim(ConfigOptions::getValue('mailing_native_options')); if (empty($options)) { $options = null; } // if $this->swift = new Swift(new Swift_Connection_NativeMail($options)); // Create SMTP connection } elseif ($mailing == MAILING_SMTP) { require_once SWIFTMAILER_LIB_PATH . '/Swift/Connection/SMTP.php'; $smtp_host = ConfigOptions::getValue('mailing_smtp_host'); $smtp_port = ConfigOptions::getValue('mailing_smtp_port'); $smtp_auth = ConfigOptions::getValue('mailing_smtp_authenticate'); $smtp_user = ConfigOptions::getValue('mailing_smtp_username'); $smtp_pass = ConfigOptions::getValue('mailing_smtp_password'); $smtp_security = ConfigOptions::getValue('mailing_smtp_security'); switch ($smtp_security) { case 'tsl': $smtp_enc = SWIFT_SMTP_ENC_TLS; break; case 'ssl': $smtp_enc = SWIFT_SMTP_ENC_SSL; break; default: $smtp_enc = SWIFT_SMTP_ENC_OFF; } // switch $smtp = new Swift_Connection_SMTP($smtp_host, $smtp_port, $smtp_enc); if ($smtp_auth) { $smtp->setUsername($smtp_user); $smtp->setPassword($smtp_pass); } // if $this->swift = new Swift($smtp); // Not supported! } else { return new InvalidParamError('mailing', $mailer, "Unknown mailing type: '{$mailing}' in configuration", true); } // if // Set logger if (DEBUG >= DEBUG_DEVELOPMENT) { Swift_ClassLoader::load("Swift_Log_AngieLog"); $logger = new Swift_Log_AngieLog(); $logger->setLogLevel(SWIFT_LOG_EVERYTHING); Swift_LogContainer::setLog($logger); } // if return $this->swift; }
public function testLoggerIsInvokedIfSetActive() { $conn = new FullMockConnection(); $conn->setReturnValueAt(0, "read", "220 xxx ESMTP"); $conn->setReturnValueAt(1, "read", "250-Hello xxx\r\n250 HELP"); $conn->setReturnValueAt(2, "read", "250 Ok"); $conn->setReturnValueAt(3, "read", "250 ok"); $conn->setReturnValueAt(4, "read", "354 Go ahead"); $conn->setReturnValueAt(5, "read", "250 ok"); $logger = new MockLogger(); $logger->setLogLevel(Swift_Log::LOG_EVERYTHING); $logger->expectMinimumCallCount("add", 8); Swift_LogContainer::setLog($logger); $swift = new Swift($conn, "abc"); $message = new Swift_Message("My Subject", "my body"); $swift->send($message, new Swift_Address("*****@*****.**"), new Swift_Address("*****@*****.**", "Foo Bar")); }