- ApiResource MailSettings expose les operations Get + Patch sur /api/mail/configuration - Provider + Processor relient le DTO a l'entite MailConfiguration (singleton) - password en write-only (jamais retourne) + hasPassword en lecture - chiffrement password via TokenEncryptor (sodium) - securite ROLE_ADMIN sur les deux operations Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
40 lines
1.3 KiB
PHP
40 lines
1.3 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\State\Mail;
|
|
|
|
use ApiPlatform\Metadata\Operation;
|
|
use ApiPlatform\State\ProviderInterface;
|
|
use App\ApiResource\MailSettings;
|
|
use App\Repository\MailConfigurationRepository;
|
|
|
|
final readonly class MailSettingsProvider implements ProviderInterface
|
|
{
|
|
public function __construct(
|
|
private MailConfigurationRepository $configRepository,
|
|
) {}
|
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): MailSettings
|
|
{
|
|
$config = $this->configRepository->findSingleton();
|
|
$dto = new MailSettings();
|
|
|
|
if (null !== $config) {
|
|
$dto->protocol = $config->getProtocol();
|
|
$dto->imapHost = $config->getImapHost();
|
|
$dto->imapPort = $config->getImapPort();
|
|
$dto->imapEncryption = $config->getImapEncryption();
|
|
$dto->smtpHost = $config->getSmtpHost();
|
|
$dto->smtpPort = $config->getSmtpPort();
|
|
$dto->smtpEncryption = $config->getSmtpEncryption();
|
|
$dto->username = $config->getUsername();
|
|
$dto->sentFolderPath = $config->getSentFolderPath();
|
|
$dto->enabled = $config->isEnabled();
|
|
$dto->hasPassword = $config->hasPassword();
|
|
}
|
|
|
|
return $dto;
|
|
}
|
|
}
|