| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . "/BAD_REQUEST.php"; |
| 4 | require_once __DIR__ . "/ProblemDetails.php"; |
| 5 | |
| 6 | function validaNombre(false|string $nombre) |
| 7 | { |
| 8 | |
| 9 | if ($nombre === false) |
| 10 | throw new ProblemDetails( |
| 11 | status: BAD_REQUEST, |
| 12 | title: "Falta el nombre.", |
| 13 | type: "/error/faltanombre.html", |
| 14 | detail: "La solicitud no tiene el valor de nombre." |
| 15 | ); |
| 16 | |
| 17 | $trimNombre = trim($nombre); |
| 18 | |
| 19 | if ($trimNombre === "") |
| 20 | throw new ProblemDetails( |
| 21 | status: BAD_REQUEST, |
| 22 | title: "Nombre en blanco.", |
| 23 | type: "/error/nombreenblanco.html", |
| 24 | detail: "Pon texto en el campo nombre.", |
| 25 | ); |
| 26 | |
| 27 | return $trimNombre; |
| 28 | } |
| 29 | |