diff --git a/app/modules/web/Controllers/ConfigManager/IndexController.php b/app/modules/web/Controllers/ConfigManager/IndexController.php index e5201bf1..84642b7a 100644 --- a/app/modules/web/Controllers/ConfigManager/IndexController.php +++ b/app/modules/web/Controllers/ConfigManager/IndexController.php @@ -51,7 +51,7 @@ use SP\Domain\Crypt\Services\TemporaryMasterPass; use SP\Domain\Export\Services\BackupFileHelper; use SP\Domain\Export\Services\XmlExport; use SP\Domain\Log\Providers\LogInterface; -use SP\Domain\Notification\Providers\MailHandler; +use SP\Domain\Notification\Services\MailEvent; use SP\Domain\Task\Services\Task; use SP\Domain\User\Ports\UserGroupService; use SP\Domain\User\Ports\UserProfileService; @@ -376,7 +376,7 @@ final class IndexController extends ControllerBase $mailEvents = $this->configData->getMailEvents(); - $events = array_merge(MailHandler::EVENTS, $mailEvents); + $events = array_merge(MailEvent::EVENTS, $mailEvents); sort($events, SORT_STRING); diff --git a/lib/SP/Core/Definitions/CoreDefinitions.php b/lib/SP/Core/Definitions/CoreDefinitions.php index 4c4e2f2d..442bac70 100644 --- a/lib/SP/Core/Definitions/CoreDefinitions.php +++ b/lib/SP/Core/Definitions/CoreDefinitions.php @@ -102,10 +102,10 @@ use SP\Domain\Install\Services\MysqlSetupBuilder; use SP\Domain\Log\Providers\DatabaseHandler; use SP\Domain\Log\Providers\LogHandler; use SP\Domain\Notification\Ports\MailerInterface; -use SP\Domain\Notification\Providers\MailHandler; -use SP\Domain\Notification\Providers\NotificationHandler; -use SP\Domain\Notification\Providers\PhpMailerWrapper; use SP\Domain\Notification\Services\Mail; +use SP\Domain\Notification\Services\MailEvent; +use SP\Domain\Notification\Services\NotificationEvent; +use SP\Domain\Notification\Services\PhpMailerService; use SP\Domain\Storage\Ports\FileCacheService; use SP\Infrastructure\Database\Database; use SP\Infrastructure\Database\DatabaseConnectionData; @@ -236,8 +236,8 @@ final class CoreDefinitions Csrf::class => autowire(Csrf::class), LanguageInterface::class => autowire(Language::class), DatabaseInterface::class => autowire(Database::class), - PhpMailerWrapper::class => autowire(PhpMailerWrapper::class), - MailerInterface::class => factory([PhpMailerWrapper::class, 'configure']) + PhpMailerService::class => autowire(PhpMailerService::class), + MailerInterface::class => factory([PhpMailerService::class, 'configure']) ->parameter( 'mailParams', factory([Mail::class, 'getParamsFromConfig']) @@ -262,9 +262,9 @@ final class CoreDefinitions return new ProvidersHelper( $c->get(LogHandler::class), $c->get(DatabaseHandler::class), - $c->get(MailHandler::class), + $c->get(MailEvent::class), $c->get(AclHandler::class), - $c->get(NotificationHandler::class) + $c->get(NotificationEvent::class) ); }), QueryFactory::class => create(QueryFactory::class) diff --git a/lib/SP/Core/ProvidersHelper.php b/lib/SP/Core/ProvidersHelper.php index b72c20a8..fc3982b6 100644 --- a/lib/SP/Core/ProvidersHelper.php +++ b/lib/SP/Core/ProvidersHelper.php @@ -29,8 +29,8 @@ namespace SP\Core; use SP\Domain\Auth\Providers\AclHandler; use SP\Domain\Log\Providers\DatabaseHandler; use SP\Domain\Log\Providers\LogHandler; -use SP\Domain\Notification\Providers\MailHandler; -use SP\Domain\Notification\Providers\NotificationHandler; +use SP\Domain\Notification\Services\MailEvent; +use SP\Domain\Notification\Services\NotificationEvent; /** * The Provider helper class will have oll the providers availabe in the application @@ -39,11 +39,11 @@ final readonly class ProvidersHelper { public function __construct( - private LogHandler $logHandler, - private ?DatabaseHandler $databaseLogHandler = null, - private ?MailHandler $mailHandler = null, + private LogHandler $logHandler, + private ?DatabaseHandler $databaseLogHandler = null, + private ?MailEvent $mailHandler = null, private ?AclHandler $aclHandler = null, - private ?NotificationHandler $notificationHandler = null + private ?NotificationEvent $notificationHandler = null ) { } @@ -57,7 +57,7 @@ final readonly class ProvidersHelper return $this->databaseLogHandler; } - public function getMailHandler(): MailHandler + public function getMailHandler(): MailEvent { return $this->mailHandler; } @@ -67,7 +67,7 @@ final readonly class ProvidersHelper return $this->aclHandler; } - public function getNotificationHandler(): NotificationHandler + public function getNotificationHandler(): NotificationEvent { return $this->notificationHandler; } diff --git a/lib/SP/Domain/Notification/Providers/MailProviderException.php b/lib/SP/Domain/Notification/MailerException.php similarity index 87% rename from lib/SP/Domain/Notification/Providers/MailProviderException.php rename to lib/SP/Domain/Notification/MailerException.php index 92bcceb3..9765668b 100644 --- a/lib/SP/Domain/Notification/Providers/MailProviderException.php +++ b/lib/SP/Domain/Notification/MailerException.php @@ -1,5 +1,4 @@ . */ -namespace SP\Domain\Notification\Providers; +declare(strict_types=1); + +namespace SP\Domain\Notification; use SP\Domain\Core\Exceptions\SPException; /** - * Class MailProviderException + * Class MailerException */ -final class MailProviderException extends SPException +final class MailerException extends SPException { } diff --git a/lib/SP/Domain/Notification/Providers/MailHandler.php b/lib/SP/Domain/Notification/Services/MailEvent.php similarity index 93% rename from lib/SP/Domain/Notification/Providers/MailHandler.php rename to lib/SP/Domain/Notification/Services/MailEvent.php index 73d3e3cc..f9b63729 100644 --- a/lib/SP/Domain/Notification/Providers/MailHandler.php +++ b/lib/SP/Domain/Notification/Services/MailEvent.php @@ -1,6 +1,4 @@ . */ -namespace SP\Domain\Notification\Providers; +declare(strict_types=1); + +namespace SP\Domain\Notification\Services; use Exception; use SP\Core\Application; @@ -32,7 +32,7 @@ use SP\Core\Events\Event; use SP\Core\Messages\MailMessage; use SP\Core\Messages\TextFormatter; use SP\Domain\Common\Providers\EventsTrait; -use SP\Domain\Common\Providers\Provider; +use SP\Domain\Common\Services\Service; use SP\Domain\Core\Events\EventReceiver; use SP\Domain\Http\Ports\RequestService; use SP\Domain\Notification\Ports\MailService; @@ -41,9 +41,9 @@ use function SP\__; use function SP\processException; /** - * Class MailHandler + * Class MailEvent */ -final class MailHandler extends Provider implements EventReceiver +final class MailEvent extends Service implements EventReceiver { use EventsTrait; @@ -152,11 +152,7 @@ final class MailHandler extends Provider implements EventReceiver $subject = $eventMessage->getDescription(new TextFormatter(), true) ?: $eventType; - $this->mailService->send( - $subject, - $to, - $mailMessage - ); + $this->mailService->send($subject, $to, $mailMessage); } catch (Exception $e) { processException($e); } diff --git a/lib/SP/Domain/Notification/Providers/NotificationHandler.php b/lib/SP/Domain/Notification/Services/NotificationEvent.php similarity index 94% rename from lib/SP/Domain/Notification/Providers/NotificationHandler.php rename to lib/SP/Domain/Notification/Services/NotificationEvent.php index 557051e1..96cfb0f6 100644 --- a/lib/SP/Domain/Notification/Providers/NotificationHandler.php +++ b/lib/SP/Domain/Notification/Services/NotificationEvent.php @@ -1,5 +1,4 @@ . */ -namespace SP\Domain\Notification\Providers; +declare(strict_types=1); + +namespace SP\Domain\Notification\Services; use Exception; use SP\Core\Application; use SP\Core\Events\Event; use SP\Domain\Common\Providers\EventsTrait; -use SP\Domain\Common\Providers\Provider; +use SP\Domain\Common\Services\Service; use SP\Domain\Core\Events\EventReceiver; use SP\Domain\Notification\Models\Notification; use SP\Domain\Notification\Ports\NotificationService; @@ -38,11 +39,9 @@ use function SP\__; use function SP\processException; /** - * Class NotificationHandler - * - * @package SP\Domain\Providers\Notification + * Class NotificationEvent */ -final class NotificationHandler extends Provider implements EventReceiver +final class NotificationEvent extends Service implements EventReceiver { use EventsTrait; diff --git a/lib/SP/Domain/Notification/Providers/PhpMailerWrapper.php b/lib/SP/Domain/Notification/Services/PhpMailerService.php similarity index 87% rename from lib/SP/Domain/Notification/Providers/PhpMailerWrapper.php rename to lib/SP/Domain/Notification/Services/PhpMailerService.php index bfcf9c60..49c23fef 100644 --- a/lib/SP/Domain/Notification/Providers/PhpMailerWrapper.php +++ b/lib/SP/Domain/Notification/Services/PhpMailerService.php @@ -1,5 +1,4 @@ . */ -namespace SP\Domain\Notification\Providers; +declare(strict_types=1); + +namespace SP\Domain\Notification\Services; use PHPMailer\PHPMailer\Exception; use PHPMailer\PHPMailer\PHPMailer; use SP\Domain\Core\AppInfoInterface; use SP\Domain\Notification\Dtos\MailParams; +use SP\Domain\Notification\MailerException; use SP\Domain\Notification\Ports\MailerInterface; use function SP\__u; @@ -38,7 +40,7 @@ use function SP\processException; /** * A wrapper for PHPMailer */ -final readonly class PhpMailerWrapper implements MailerInterface +final readonly class PhpMailerService implements MailerInterface { public function __construct(private PHPMailer $mailer, private bool $debug = false) @@ -53,14 +55,14 @@ final readonly class PhpMailerWrapper implements MailerInterface } /** - * @throws MailProviderException + * @throws \SP\Domain\Notification\MailerException */ public function addAddress(string $address): MailerInterface { try { $this->mailer->addAddress($address); } catch (Exception $e) { - throw new MailProviderException($e); + throw new MailerException($e); } return $this; @@ -81,14 +83,14 @@ final readonly class PhpMailerWrapper implements MailerInterface } /** - * @throws MailProviderException + * @throws MailerException */ public function send(): bool { try { return $this->mailer->send(); } catch (Exception $e) { - throw new MailProviderException($e); + throw new MailerException($e); } } @@ -100,7 +102,7 @@ final readonly class PhpMailerWrapper implements MailerInterface /** * Configure the mailer with the configuration settings * - * @throws MailProviderException + * @throws \SP\Domain\Notification\MailerException */ public function configure(MailParams $mailParams): MailerInterface { @@ -135,7 +137,7 @@ final readonly class PhpMailerWrapper implements MailerInterface } catch (Exception $e) { processException($e); - throw MailProviderException::error(__u('Unable to initialize'), $e->getMessage(), $e->getCode(), $e); + throw MailerException::error(__u('Unable to initialize'), $e->getMessage(), $e->getCode(), $e); } } } diff --git a/tests/SP/Domain/Notification/Providers/MailHandlerTest.php b/tests/SP/Domain/Notification/Providers/MailHandlerTest.php index 0041a0b9..0acb76f3 100644 --- a/tests/SP/Domain/Notification/Providers/MailHandlerTest.php +++ b/tests/SP/Domain/Notification/Providers/MailHandlerTest.php @@ -36,7 +36,7 @@ use SP\Domain\Config\Adapters\ConfigData; use SP\Domain\Config\Ports\ConfigFileService; use SP\Domain\Http\Ports\RequestService; use SP\Domain\Notification\Ports\MailService; -use SP\Domain\Notification\Providers\MailHandler; +use SP\Domain\Notification\Services\MailEvent; use SP\Tests\Generators\ConfigDataGenerator; use SP\Tests\UnitaryTestCase; @@ -49,7 +49,7 @@ class MailHandlerTest extends UnitaryTestCase private MockObject|MailService $mailService; private RequestService|MockObject $requestService; - private MailHandler $mailHandler; + private MailEvent $mailHandler; private ConfigData $configData; public function testUpdate() @@ -240,7 +240,7 @@ class MailHandlerTest extends UnitaryTestCase $this->configData->setMailEvents([]); - $databaseHandler = new MailHandler($this->application, $this->mailService, $this->requestService); + $databaseHandler = new MailEvent($this->application, $this->mailService, $this->requestService); $out = $databaseHandler->getEventsString(); $this->assertEquals($expected, $out); @@ -264,6 +264,6 @@ class MailHandlerTest extends UnitaryTestCase $this->mailService = $this->createMock(MailService::class); $this->requestService = $this->createMock(RequestService::class); - $this->mailHandler = new MailHandler($this->application, $this->mailService, $this->requestService); + $this->mailHandler = new MailEvent($this->application, $this->mailService, $this->requestService); } }