Skip to content

Commit

Permalink
Merge pull request #6 from Linkdup/master
Browse files Browse the repository at this point in the history
Made updates for SilverStripe 4.9.0
  • Loading branch information
lekoala authored Oct 12, 2021
2 parents 841c329 + 9da49f0 commit fe46dbc
Show file tree
Hide file tree
Showing 2 changed files with 148 additions and 64 deletions.
28 changes: 19 additions & 9 deletions src/MailgunHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace LeKoala\Mailgun;

use \Exception;
use Swift_Mailer;
use Mailgun\Mailgun;
use SilverStripe\Control\Director;
use SilverStripe\Core\Environment;
Expand Down Expand Up @@ -47,7 +48,9 @@ public static function getMailer()
*/
public static function isMailgunMailer()
{
return self::getMailer()->getSwiftMailer()->getTransport() instanceof MailgunSwiftTransport;
return self::getMailer()
->getSwiftMailer()
->getTransport() instanceof MailgunSwiftTransport;
}

/**
Expand All @@ -60,7 +63,9 @@ public static function getClient()
if (!self::$client) {
$key = self::config()->api_key;
if (empty($key)) {
throw new \Exception("api_key is not configured for " . __CLASS__);
throw new \Exception(
'api_key is not configured for ' . __CLASS__
);
}
$endpoint = self::DEFAULT_ENDPOINT;
if (self::config()->endpoint) {
Expand Down Expand Up @@ -102,7 +107,7 @@ public static function getDomain()
if ($domain = Environment::getEnv('MAILGUN_DOMAIN')) {
return $domain;
}
throw new Exception("MAILGUN_DOMAIN not set");
throw new Exception('MAILGUN_DOMAIN not set');
}

/**
Expand Down Expand Up @@ -164,15 +169,18 @@ public static function registerTransport()
$client = self::getClient();
$mailer = self::getMailer();
if (!$mailer instanceof SwiftMailer) {
throw new Exception("Mailer must be an instance of " . SwiftMailer::class . " instead of " . get_class($mailer));
throw new Exception(
'Mailer must be an instance of ' .
SwiftMailer::class .
' instead of ' .
get_class($mailer)
);
}
$transport = new MailgunSwiftTransport($client);
$newSwiftMailer = $mailer->getSwiftMailer()->newInstance($transport);
$mailer->setSwiftMailer($newSwiftMailer);
$mailer->setSwiftMailer(new Swift_Mailer($transport));
return $mailer;
}


/**
* Resolve default send from address
*
Expand All @@ -184,8 +192,10 @@ public static function registerTransport()
* @param bool $createDefault
* @return string
*/
public static function resolveDefaultFromEmail($from = null, $createDefault = true)
{
public static function resolveDefaultFromEmail(
$from = null,
$createDefault = true
) {
$original_from = $from;
if (!empty($from)) {
// If we have a sender, validate its email
Expand Down
Loading

0 comments on commit fe46dbc

Please sign in to comment.