From b7bda373807b6b7ad83be3f3f04e0a69491b9ac3 Mon Sep 17 00:00:00 2001 From: Franz Liedke Date: Fri, 24 Jan 2020 17:59:39 +0100 Subject: [PATCH] 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. --- .../src/Api/Controller/ShowMailSettingsController.php | 8 ++++++-- framework/core/src/Mail/DriverInterface.php | 8 ++++---- framework/core/src/Mail/MailServiceProvider.php | 10 +++++++--- 3 files changed, 17 insertions(+), 9 deletions(-) diff --git a/framework/core/src/Api/Controller/ShowMailSettingsController.php b/framework/core/src/Api/Controller/ShowMailSettingsController.php index d699ee2b0..6fca5ffb1 100644 --- a/framework/core/src/Api/Controller/ShowMailSettingsController.php +++ b/framework/core/src/Api/Controller/ShowMailSettingsController.php @@ -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, ]; } diff --git a/framework/core/src/Mail/DriverInterface.php b/framework/core/src/Mail/DriverInterface.php index 17fa26aa9..44215a17f 100644 --- a/framework/core/src/Mail/DriverInterface.php +++ b/framework/core/src/Mail/DriverInterface.php @@ -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. diff --git a/framework/core/src/Mail/MailServiceProvider.php b/framework/core/src/Mail/MailServiceProvider.php index 024757f2f..34fd2b504 100644 --- a/framework/core/src/Mail/MailServiceProvider.php +++ b/framework/core/src/Mail/MailServiceProvider.php @@ -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);