You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
2.3 KiB

<?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';
/**
* Instantiate App
*/
$app = AppFactory::create();
// Add Routing Middleware
$app->addRoutingMiddleware();
/**
* Add Error Handling Middleware
*
* @param bool $displayErrorDetails -> Should be set to false in production
* @param bool $logErrors -> Parameter is passed to the default ErrorHandler
* @param bool $logErrorDetails -> Display error details in error log
*/
$errorMiddleware = $app->addErrorMiddleware(true, true, true);
/**
* Add a route for the API
*/
$app->get('/', function (Request $request, Response $response) {
$parameters = $request->getQueryParams();
if (empty($parameters['method'])){
throw new TypeErrorMethod($request);
}else{
$method = $parameters['method'];
}
unset($parameters['method']);
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
$ok = false;
foreach ($listGateway as $gateway){
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){
throw new HttpNotFoundError($request);
}
$temp = array(0 => array("id" => "1",
"0" => "1",
"title" => "Votre avis nous intéresse !",
"1" => "Votre avis nous intéresse !",
"description" => "Ce formulaire vous permet de candidater à une potentielle interview si votre profil nous intéresse.",
"2" => "Ce formulaire vous permet de candidater à une potentielle interview si votre profil nous intéresse."
));
$response->getBody()->write(json_encode($temp));
return $response->withHeader('Content-type', 'application/json');
});
// Run app
$app->run();