A. srv / srvProcesa.php

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