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