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;
use PDOException;
require_once __DIR__ ."/Connection.php";
@ -21,9 +20,7 @@ class ConnectClass{
$connection = new Connection($dsn,$login,$password);
}catch (PDOException){
http_response_code(404);
return http_response_code();
throw new PDOException();
}
return $connection;
}

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

@ -2,17 +2,20 @@
namespace Gateway;
use Config\Connection;
use PDO;
use Config\ConnectClass;
use PDOException;
class GatewayForm
{
private Connection $connection;
private \Config\Connection $connection;
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

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection;
use Config\ConnectClass;
use PDO;
use PDOException;
class GatewayKeyword
{
@ -12,8 +13,11 @@ class GatewayKeyword
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
{

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection;
use Config\ConnectClass;
use PDO;
use PDOException;
class GatewayListResponseOfCandidate
{
@ -12,8 +13,11 @@ class GatewayListResponseOfCandidate
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
{

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection;
use Config\ConnectClass;
use PDO;
use PDOException;
class GatewayPossibleResponse
{
@ -12,8 +13,11 @@ class GatewayPossibleResponse
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
{

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection;
use Config\ConnectClass;
use PDO;
use PDOException;
class GatewayQuestion
{
@ -12,8 +13,11 @@ class GatewayQuestion
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
{

@ -5,6 +5,7 @@ namespace Gateway;
use Config\Connection;
use Config\ConnectClass;
use PDO;
use PDOException;
class GatewayResponse
{
@ -12,8 +13,11 @@ class GatewayResponse
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
{

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

Loading…
Cancel
Save