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 | public string $match; |
12 | |
13 | public array $roles; |
14 | |
15 | public function __construct( |
16 | string $cue = "", |
17 | string $match = "", |
18 | array $roles = [], |
19 | int $id = 0 |
20 | ) { |
21 | $this->id = $id; |
22 | $this->cue = $cue; |
23 | $this->match = $match; |
24 | $this->roles = $roles; |
25 | } |
26 | |
27 | public function valida() |
28 | { |
29 | |
30 | if ($this->cue === "") |
31 | throw new ProblemDetails( |
32 | status: ProblemDetails::BadRequest, |
33 | type: "/error/faltacue.html", |
34 | title: "Falta el cue.", |
35 | ); |
36 | |
37 | if ($this->match === "") |
38 | throw new ProblemDetails( |
39 | status: ProblemDetails::BadRequest, |
40 | type: "/error/faltamatch.html", |
41 | title: "Falta el match.", |
42 | ); |
43 | |
44 | foreach ($this->roles as $rol) { |
45 | if (!($rol instanceof Rol)) |
46 | throw new ProblemDetails( |
47 | status: ProblemDetails::BadRequest, |
48 | type: "/error/rolincorrecto.html", |
49 | title: "Tipo incorrecto para un rol.", |
50 | ); |
51 | } |
52 | } |
53 | } |
54 | |