2. srv / modelo / recuperaPasatiempo.php

1<?php
2
3require_once __DIR__ . "/../../lib/php/BAD_REQUEST.php";
4require_once __DIR__ . "/../../lib/php/validaJson.php";
5require_once __DIR__ . "/../../lib/php/ProblemDetails.php";
6require_once __DIR__ . "/Pasatiempo.php";
7
8function recuperaPasatiempo($objeto)
9{
10
11 $objeto = validaJson($objeto);
12
13 if (!isset($objeto->nombre) || !is_string($objeto->nombre))
14 throw new ProblemDetails(
15 status: BAD_REQUEST,
16 title: "El nombre debe ser texto.",
17 type: "/error/nombreincorrecto.html",
18 );
19
20 if (!isset($objeto->uuid) || !is_string($objeto->uuid))
21 throw new ProblemDetails(
22 status: BAD_REQUEST,
23 title: "El uuid debe ser texto.",
24 type: "/error/uuidincorrecto.html",
25 );
26
27 if (!isset($objeto->eliminado) || !is_bool($objeto->eliminado))
28 throw new ProblemDetails(
29 status: BAD_REQUEST,
30 title: "El campo eliminado debe ser booleano.",
31 type: "/error/eliminadoincorrecto.html",
32 );
33
34 if (!isset($objeto->modificacion) || !is_int($objeto->modificacion))
35 throw new ProblemDetails(
36 status: BAD_REQUEST,
37 title: "La modificacion debe ser número.",
38 type: "/error/modificacionincorrecta.html",
39 );
40
41 return new Pasatiempo(
42 uuid: $objeto->uuid,
43 nombre: $objeto->nombre,
44 modificacion: $objeto->modificacion,
45 eliminado: $objeto->eliminado
46 );
47}
48
skip_previous skip_next