issue-19: ajout de logs des exceptions PDOExceptions
Cadoles/hydra-sql/pipeline/head This commit looks good
Details
Cadoles/hydra-sql/pipeline/head This commit looks good
Details
This commit is contained in:
parent
ba63c271f9
commit
fe5ca83664
|
@ -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($login)
|
public function fetchDatas($login): array
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dbh = $this->getConnection();
|
$dbh = $this->getConnection();
|
||||||
|
@ -29,19 +31,14 @@ 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();
|
||||||
}
|
}
|
||||||
|
|
||||||
return $datas;
|
return $datas;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public function fetchPassword($login): array|bool
|
||||||
* @param mixed $login
|
|
||||||
*
|
|
||||||
* @return bool
|
|
||||||
*/
|
|
||||||
public function fetchPassword($login)
|
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
$dbh = $this->getConnection();
|
$dbh = $this->getConnection();
|
||||||
|
@ -50,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) {
|
||||||
|
@ -63,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();
|
||||||
|
|
Loading…
Reference in New Issue