complément logs et exceptions #20

Merged
mlamalle merged 4 commits from issue-19 into develop 2024-04-29 11:33:17 +02:00
1 changed files with 7 additions and 5 deletions
Showing only changes of commit 5aacd981b4 - Show all commits

View File

@ -6,18 +6,20 @@ use App\SQLLogin\SQLLoginConnect;
use App\SQLLogin\SQLLoginRequest; use App\SQLLogin\SQLLoginRequest;
use PDO; use PDO;
use PDOException; use PDOException;
use Psr\Log\LoggerInterface;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class SQLLoginService extends AbstractController class SQLLoginService extends AbstractController
{ {
public SQLLoginRequest $sqlLoginRequest; public SQLLoginRequest $sqlLoginRequest;
public function __construct(SQLLoginRequest $sqlLoginRequest) public function __construct(SQLLoginRequest $sqlLoginRequest, private LoggerInterface $loggerInterface)
{ {
$this->sqlLoginRequest = $sqlLoginRequest; $this->sqlLoginRequest = $sqlLoginRequest;
$this->loggerInterface = $loggerInterface;
} }
public function fetchDatas(string $login) public function fetchDatas(string $login): array
{ {
try { try {
$dbh = $this->getConnection(); $dbh = $this->getConnection();
@ -29,7 +31,7 @@ class SQLLoginService extends AbstractController
$datas = $query->fetch(PDO::FETCH_ASSOC); $datas = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) { } catch (PDOException $e) {
\Sentry\captureException($e); \Sentry\captureException($e);
$this->loggerInterface->critical($e->getMessage());
throw new PDOException(); throw new PDOException();
} }
@ -45,7 +47,7 @@ class SQLLoginService extends AbstractController
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]); $query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
$password = $query->fetch(PDO::FETCH_ASSOC); $password = $query->fetch(PDO::FETCH_ASSOC);
} catch (PDOException $e) { } catch (PDOException $e) {
\Sentry\captureException($e); $this->loggerInterface->critical($e->getMessage());
throw new PDOException(); throw new PDOException();
} }
if ($password) { if ($password) {
@ -58,7 +60,7 @@ class SQLLoginService extends AbstractController
return false; return false;
} }
public function getConnection() public function getConnection(): PDO
{ {
// Appel du singleton // Appel du singleton
$sqlLogin = SQLLoginConnect::getInstance(); $sqlLogin = SQLLoginConnect::getInstance();