1 | <?php |
2 | |
3 | require_once __DIR__ . "/../lib/php/BAD_REQUEST.php"; |
4 | require_once __DIR__ . "/../lib/php/recuperaTexto.php"; |
5 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
6 | require_once __DIR__ . "/../lib/php/devuelveJson.php"; |
7 | require_once __DIR__ . "/../lib/php/devuelveProblemDetails.php"; |
8 | require_once __DIR__ . "/../lib/php/devuelveErrorInterno.php"; |
9 | |
10 | try { |
11 | |
12 | $saludo = recuperaTexto("saludo"); |
13 | $nombre = recuperaTexto("nombre"); |
14 | |
15 | if ( |
16 | $saludo === false |
17 | || $saludo === "" |
18 | ) |
19 | throw new ProblemDetails( |
20 | status: BAD_REQUEST, |
21 | title: "Falta el saludo.", |
22 | type: "/error/faltasaludo.html" |
23 | ); |
24 | |
25 | if ( |
26 | $nombre === false |
27 | || $nombre === "" |
28 | ) |
29 | throw new ProblemDetails( |
30 | status: BAD_REQUEST, |
31 | title: "Falta el nombre.", |
32 | type: "/error/faltanombre.html" |
33 | ); |
34 | |
35 | $resultado = |
36 | "{$saludo} {$nombre}."; |
37 | |
38 | devuelveJson($resultado); |
39 | } catch (ProblemDetails $details) { |
40 | |
41 | devuelveProblemDetails($details); |
42 | } catch (Throwable $error) { |
43 | |
44 | devuelveErrorInterno($error); |
45 | } |
46 | |