mirror of
https://github.com/flarum/framework.git
synced 2025-02-11 09:59:28 +08:00
Add BC layer for mail driver configuration
By commenting out the new methods on the `DriverInterface` and checking for these methods' existence before calling them, old implementations in extensions will not break right away. This will be removed after beta.12 is released, giving extension authors about two months time to update their extensions.
This commit is contained in:
parent
1e6d7efdc0
commit
b7bda37380
|
@ -41,11 +41,15 @@ class ShowMailSettingsController extends AbstractShowController
|
|||
$actual = self::$container->make('mail.driver');
|
||||
$validator = self::$container->make(Factory::class);
|
||||
|
||||
$errors = $configured->validate($settings, $validator);
|
||||
if (method_exists($configured, 'validate')) {
|
||||
$errors = $configured->validate($settings, $validator);
|
||||
} else {
|
||||
$errors = new \Illuminate\Support\MessageBag;
|
||||
}
|
||||
|
||||
return [
|
||||
'drivers' => $drivers,
|
||||
'sending' => $actual->canSend(),
|
||||
'sending' => method_exists($actual, 'canSend') ? $actual->canSend() : true,
|
||||
'errors' => $errors,
|
||||
];
|
||||
}
|
||||
|
|
|
@ -10,8 +10,6 @@
|
|||
namespace Flarum\Mail;
|
||||
|
||||
use Flarum\Settings\SettingsRepositoryInterface;
|
||||
use Illuminate\Contracts\Validation\Factory;
|
||||
use Illuminate\Support\MessageBag;
|
||||
use Swift_Transport;
|
||||
|
||||
/**
|
||||
|
@ -46,12 +44,14 @@ interface DriverInterface
|
|||
* presence of validation problems with the configured mail driver, Flarum
|
||||
* will fall back to its no-op {@see \Flarum\Mail\NullDriver}.
|
||||
*/
|
||||
public function validate(SettingsRepositoryInterface $settings, Factory $validator): MessageBag;
|
||||
// TODO: Uncomment for beta.13
|
||||
//public function validate(SettingsRepositoryInterface $settings, Factory $validator): MessageBag;
|
||||
|
||||
/**
|
||||
* Does this driver actually send out emails?
|
||||
*/
|
||||
public function canSend(): bool;
|
||||
// TODO: Uncomment for beta.13
|
||||
//public function canSend(): bool;
|
||||
|
||||
/**
|
||||
* Build a mail transport based on Flarum's current settings.
|
||||
|
|
|
@ -36,9 +36,13 @@ class MailServiceProvider extends AbstractServiceProvider
|
|||
$settings = $this->app->make(SettingsRepositoryInterface::class);
|
||||
$validator = $this->app->make(Factory::class);
|
||||
|
||||
return $configured->validate($settings, $validator)->any()
|
||||
? $this->app->make(NullDriver::class)
|
||||
: $configured;
|
||||
if (method_exists($configured, 'validate')) {
|
||||
return $configured->validate($settings, $validator)->any()
|
||||
? $this->app->make(NullDriver::class)
|
||||
: $configured;
|
||||
} else {
|
||||
return $configured;
|
||||
}
|
||||
});
|
||||
|
||||
$this->app->alias('mail.driver', DriverInterface::class);
|
||||
|
|
Loading…
Reference in New Issue
Block a user