1 | <?php |
2 | |
3 | require_once __DIR__ . "/../../lib/php/ProblemDetails.php"; |
4 | |
5 | class Rol |
6 | { |
7 | |
8 | public string $id; |
9 | public string $descripcion; |
10 | |
11 | public function __construct(string $descripcion = "", string $id = "") |
12 | { |
13 | $this->id = $id; |
14 | $this->descripcion = $descripcion; |
15 | } |
16 | |
17 | public function valida() |
18 | { |
19 | |
20 | if ($this->id === "") |
21 | throw new ProblemDetails( |
22 | status: ProblemDetails::BadRequest, |
23 | type: "/error/faltaid.html", |
24 | title: "Falta el id.", |
25 | ); |
26 | |
27 | if ($this->descripcion === "") |
28 | throw new ProblemDetails( |
29 | status: ProblemDetails::BadRequest, |
30 | type: "/error/faltadescripcion.html", |
31 | title: "Falta la descripción.", |
32 | ); |
33 | } |
34 | } |
35 |
1 | <?php |
2 | |
3 | require_once __DIR__ . "/../../lib/php/ProblemDetails.php"; |
4 | require_once __DIR__ . "/Rol.php"; |
5 | |
6 | class Usuario |
7 | { |
8 | |
9 | public int $id; |
10 | public string $cue; |
11 | /** @var Rol[] */ |
12 | public array $roles; |
13 | |
14 | public function __construct( |
15 | string $cue = "", |
16 | array $roles = [], |
17 | int $id = 0 |
18 | ) { |
19 | $this->id = $id; |
20 | $this->cue = $cue; |
21 | $this->roles = $roles; |
22 | } |
23 | |
24 | public function valida() |
25 | { |
26 | |
27 | if ($this->cue === "") |
28 | throw new ProblemDetails( |
29 | status: ProblemDetails::BadRequest, |
30 | type: "/error/faltacue.html", |
31 | title: "Falta el cue.", |
32 | ); |
33 | |
34 | foreach ($this->roles as $rol) { |
35 | if (!($rol instanceof Rol)) |
36 | throw new ProblemDetails( |
37 | status: ProblemDetails::BadRequest, |
38 | type: "/error/rolincorrecto.html", |
39 | title: "Tipo incorrecto para un rol.", |
40 | ); |
41 | } |
42 | } |
43 | } |
44 |