feat : add Zimbra settings API (CRUD + test connection)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
Matthieu
2026-03-19 10:13:44 +01:00
parent 97a8afe559
commit 75c53632c8
5 changed files with 202 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
<?php
declare(strict_types=1);
namespace App\State;
use ApiPlatform\Metadata\Operation;
use ApiPlatform\State\ProcessorInterface;
use App\ApiResource\ZimbraSettings;
use App\Entity\ZimbraConfiguration;
use App\Repository\ZimbraConfigurationRepository;
use App\Service\TokenEncryptor;
use Doctrine\ORM\EntityManagerInterface;
final readonly class ZimbraSettingsProcessor implements ProcessorInterface
{
public function __construct(
private EntityManagerInterface $em,
private ZimbraConfigurationRepository $configRepository,
private TokenEncryptor $tokenEncryptor,
) {}
public function process(mixed $data, Operation $operation, array $uriVariables = [], array $context = []): ZimbraSettings
{
assert($data instanceof ZimbraSettings);
$config = $this->configRepository->findSingleton();
if (null === $config) {
$config = new ZimbraConfiguration();
}
$config->setServerUrl($data->serverUrl);
$config->setUsername($data->username);
$config->setCalendarPath($data->calendarPath);
$config->setEnabled($data->enabled);
if (null !== $data->password && '' !== $data->password) {
$config->setEncryptedPassword($this->tokenEncryptor->encrypt($data->password));
}
$this->em->persist($config);
$this->em->flush();
$result = new ZimbraSettings();
$result->serverUrl = $config->getServerUrl();
$result->username = $config->getUsername();
$result->calendarPath = $config->getCalendarPath();
$result->enabled = $config->isEnabled();
$result->hasPassword = $config->hasPassword();
return $result;
}
}