| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . "/../lib/php/BAD_REQUEST.php"; |
| 4 | require_once __DIR__ . "/../lib/php/ejecutaServicio.php"; |
| 5 | require_once __DIR__ . "/../lib/php/recuperaTexto.php"; |
| 6 | require_once __DIR__ . "/../lib/php/validaToken.php"; |
| 7 | require_once __DIR__ . "/../lib/php/recuperaTexto.php"; |
| 8 | require_once __DIR__ . "/../lib/php/ProblemDetails.php"; |
| 9 | require_once __DIR__ . "/../lib/php/devuelveJson.php"; |
| 10 | |
| 11 | ejecutaServicio(function () { |
| 12 | |
| 13 | session_start(); |
| 14 | |
| 15 | $token = recuperaTexto("token"); |
| 16 | if ($token === false) { |
| 17 | throw new ProblemDetails( |
| 18 | status: BAD_REQUEST, |
| 19 | title: "Falta el token.", |
| 20 | type: "/error/faltatoken.html", |
| 21 | ); |
| 22 | } |
| 23 | |
| 24 | validaToken("formulario", $token); |
| 25 | |
| 26 | |
| 27 | |
| 28 | $saludo = recuperaTexto("saludo"); |
| 29 | $nombre = recuperaTexto("nombre"); |
| 30 | |
| 31 | if ($saludo === false) |
| 32 | throw new ProblemDetails( |
| 33 | status: BAD_REQUEST, |
| 34 | title: "Falta el saludo.", |
| 35 | type: "/error/faltasaludo.html", |
| 36 | detail: "La solicitud no tiene el valor de saludo.", |
| 37 | ); |
| 38 | |
| 39 | if ($saludo === "") |
| 40 | throw new ProblemDetails( |
| 41 | status: BAD_REQUEST, |
| 42 | title: "El saludo está en blanco.", |
| 43 | type: "/error/saludoenblanco.html", |
| 44 | detail: "Pon texto en el campo saludo.", |
| 45 | ); |
| 46 | |
| 47 | if ($nombre === false) |
| 48 | throw new ProblemDetails( |
| 49 | status: BAD_REQUEST, |
| 50 | title: "Falta el nombre.", |
| 51 | type: "/error/faltanombre.html", |
| 52 | detail: "La solicitud no tiene el valor de nombre.", |
| 53 | ); |
| 54 | |
| 55 | if ($nombre === "") |
| 56 | throw new ProblemDetails( |
| 57 | status: BAD_REQUEST, |
| 58 | title: "El nombre está en blanco.", |
| 59 | type: "/error/nombreenblanco.html", |
| 60 | detail: "Pon texto en el campo nombre.", |
| 61 | ); |
| 62 | |
| 63 | $resultado = "{$saludo} {$nombre}."; |
| 64 | |
| 65 | devuelveJson($resultado); |
| 66 | }); |
| 67 | |