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("\n", 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();