feat : restructuration des dossiers pour implementer plus facilement la suite des WS
All checks were successful
Auto Tag Develop / tag (push) Successful in 5s
Build Release Artefact / build (push) Successful in 36s

This commit is contained in:
2026-01-23 16:19:50 +01:00
parent b279f1ac47
commit 7e0c084ebe
36 changed files with 2633 additions and 226 deletions

View File

@@ -4,12 +4,14 @@ declare(strict_types=1);
namespace Malio\EdnotifBundle\Auth;
use Malio\EdnotifBundle\Exception\EdnotifException;
use Malio\EdnotifBundle\Shared\Exception\EdnotifException;
use Psr\Cache\CacheItemPoolInterface;
use Psr\Cache\InvalidArgumentException;
use RuntimeException;
use SoapClient;
use SoapFault;
final class TokenProvider
final readonly class TokenProvider
{
public function __construct(
private SoapClient $guichetClient,
@@ -20,17 +22,19 @@ final class TokenProvider
private string $password,
private int $tokenTtlSeconds,
private CacheItemPoolInterface $cachePool,
) {
}
) {}
/**
* @throws InvalidArgumentException
*/
public function getToken(): string
{
$cacheKey = $this->getCacheKey();
$item = $this->cachePool->getItem($cacheKey);
$item = $this->cachePool->getItem($cacheKey);
if ($item->isHit()) {
$token = $item->get();
if (is_string($token) && $token !== '') {
if (is_string($token) && '' !== $token) {
return $token;
}
}
@@ -44,6 +48,9 @@ final class TokenProvider
return $token;
}
/**
* @throws InvalidArgumentException
*/
public function invalidateToken(): void
{
$this->cachePool->deleteItem($this->getCacheKey());
@@ -52,16 +59,16 @@ final class TokenProvider
private function createToken(): string
{
$profil = array_filter([
'Entreprise' => $this->entreprise,
'Zone' => $this->zone,
'Entreprise' => $this->entreprise,
'Zone' => $this->zone,
'Application' => $this->application,
], static fn ($v) => $v !== null && $v !== '');
], static fn ($v) => null !== $v && '' !== $v);
$payload = [
'Identification' => [
'UserId' => $this->login,
'UserId' => $this->login,
'Password' => $this->password,
'Profil' => $profil,
'Profil' => $profil,
],
];
@@ -69,7 +76,7 @@ final class TokenProvider
/** @var object $response */
$response = $this->guichetClient->__soapCall('tkCreateIdentification', [$payload]);
} catch (SoapFault $e) {
throw new \RuntimeException('SOAP Fault lors de tkCreateIdentification: ' . $e->getMessage(), 0, $e);
throw new RuntimeException('SOAP Fault lors de tkCreateIdentification: '.$e->getMessage(), 0, $e);
}
$rs = $response->ReponseStandard ?? null;
@@ -77,15 +84,16 @@ final class TokenProvider
if (!$ok) {
$anom = $rs->Anomalie ?? null;
$code = (string)($anom->Code ?? 'UNKNOWN');
$sev = (int)($anom->Severite ?? 1);
$msg = (string)($anom->Message ?? 'Authentification refusée');
$code = (string) ($anom->Code ?? 'UNKNOWN');
$sev = (int) ($anom->Severite ?? 1);
$msg = (string) ($anom->Message ?? 'Authentification refusée');
throw new EdnotifException($code, $sev, $msg);
}
$token = $response->Jeton ?? null;
if (!is_string($token) || $token === '') {
throw new \RuntimeException('Guichet: réponse OK mais Jeton absent.');
if (!is_string($token) || '' === $token) {
throw new RuntimeException('Guichet: réponse OK mais Jeton absent.');
}
return $token;
@@ -93,6 +101,6 @@ final class TokenProvider
private function getCacheKey(): string
{
return 'ednotif.token.' . hash('sha256', $this->entreprise . '|' . $this->login);
return 'ednotif.token.'.hash('sha256', $this->entreprise.'|'.$this->login);
}
}