26 |
alex |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
class Commun {
|
|
|
4 |
|
|
|
5 |
|
|
|
6 |
private $parametres;
|
|
|
7 |
private $nomSource;
|
|
|
8 |
private $nomService;
|
|
|
9 |
|
|
|
10 |
private $verificateur;
|
|
|
11 |
private $parametresRecherche;
|
|
|
12 |
|
|
|
13 |
|
|
|
14 |
public function consulter($ressources, $parametres) {
|
|
|
15 |
|
|
|
16 |
$this->recupererRessourcesEtParametres($ressources, $parametres);
|
|
|
17 |
$retour = null;
|
|
|
18 |
|
|
|
19 |
try {
|
|
|
20 |
if (!$this->verifierExistenceSourcesDonnees()) {
|
|
|
21 |
$message = "Source de donnees indisponible";
|
|
|
22 |
throw new Exception($message, RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE);
|
|
|
23 |
} else {
|
|
|
24 |
$this->chargerNomSource();
|
|
|
25 |
$this->verifierParametres();
|
|
|
26 |
$this->chargerNomService();
|
|
|
27 |
$objetTraitement = new $this->nomService($this->parametresRecherche);
|
|
|
28 |
$methode = $this->genererNomMethodeAExecuter();
|
|
|
29 |
$retour = $objetTraitement->$methode();
|
|
|
30 |
}
|
|
|
31 |
|
|
|
32 |
} catch (Exception $erreur) {
|
|
|
33 |
$retour = $erreur;
|
|
|
34 |
}
|
|
|
35 |
|
|
|
36 |
return $retour;
|
|
|
37 |
}
|
|
|
38 |
|
|
|
39 |
private function recupererRessourcesEtParametres($ressources, $parametres) {
|
|
|
40 |
$this->ressources = $ressources;
|
|
|
41 |
$this->parametres = $parametres;
|
|
|
42 |
}
|
|
|
43 |
|
|
|
44 |
private function chargerNomService() {
|
|
|
45 |
$this->nomService = ucfirst($this->parametres['source']) . 'Formateur';
|
|
|
46 |
Projets::chargerConfigurationSource($this->parametres['source']);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
private function genererNomMethodeAExecuter() {
|
|
|
50 |
return 'recuperer' . ucfirst($this->ressources[0]);
|
|
|
51 |
}
|
|
|
52 |
|
|
|
53 |
private function verifierExistenceSourcesDonnees() {
|
|
|
54 |
$sourcesDisponibles = explode(',', Config::get('sources_dispo'));
|
|
|
55 |
$estDisponible = false;
|
|
|
56 |
if (isset($this->parametres['source'])) {
|
|
|
57 |
if (in_array($this->parametres['source'], $sourcesDisponibles)) {
|
|
|
58 |
$estDisponible = true;
|
|
|
59 |
}
|
|
|
60 |
} else {
|
|
|
61 |
// choisir la source par defaut, qui est toujours disponible
|
|
|
62 |
$estDisponible = true;
|
|
|
63 |
}
|
|
|
64 |
return $estDisponible;
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
private function chargerNomSource() {
|
|
|
68 |
if (isset($this->parametres['source'])) {
|
|
|
69 |
$this->nomSource = $this->parametres['source'];
|
|
|
70 |
} else {
|
|
|
71 |
$this->nomSource = Config::get('source_defaut');
|
|
|
72 |
}
|
|
|
73 |
}
|
|
|
74 |
|
|
|
75 |
private function verifierParametres() {
|
|
|
76 |
$this->verificateur = new VerificateurParametres($this->parametres);
|
|
|
77 |
$this->verificateur->verifierParametres();
|
|
|
78 |
if ($this->verificateur->contientErreurs()) {
|
|
|
79 |
$this->verificateur->leverException();
|
|
|
80 |
} else {
|
|
|
81 |
$this->recupererParametresRecherche();
|
|
|
82 |
}
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
private function recupererParametresRecherche() {
|
|
|
86 |
$this->parametresRecherche = $this->verificateur->renvoyerResultatVerification();
|
|
|
87 |
}
|
|
|
88 |
|
|
|
89 |
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
?>
|