optimisation appel pdo, retry consent
Some checks failed
Cadoles/hydra-sql/pipeline/pr-develop There was a failure building this commit
Some checks failed
Cadoles/hydra-sql/pipeline/pr-develop There was a failure building this commit
This commit is contained in:
@ -2,22 +2,18 @@
|
||||
|
||||
namespace App\Service;
|
||||
|
||||
use App\SQLLogin\Exception\DatabaseConnectionException;
|
||||
use App\SQLLogin\Exception\DataToFetchConfigurationException;
|
||||
use App\SQLLogin\Exception\EmptyResultException;
|
||||
use App\SQLLogin\Exception\LoginElementsConfigurationException;
|
||||
use App\SQLLogin\Exception\NullDataToFetchException;
|
||||
use App\SQLLogin\SQLLoginConnect;
|
||||
use App\SQLLogin\SQLLoginRequest;
|
||||
use PDO;
|
||||
use PDOException;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
|
||||
|
||||
class SQLLoginService extends AbstractController
|
||||
{
|
||||
public const MAX_RETRY = 3;
|
||||
private PDO $pdo;
|
||||
|
||||
public function __construct(
|
||||
private SQLLoginRequest $sqlLoginRequest,
|
||||
@ -25,7 +21,6 @@ class SQLLoginService extends AbstractController
|
||||
) {
|
||||
$this->sqlLoginRequest = $sqlLoginRequest;
|
||||
$this->loggerInterface = $loggerInterface;
|
||||
$this->pdo = $this->getConnection();
|
||||
}
|
||||
|
||||
public function fetchPasswordAndDatas(string $login): array
|
||||
@ -35,9 +30,6 @@ class SQLLoginService extends AbstractController
|
||||
$datas = $this->executeRequestWithLogin($dataRequest, $login);
|
||||
} catch (NullDataToFetchException $e) {
|
||||
throw new DataToFetchConfigurationException($e->getMessage());
|
||||
} catch (PDOException $e) {
|
||||
$this->loggerInterface->critical($e->getMessage());
|
||||
throw new LoginElementsConfigurationException($e->getMessage());
|
||||
}
|
||||
|
||||
return $datas;
|
||||
@ -47,7 +39,8 @@ class SQLLoginService extends AbstractController
|
||||
{
|
||||
$attempt = 0;
|
||||
while ($attempt < self::MAX_RETRY) {
|
||||
$query = $this->pdo->prepare($request);
|
||||
$pdo = $this->getConnection();
|
||||
$query = $pdo->prepare($request);
|
||||
$query->execute([$this->sqlLoginRequest->getLoginColumnName() => $login]);
|
||||
$datas = $query->fetch(PDO::FETCH_ASSOC);
|
||||
$query->closeCursor();
|
||||
@ -68,13 +61,8 @@ class SQLLoginService extends AbstractController
|
||||
private function getConnection(): PDO
|
||||
{
|
||||
// Appel du singleton
|
||||
try {
|
||||
$sqlLogin = SQLLoginConnect::getInstance();
|
||||
$pdo = $sqlLogin->connect($this->sqlLoginRequest->getDatabaseDsn(), $this->sqlLoginRequest->getDbUser(), $this->sqlLoginRequest->getDbPassword());
|
||||
} catch (PDOException $e) {
|
||||
$this->loggerInterface->critical($e->getMessage());
|
||||
throw new DatabaseConnectionException($e->getMessage());
|
||||
}
|
||||
$sqlLogin = SQLLoginConnect::getInstance();
|
||||
$pdo = $sqlLogin->connect($this->sqlLoginRequest->getDatabaseDsn(), $this->sqlLoginRequest->getDbUser(), $this->sqlLoginRequest->getDbPassword());
|
||||
|
||||
return $pdo;
|
||||
}
|
||||
|
Reference in New Issue
Block a user