mirror of
https://github.com/nuxsmin/sysPass.git
synced 2026-03-07 00:46:59 +01:00
refactor(php): Relocate and rename classes
Signed-off-by: Rubén D <nuxsmin@syspass.org>
This commit is contained in:
@@ -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);
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
@@ -23,14 +22,16 @@ declare(strict_types=1);
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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
|
||||
{
|
||||
|
||||
}
|
||||
@@ -1,6 +1,4 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
@@ -24,7 +22,9 @@ declare(strict_types=1);
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
@@ -23,13 +22,15 @@ declare(strict_types=1);
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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;
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
<?php
|
||||
declare(strict_types=1);
|
||||
/**
|
||||
* sysPass
|
||||
*
|
||||
@@ -23,12 +22,15 @@ declare(strict_types=1);
|
||||
* along with sysPass. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user