Subversion Repositories eFlore/Projets.eflore-projets

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
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 = '';
9
 
10
	public function __construct(Ressources $ressources) {
11
		$this->ressources = $ressources;
12
	}
13
 
14
	public function setCheminBase($chemin) {
15
		$this->cheminBase = $chemin;
16
	}
17
 
18
	public function setCheminConfig($chemin) {
19
		$this->cheminConfig = $chemin;
20
	}
21
 
22
	public function setCheminBiblio($chemin) {
23
		$this->cheminBiblio = $chemin;
24
	}
25
 
26
	public function setParamsVerif($paramsVerificateur) {
27
		$this->paramsVerif = $paramsVerificateur;
28
	}
29
 
30
	public function setRessourcesVerif($ressourcesVerificateur) {
31
		$this->ressourcesVerif = $ressourcesVerificateur;
32
	}
33
 
34
	public function initialiser() {
35
		$this->chargerConfig();
36
		// php5.3 : Enregistrement en première position des autoload de la méthode gérant les classes des services
37
		if (phpversion() < 5.3) {
38
			spl_autoload_register(array($this, 'chargerClasseProjet'));
39
		} else {
40
			spl_autoload_register(array($this, 'chargerClasseProjet'), true , true);
41
		}
42
	}
43
 
44
	private function chargerConfig() {
45
		$projet = $this->getNom();
46
		$chemin = $this->cheminConfig."config_$projet.ini";
47
 
48
		Config::charger($chemin);
49
	}
50
 
51
	public function getNom() {
52
		return $this->ressources->getProjetNom();
53
	}
54
 
55
	private function chargerClasseProjet($classe) {
56
		if (class_exists($classe)) {
57
			return null;
58
		}
59
 
60
		$chemins = array();
61
		$chemins[] = $this->cheminBase.$this->getNom().DS;
62
		$chemins[] = $this->cheminBase.'commun'.DS;
63
		$chemins[] = $this->cheminBiblio;
201 jpm 64
		$chemins[] = $this->cheminBiblio.'interfaces'.DS;
163 jpm 65
		$chemins[] = $this->cheminBiblio.'nom'.DS;
66
		$chemins[] = $this->cheminBiblio.'nom'.DS.'decorateurs'.DS;
67
 
68
		foreach ($chemins as $chemin) {
69
			$chemin = $chemin.$classe.'.php';
70
			if (file_exists($chemin)) {
71
				require_once $chemin;
72
			}
73
		}
74
	}
75
 
76
	public function getServiceClasseNom() {
77
		$classeNom = '';
78
		if ($this->ressources->getNombre() == 2) {
79
			if ($this->ressources->getServiceNom() == 'noms') {
80
				$classeNom = 'NomsListe';
81
			} else if ($this->ressources->getServiceNom() == 'taxons') {
82
				$classeNom = 'TaxonsListe';
83
			}
84
 
85
		} else if ($this->ressources->getNombre() == 3) {
86
			$position3 = $this->ressources->getParPosition(2);
87
			if ($this->ressources->etreId($position3)) {
88
				if ($this->ressources->getServiceNom() == 'noms') {
89
					$classeNom = 'NomDetails';
90
				} else if ($this->ressources->getServiceNom() == 'taxons') {
91
					$classeNom = 'TaxonDetails';
92
				}
93
			}
94
		} else if ($this->ressources->getNombre() == 4) {
95
			$position3 = $this->ressources->getParPosition(2);
96
			$position4 = $this->ressources->getParPosition(3);
97
			if ($this->ressources->etreStats($position3)) {
98
				if ($this->ressources->etreTypeDeStats($position4)) {
99
					$classeNom = 'NomsStats'.ucfirst($position4);
100
				}
101
			} else if ($this->ressources->etreId($position3)) {
102
				if ($this->ressources->etreRelations($position4)) {
103
					$classeNom = 'NomRelations';
104
				}
105
			}
106
		} else if ($this->ressources->getNombre() == 5) {
107
			$position3 = $this->ressources->getParPosition(2);
108
			$position4 = $this->ressources->getParPosition(3);
109
			$position5 = $this->ressources->getParPosition(4);
110
			if ($this->ressources->etreId($position3)) {
111
				if ($this->ressources->etreRelations($position4)) {
112
					if ($this->ressources->etreTypeDeRelations($position5)) {
113
						$classeNom = 'NomRelations'.ucfirst($position5);
114
					}
115
				}
116
			}
117
		}
207 jpm 118
		$classeNomProjet = $classeNom.'Generique';//.ucfirst($this->getNom());
201 jpm 119
		return $classeNomProjet;
163 jpm 120
	}
121
 
122
	public function verifier() {
123
		$this->paramsVerif->verifier();
124
		$this->ressourcesVerif->verifier();
125
		$this->verifierExistanceServiceClasse();
126
	}
127
 
128
	private function verifierExistanceServiceClasse() {
129
		$service = $this->ressources->getServiceNom();
130
		$classe = $this->getServiceClasseNom();
131
		$projet = $this->getNom();
132
 
133
		$chemins = array();
134
		$chemins[] = $this->cheminBase.$projet.DS.$classe.'.php';
135
		$chemins[] = $this->cheminBase.'commun'.DS.$classe.'.php';
136
 
137
		$existe = false;
138
		foreach ($chemins as $chemin) {
139
			if (file_exists($chemin)) {
140
				$existe = true;
141
				break;
142
			}
143
		}
144
		if ($existe === false) {
145
			$message = "La classe '$classe' du service demandé '$service' n'existe pas dans le projet '$projet' !";
146
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
147
			throw new Exception($message, $code);
148
		}
149
	}
150
 
151
}
152
?>