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.

57 lines
1.8 KiB

<?php
use Psr\Http\Message\ResponseInterface as Response;
use Psr\Http\Message\ServerRequestInterface as Request;
use Slim\Exception\HttpNotFoundException;
use Slim\Factory\AppFactory;
use Selective\BasePath\BasePathMiddleware;
try{
require 'Config/vendor/autoload.php';
/**
* Instantiate App
*/
$app = AppFactory::create();
// Add Routing Middleware
$app->addRoutingMiddleware();
// Set the base path to run the app in a subdirectory.
// This path is used in urlFor().
$app->add(new BasePathMiddleware($app));
/**
* 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);
$app->get('/', function (Request $request, Response $response) {
$response->getBody()->write("Hello, this is the base page");
return $response;
});
$app->get('/api/{method}', function (Request $request, Response $response, $args) {
$method = $args['method'];
$parameters = $request->getQueryParams();
$listGateway = array("\\Gateway\\GatewayForm", "\\Gateway\\GatewayKeyword", "\\Gateway\\GatewayQuestion");
foreach ($listGateway as $gateway) // Pour chaque Gateway
{
if (method_exists($gateway, $method)) {
(new $gateway)->$method($parameters); // Si oui, on appelle cette fonction
}
}
$response->getBody()->write("Use the method $method, with the parameters ");
return $response;
});
// Run app
$app->run();
}catch (HttpNotFoundException|Exception $e){
echo "Error :".$e->getMessage();
}