Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
class JoueurSquadro
{
private string $nomJoueur;
private int $id;
// Constructeur
public function __construct(string $nomJoueur, int $id = 0)
{
$this->nomJoueur = $nomJoueur;
$this->id = $id;
}
// Getter et Setter pour nomJoueur
public function getNomJoueur(): string
{
return $this->nomJoueur;
}
public function setNomJoueur(string $nom): void
{
$this->nomJoueur = $nom;
}
// Getter et Setter pour id
public function getId(): int
{
return $this->id;
}
public function setId(int $id): void
{
$this->id = $id;
}
// Convertir l'objet en JSON
public function toJson(): string
{
return json_encode([
'nomJoueur' => $this->nomJoueur,
'id' => $this->id
]);
}
// Créer un objet à partir d'une chaîne JSON
public static function fromJson(string $json): JoueurSquadro
{
$data = json_decode($json, true);
return new JoueurSquadro($data['nomJoueur'], $data['id']);
}
}