[MAILER][WRAPPER] Add mailer wrapper that respects the configuration

This commit is contained in:
Hugo Sales 2020-07-25 01:57:34 +00:00 committed by Hugo Sales
parent 7c35fde8bc
commit 7a7f7d3ae1
Signed by: someonewithpc
GPG Key ID: 7D0C7EAFC9D835A0
3 changed files with 66 additions and 1 deletions

View File

@ -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,

View File

@ -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();
}

52
src/Core/Mailer.php Normal file
View File

@ -0,0 +1,52 @@
<?php
// {{{ License
// This file is part of GNU social - https://www.gnu.org/software/social
//
// GNU social is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// GNU social is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with GNU social. If not, see <http://www.gnu.org/licenses/>.
// }}}
/**
* Mailer wrapper
*
* @package GNUsocial
* @category Wrapper
*
* @author Hugo Sales <hugo@fc.up.pt>
* @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);
}
}
}