TEMP : try to change import of function, create a new PDO exception Handler
continuous-integration/drone/push Build is passing Details

master
dorian.hodin 2 years ago
parent 18d54dd06a
commit b32202fc32

@ -2,7 +2,6 @@
namespace Config; namespace Config;
use PDOException; use PDOException;
require_once __DIR__ ."/Connection.php"; require_once __DIR__ ."/Connection.php";
@ -21,9 +20,7 @@ class ConnectClass{
$connection = new Connection($dsn,$login,$password); $connection = new Connection($dsn,$login,$password);
}catch (PDOException){ }catch (PDOException){
throw new PDOException();
http_response_code(404);
return http_response_code();
} }
return $connection; return $connection;
} }

@ -9,6 +9,7 @@ use Throwable;
class HttpNotFoundError extends HttpSpecializedException { class HttpNotFoundError extends HttpSpecializedException {
protected $code = 404; protected $code = 404;
protected string $title = "Method Not Found";
protected $message = "Method not found on the API, verify the method's name."; protected $message = "Method not found on the API, verify the method's name.";
public function __construct(ServerRequestInterface $request,?Throwable $previous = null) public function __construct(ServerRequestInterface $request,?Throwable $previous = null)

@ -0,0 +1,20 @@
<?php
namespace ExceptionHandle;
use Psr\Http\Message\ServerRequestInterface;
use Slim\Exception\HttpSpecializedException;
use Throwable;
class PDOError extends HttpSpecializedException {
protected $code = 408;
protected string $title = "PDO connection failed";
protected $message = "The connection method throw a PDO Exception, connection to database failed";
public function __construct(ServerRequestInterface $request,?Throwable $previous = null)
{
parent::__construct($request, $this->message, $previous);
}
}

@ -9,6 +9,7 @@ use Throwable;
class TypeErrorMethod extends HttpSpecializedException { class TypeErrorMethod extends HttpSpecializedException {
protected $code = 400; protected $code = 400;
protected string $title = "Method query params is not specified";
protected $message = "Bad Parameters, The API need a 'method' query params in URL. Exemple :'http://url?method=getSomething'"; protected $message = "Bad Parameters, The API need a 'method' query params in URL. Exemple :'http://url?method=getSomething'";
public function __construct(ServerRequestInterface $request,?Throwable $previous = null) public function __construct(ServerRequestInterface $request,?Throwable $previous = null)

@ -2,17 +2,20 @@
namespace Gateway; namespace Gateway;
use Config\Connection;
use PDO; use PDO;
use Config\ConnectClass; use PDOException;
class GatewayForm class GatewayForm
{ {
private Connection $connection; private \Config\Connection $connection;
public function __construct() public function __construct()
{ {
$this->connection = (new ConnectClass)->connect(); try{
$this->connection = (new \Config\ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException();
}
} }
public function insertForm(array $parameters): void public function insertForm(array $parameters): void

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection; use Config\Connection;
use Config\ConnectClass; use Config\ConnectClass;
use PDO; use PDO;
use PDOException;
class GatewayKeyword class GatewayKeyword
{ {
@ -12,8 +13,11 @@ class GatewayKeyword
public function __construct() public function __construct()
{ {
$this->connection = (new ConnectClass())->connect(); try{
} $this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException();
} }
public function insertKeyword(array $keyword): void public function insertKeyword(array $keyword): void
{ {

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection; use Config\Connection;
use Config\ConnectClass; use Config\ConnectClass;
use PDO; use PDO;
use PDOException;
class GatewayListResponseOfCandidate class GatewayListResponseOfCandidate
{ {
@ -12,8 +13,11 @@ class GatewayListResponseOfCandidate
public function __construct() public function __construct()
{ {
$this->connection = (new ConnectClass())->connect(); try{
} $this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException();
} }
public function getDetailsListResponsesOfCandidate(array $idListResponse): array public function getDetailsListResponsesOfCandidate(array $idListResponse): array
{ {

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection; use Config\Connection;
use Config\ConnectClass; use Config\ConnectClass;
use PDO; use PDO;
use PDOException;
class GatewayPossibleResponse class GatewayPossibleResponse
{ {
@ -12,8 +13,11 @@ class GatewayPossibleResponse
public function __construct() public function __construct()
{ {
$this->connection = (new ConnectClass())->connect(); try{
} $this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException();
} }
public function getPossibleResponseByQuestion(array $idQuestion): array public function getPossibleResponseByQuestion(array $idQuestion): array
{ {

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection; use Config\Connection;
use Config\ConnectClass; use Config\ConnectClass;
use PDO; use PDO;
use PDOException;
class GatewayQuestion class GatewayQuestion
{ {
@ -12,8 +13,11 @@ class GatewayQuestion
public function __construct() public function __construct()
{ {
$this->connection = (new ConnectClass())->connect(); try{
} $this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException();
} }
public function insertQuestion(QuestionAPI $question, int $idForm): void public function insertQuestion(QuestionAPI $question, int $idForm): void
{ {

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection; use Config\Connection;
use Config\ConnectClass; use Config\ConnectClass;
use PDO; use PDO;
use PDOException;
class GatewayResponse class GatewayResponse
{ {
@ -12,8 +13,11 @@ class GatewayResponse
public function __construct() public function __construct()
{ {
$this->connection = (new ConnectClass())->connect(); try{
} $this->connection = (new ConnectClass)->connect();
}catch(PDOException $e){
throw new PDOException();
} }
public function getResponsesByIdListCandidate(array $listResponsesOfCandidateId): array public function getResponsesByIdListCandidate(array $listResponsesOfCandidateId): array
{ {

@ -1,12 +1,12 @@
<?php <?php
use ExceptionHandle\HttpNotFoundError; use ExceptionHandle\HttpNotFoundError;
use ExceptionHandle\PDOError;
use ExceptionHandle\TypeErrorMethod; use ExceptionHandle\TypeErrorMethod;
use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request; use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Factory\AppFactory; use Slim\Factory\AppFactory;
require 'Config/vendor/autoload.php'; require 'Config/vendor/autoload.php';
/** /**
@ -40,11 +40,15 @@ $app->get('/', function (Request $request, Response $response) {
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion"); $listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
$ok = false; $ok = false;
foreach ($listGateway as $gateway){ foreach ($listGateway as $gateway){
echo implode(",",get_class_methods((new $gateway))); try {
echo implode(",", get_class_methods((new $gateway)));
if (method_exists($gateway, $method)) { if (method_exists($gateway, $method)) {
$ok = true; $ok = true;
$response->getBody()->write(json_encode((new $gateway)->$method($parameters))); $response->getBody()->write(json_encode((new $gateway)->$method($parameters)));
} }
}catch (PDOException $e){
throw new PDOError($request);
}
} }
if (!$ok){ if (!$ok){
throw new HttpNotFoundError($request); throw new HttpNotFoundError($request);

Loading…
Cancel
Save