From 7a7f7d3ae11d198b9ce064397a44ead27d5ccb15 Mon Sep 17 00:00:00 2001 From: Hugo Sales Date: Sat, 25 Jul 2020 01:57:34 +0000 Subject: [PATCH] [MAILER][WRAPPER] Add mailer wrapper that respects the configuration --- src/Core/DB/DefaultSettings.php | 1 + src/Core/GNUsocial.php | 14 ++++++++- src/Core/Mailer.php | 52 +++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 src/Core/Mailer.php diff --git a/src/Core/DB/DefaultSettings.php b/src/Core/DB/DefaultSettings.php index a3e6cd035b..1c46a4513c 100644 --- a/src/Core/DB/DefaultSettings.php +++ b/src/Core/DB/DefaultSettings.php @@ -51,6 +51,7 @@ abstract class DefaultSettings 'detect_language' => true, 'languages' => I18n::getAllLanguages(), 'email' => $_ENV['SERVER_ADMIN'] ?? $_ENV['SOCIAL_ADMIN_EMAIL'] ?? null, + 'use_email' => false, // TODO 'recovery_disclose' => false, // Whether to not say that we found the email in the database, when asking for recovery 'timezone' => 'UTC', 'brought_by' => null, diff --git a/src/Core/GNUsocial.php b/src/Core/GNUsocial.php index a71213d963..3be0a550bc 100644 --- a/src/Core/GNUsocial.php +++ b/src/Core/GNUsocial.php @@ -47,7 +47,9 @@ use App\Core\DB\DefaultSettings; use App\Core\I18n\I18n; use App\Core\Queue\Queue; use App\Core\Router\Router; +use App\Util\Common; use Doctrine\ORM\EntityManagerInterface; +use Exception; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Event\ConsoleCommandEvent; use Symfony\Component\EventDispatcher\EventDispatcherInterface; @@ -74,7 +76,7 @@ class GNUsocial implements EventSubscriberInterface protected MessageBusInterface $message_bus; protected EventDispatcherInterface $event_dispatcher; protected SessionInterface $session; - protected SSecurity $security; + protected SSecurity $security; /** * Symfony dependency injection gives us access to these services @@ -119,6 +121,16 @@ class GNUsocial implements EventSubscriberInterface Security::setHelper($this->security); DefaultSettings::setDefaults(); + + // TODO use configuration properly + try { + if (Common::config('site', 'use_email')) { + Mailer::setMailer($this->containen->get('mailer')); + } + } catch (Exception $e) { + // Table doesn't exist yet + } + Cache::setupCache(); ModulesManager::loadModules(); } diff --git a/src/Core/Mailer.php b/src/Core/Mailer.php new file mode 100644 index 0000000000..79f48c2a88 --- /dev/null +++ b/src/Core/Mailer.php @@ -0,0 +1,52 @@ +. + +// }}} + +/** + * Mailer wrapper + * + * @package GNUsocial + * @category Wrapper + * + * @author Hugo Sales + * @copyright 2020 Free Software Foundation, Inc http://www.fsf.org + * @license https://www.gnu.org/licenses/agpl.html GNU AGPL v3 or later + */ + +namespace App\Core; + +use App\Util\Common; +use Symfony\Component\Mailer\MailerInterface; + +abstract class Mailer +{ + private MailerInterface $mailer; + public static function setMailer($m) + { + $this->mailer = $m; + } + + public static function __callStatic(string $method, array $args) + { + if (Common::config('site', 'use_email')) { + return $this->{$method}(...$args); + } + } +}