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); $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(); }