Require new mail driver methods, remove BC layer

This commit is contained in:
Franz Liedke 2020-02-26 22:56:09 +01:00
parent ccf11480bf
commit 50ea61b524
3 changed files with 9 additions and 17 deletions

View File

@ -41,15 +41,11 @@ class ShowMailSettingsController extends AbstractShowController
$actual = self::$container->make('mail.driver'); $actual = self::$container->make('mail.driver');
$validator = self::$container->make(Factory::class); $validator = self::$container->make(Factory::class);
if (method_exists($configured, 'validate')) { $errors = $configured->validate($settings, $validator);
$errors = $configured->validate($settings, $validator);
} else {
$errors = new \Illuminate\Support\MessageBag;
}
return [ return [
'drivers' => $drivers, 'drivers' => $drivers,
'sending' => method_exists($actual, 'canSend') ? $actual->canSend() : true, 'sending' => $actual->canSend(),
'errors' => $errors, 'errors' => $errors,
]; ];
} }

View File

@ -10,6 +10,8 @@
namespace Flarum\Mail; namespace Flarum\Mail;
use Flarum\Settings\SettingsRepositoryInterface; use Flarum\Settings\SettingsRepositoryInterface;
use Illuminate\Contracts\Validation\Factory;
use Illuminate\Support\MessageBag;
use Swift_Transport; use Swift_Transport;
/** /**
@ -44,14 +46,12 @@ interface DriverInterface
* presence of validation problems with the configured mail driver, Flarum * presence of validation problems with the configured mail driver, Flarum
* will fall back to its no-op {@see \Flarum\Mail\NullDriver}. * will fall back to its no-op {@see \Flarum\Mail\NullDriver}.
*/ */
// TODO: Uncomment for beta.13 public function validate(SettingsRepositoryInterface $settings, Factory $validator): MessageBag;
//public function validate(SettingsRepositoryInterface $settings, Factory $validator): MessageBag;
/** /**
* Does this driver actually send out emails? * Does this driver actually send out emails?
*/ */
// TODO: Uncomment for beta.13 public function canSend(): bool;
//public function canSend(): bool;
/** /**
* Build a mail transport based on Flarum's current settings. * Build a mail transport based on Flarum's current settings.

View File

@ -35,13 +35,9 @@ class MailServiceProvider extends AbstractServiceProvider
$settings = $this->app->make(SettingsRepositoryInterface::class); $settings = $this->app->make(SettingsRepositoryInterface::class);
$validator = $this->app->make(Factory::class); $validator = $this->app->make(Factory::class);
if (method_exists($configured, 'validate')) { return $configured->validate($settings, $validator)->any()
return $configured->validate($settings, $validator)->any() ? $this->app->make(NullDriver::class)
? $this->app->make(NullDriver::class) : $configured;
: $configured;
} else {
return $configured;
}
}); });
$this->app->alias('mail.driver', DriverInterface::class); $this->app->alias('mail.driver', DriverInterface::class);