| 1 | <?php |
| 2 | |
| 3 | require_once __DIR__ . "/BAD_REQUEST.php"; |
| 4 | require_once __DIR__ . "/recibeTexto.php"; |
| 5 | require_once __DIR__ . "/ProblemDetailsException.php"; |
| 6 | |
| 7 | function recibeTextoObligatorio(string $parametro) |
| 8 | { |
| 9 | $texto = recibeTexto($parametro); |
| 10 | |
| 11 | if ($texto === false) |
| 12 | throw new ProblemDetailsException([ |
| 13 | "status" => BAD_REQUEST, |
| 14 | "title" => "Falta el valor $parametro.", |
| 15 | "type" => "/errors/faltavalor.html", |
| 16 | "detail" => "La solicitud no tiene el valor de $parametro." |
| 17 | ]); |
| 18 | |
| 19 | $trimTexto = trim($texto); |
| 20 | |
| 21 | if ($trimTexto === "") |
| 22 | throw new ProblemDetailsException([ |
| 23 | "status" => BAD_REQUEST, |
| 24 | "title" => "Campo $parametro en blanco.", |
| 25 | "type" => "/errors/campoenblanco.html", |
| 26 | "detail" => "Pon texto en el campo $parametro." |
| 27 | ]); |
| 28 | |
| 29 | return $trimTexto; |
| 30 | } |
| 31 | |