| 163 |
jpm |
1 |
<?php
|
|
|
2 |
class Projet {
|
|
|
3 |
private $ressources = null;
|
|
|
4 |
private $paramsVerif = null;
|
|
|
5 |
private $ressourcesVerif = null;
|
| 216 |
jpm |
6 |
private $versionVerif = null;
|
| 163 |
jpm |
7 |
private $cheminBase = '';
|
|
|
8 |
private $cheminConfig = '';
|
|
|
9 |
private $cheminBiblio = '';
|
| 215 |
jpm |
10 |
private $serviceGenerique = '';
|
| 163 |
jpm |
11 |
|
|
|
12 |
public function __construct(Ressources $ressources) {
|
|
|
13 |
$this->ressources = $ressources;
|
|
|
14 |
}
|
|
|
15 |
|
|
|
16 |
public function setCheminBase($chemin) {
|
|
|
17 |
$this->cheminBase = $chemin;
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public function setCheminConfig($chemin) {
|
|
|
21 |
$this->cheminConfig = $chemin;
|
|
|
22 |
}
|
|
|
23 |
|
|
|
24 |
public function setCheminBiblio($chemin) {
|
|
|
25 |
$this->cheminBiblio = $chemin;
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
public function setParamsVerif($paramsVerificateur) {
|
|
|
29 |
$this->paramsVerif = $paramsVerificateur;
|
|
|
30 |
}
|
|
|
31 |
|
| 216 |
jpm |
32 |
public function setVersionVerif($versionVerificateur) {
|
|
|
33 |
$this->versionVerif = $versionVerificateur;
|
|
|
34 |
}
|
|
|
35 |
|
| 163 |
jpm |
36 |
public function setRessourcesVerif($ressourcesVerificateur) {
|
|
|
37 |
$this->ressourcesVerif = $ressourcesVerificateur;
|
|
|
38 |
}
|
|
|
39 |
|
| 215 |
jpm |
40 |
public function setServiceGenerique($generique) {
|
|
|
41 |
$this->serviceGenerique = $generique;
|
|
|
42 |
}
|
|
|
43 |
|
| 163 |
jpm |
44 |
public function initialiser() {
|
|
|
45 |
$this->chargerConfig();
|
|
|
46 |
// php5.3 : Enregistrement en première position des autoload de la méthode gérant les classes des services
|
|
|
47 |
if (phpversion() < 5.3) {
|
|
|
48 |
spl_autoload_register(array($this, 'chargerClasseProjet'));
|
|
|
49 |
} else {
|
|
|
50 |
spl_autoload_register(array($this, 'chargerClasseProjet'), true , true);
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
|
|
|
54 |
private function chargerConfig() {
|
|
|
55 |
$projet = $this->getNom();
|
|
|
56 |
$chemin = $this->cheminConfig."config_$projet.ini";
|
|
|
57 |
Config::charger($chemin);
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
public function getNom() {
|
|
|
61 |
return $this->ressources->getProjetNom();
|
|
|
62 |
}
|
|
|
63 |
|
| 215 |
jpm |
64 |
public function getClasse() {
|
|
|
65 |
return $this->ressources->getServiceClasse().ucfirst($this->getNom());
|
|
|
66 |
}
|
|
|
67 |
|
| 163 |
jpm |
68 |
private function chargerClasseProjet($classe) {
|
|
|
69 |
if (class_exists($classe)) {
|
|
|
70 |
return null;
|
|
|
71 |
}
|
|
|
72 |
|
|
|
73 |
$chemins = array();
|
|
|
74 |
$chemins[] = $this->cheminBase.$this->getNom().DS;
|
|
|
75 |
$chemins[] = $this->cheminBase.'commun'.DS;
|
|
|
76 |
$chemins[] = $this->cheminBiblio;
|
| 215 |
jpm |
77 |
$chemins[] = $this->cheminBiblio.'generique'.DS;
|
| 201 |
jpm |
78 |
$chemins[] = $this->cheminBiblio.'interfaces'.DS;
|
| 163 |
jpm |
79 |
$chemins[] = $this->cheminBiblio.'nom'.DS;
|
|
|
80 |
$chemins[] = $this->cheminBiblio.'nom'.DS.'decorateurs'.DS;
|
| 231 |
jpm |
81 |
$chemins[] = $this->cheminBiblio.'ontologie'.DS;
|
|
|
82 |
$chemins[] = $this->cheminBiblio.'ontologie'.DS.'decorateurs'.DS;
|
| 163 |
jpm |
83 |
|
|
|
84 |
foreach ($chemins as $chemin) {
|
|
|
85 |
$chemin = $chemin.$classe.'.php';
|
|
|
86 |
if (file_exists($chemin)) {
|
|
|
87 |
require_once $chemin;
|
|
|
88 |
}
|
|
|
89 |
}
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
public function verifier() {
|
|
|
93 |
$this->paramsVerif->verifier();
|
|
|
94 |
$this->ressourcesVerif->verifier();
|
| 216 |
jpm |
95 |
$this->versionVerif->verifier();
|
| 163 |
jpm |
96 |
$this->verifierExistanceServiceClasse();
|
|
|
97 |
}
|
|
|
98 |
|
|
|
99 |
private function verifierExistanceServiceClasse() {
|
| 215 |
jpm |
100 |
$classe = $this->getClasse();
|
|
|
101 |
$existe = $this->verifierExistanceClasseDuProjet($classe);
|
| 163 |
jpm |
102 |
|
| 215 |
jpm |
103 |
if ($existe === false) {
|
|
|
104 |
$service = $this->ressources->getServiceNom();
|
|
|
105 |
$projet = $this->getNom();
|
|
|
106 |
$message = "La classe du service demandé '$service' n'existe pas dans le projet '$projet' !";
|
|
|
107 |
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
|
|
|
108 |
throw new Exception($message, $code);
|
|
|
109 |
}
|
|
|
110 |
}
|
|
|
111 |
|
|
|
112 |
private function verifierExistanceClasseDuProjet($classe) {
|
| 163 |
jpm |
113 |
$chemins = array();
|
| 215 |
jpm |
114 |
$chemins[] = $this->cheminBase.$this->getNom().DS.$classe.'.php';
|
| 163 |
jpm |
115 |
$chemins[] = $this->cheminBase.'commun'.DS.$classe.'.php';
|
|
|
116 |
|
|
|
117 |
$existe = false;
|
|
|
118 |
foreach ($chemins as $chemin) {
|
|
|
119 |
if (file_exists($chemin)) {
|
|
|
120 |
$existe = true;
|
|
|
121 |
break;
|
|
|
122 |
}
|
|
|
123 |
}
|
| 215 |
jpm |
124 |
return $existe;
|
| 163 |
jpm |
125 |
}
|
|
|
126 |
|
| 215 |
jpm |
127 |
public function consulter() {
|
|
|
128 |
$serviceNom = $this->getClasse();
|
|
|
129 |
$service = new $serviceNom($this->serviceGenerique);
|
|
|
130 |
$retour = $service->consulter();
|
|
|
131 |
return $retour;
|
|
|
132 |
}
|
|
|
133 |
|
| 163 |
jpm |
134 |
}
|
|
|
135 |
?>
|