Subversion Repositories eFlore/Projets.eflore-projets

Rev

Rev 653 | Rev 792 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 653 Rev 791
Line 25... Line 25...
25
	private $projetNom = array();
25
	private $projetNom = array();
26
	/** Nom du service demandé. */
26
	/** Nom du service demandé. */
27
	private $serviceNom = array();
27
	private $serviceNom = array();
28
	/** Chemin vers le dossier courrant. */
28
	/** Chemin vers le dossier courrant. */
29
	private $cheminCourrant = null;
29
	private $cheminCourrant = null;
-
 
30
	private $classe = null;
Line 30... Line 31...
30
 
31
 
Line 31... Line 32...
31
	private $cache;
32
	private $cache;
32
 
33
 
Line 59... Line 60...
59
 
60
 
60
	private function traiterRessources() {
61
	private function traiterRessources() {
61
		$retour = '';
62
		$retour = '';
62
		if ($this->avoirRessources()) {
63
		if ($this->avoirRessources()) {
-
 
64
			if ($this->avoirRessourceProjet()) {
63
			if ($this->avoirRessourceProjet()) {
65
				$this->chargerNomDuService(); // défini $this->serviceNom
64
				$this->initialiserProjet();
66
				$this->initialiserProjet(); // autoload defined here
-
 
67
				if ($this->avoirRessourceService()) {
65
				if ($this->avoirRessourceService()) {
68
					$this->classe = self::definirClasseNeeded($this->projetNom, $this->serviceNom);
66
					$retour = $this->initialiserService();
69
					$retour = $this->initialiserService();
67
				}
70
				}
68
			}
71
			}
69
		}
72
		}
Line 118... Line 121...
118
		$projet = $this->projetNom;
121
		$projet = $this->projetNom;
119
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
122
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
120
		Config::charger($chemin);
123
		Config::charger($chemin);
121
	}
124
	}
Line -... Line 125...
-
 
125
 
-
 
126
	/*
-
 
127
	  1) jusqu'à présent:
-
 
128
	  * le principe pour URL = a/b est: de charger
-
 
129
	  * require_once($chemin/a/ucfirst(c).php)
-
 
130
	  * new ucfirst(c); ucfirst(c)->consulter()
-
 
131
	  * sachant que ucfirst(c).php et la classe ucfirst(c) apparaîssent à de multiples emplacements (selon a)
-
 
132
 
-
 
133
	  1") Beurk... (php-className conflicts en PHP 5.2)
-
 
134
 
-
 
135
	  Ici nous faisons des cas particuliers pour Ontologies, mais en suivant ce principe, sont affectés:
-
 
136
	  Cartes, EfloreOntologiesTest, Images, Informations, InformationsTaxonsSup,
-
 
137
	  LegendeCartes, NomCommune, Noms, NomsVernaculaires, Projets, Statuts,
-
 
138
	  Taxons, TaxonsCartes, Textes, ZoneGeo
-
 
139
 
-
 
140
	  cf:
-
 
141
	  $ grep -r '^[cC]lass '|grep -F '.php:'|egrep -w " \($(grep -rh '^[cC]lass '|awk '{print $2}'|sort|uniq -d|tr "\n" '|')\) " \
-
 
142
	  |sort -k2
-
 
143
 
-
 
144
	  PS: "Using two class with the same name"
-
 
145
	  http://stackoverflow.com/questions/4555186/using-two-class-with-the-same-name
-
 
146
	  > Stop.
-
 
147
	  > Whatever you are doing is wrong. Backup. Re-evaluate what you are doing and why.
-
 
148
	*/
-
 
149
	private static function definirClasseNeeded($p, $s) {
-
 
150
		if($s != 'ontologies') return NULL;
-
 
151
 
-
 
152
		switch($p) {
-
 
153
		case 'baseflor':
-
 
154
			return 'BaseFloreOntologies';
-
 
155
		case 'eflore':
-
 
156
			return 'EfloreOntologies';
-
 
157
		case 'chorodep':
-
 
158
			return 'ChorodepOntologies';
-
 
159
		case 'baseveg':
-
 
160
			return 'BasevegOntologies';
-
 
161
		case 'moissonnage':
-
 
162
			return 'MoissonnnageOntologies';
-
 
163
		case 'commun':
-
 
164
			return 'Ontologies';
-
 
165
		}
-
 
166
		return NULL;
-
 
167
	}
122
 
168
 
123
	private function chargerClasseProjet($classe) {
169
	private function chargerClasseProjet($classe) {
124
		if (class_exists($classe)) {
170
		if (class_exists($classe)) {
125
			return null;
171
			return null;
Line -... Line 172...
-
 
172
		}
-
 
173
 
-
 
174
		if($this->serviceNom == 'ontologies') {
-
 
175
			$c = NULL;
-
 
176
			switch($this->projetNom) {
-
 
177
			case 'baseflor':
-
 
178
				$c = 'BaseFloreOntologies';
-
 
179
				break;
-
 
180
			case 'eflore':
-
 
181
				$c = 'EfloreOntologies';
-
 
182
				break;
-
 
183
			case 'chorodep':
-
 
184
				$c = 'ChorodepOntologies';
-
 
185
				break;
-
 
186
			case 'baseveg':
-
 
187
				$c = 'BasevegOntologies';
-
 
188
				break;
-
 
189
			case 'moissonnage':
-
 
190
				$c = 'MoissonnnageOntologies';
-
 
191
				break;
-
 
192
			case 'commun':
-
 
193
				$c = 'Ontologies';
-
 
194
				break;
-
 
195
			}
-
 
196
			if($c) {
-
 
197
				require_once($this->cheminCourrant . 'commun' . DS . 'Commun.php');
-
 
198
				require_once($this->cheminCourrant . $this->projetNom . DS . $this->obtenirNomClasseService($this->serviceNom) . '.php');
-
 
199
				return;
-
 
200
			}
126
		}
201
		}
127
 
202
 
128
		$cheminBiblio = Config::get('chemin_bibliotheque');
203
		$cheminBiblio = Config::get('chemin_bibliotheque');
129
		$chemins = array();
204
		$chemins = array();
130
		$chemins[] = $this->cheminCourrant.$this->projetNom.DS;
205
		$chemins[] = $this->cheminCourrant.$this->projetNom.DS;
Line 162... Line 237...
162
		}
237
		}
163
		return $presenceRessourceService;
238
		return $presenceRessourceService;
164
	}
239
	}
Line 165... Line 240...
165
 
240
 
166
	private function initialiserService() {
241
	private function initialiserService() {
-
 
242
		if($this->classe) {
-
 
243
			$classe = $this->classe;
-
 
244
			$service = new $classe($this->getBdd());
-
 
245
			return $service->consulter($ressourcesPourService, $this->parametres);
-
 
246
		}
167
		$this->chargerNomDuService();
247
 
168
		$classe = $this->obtenirNomClasseService($this->serviceNom);
248
		$classe = $this->obtenirNomClasseService($this->serviceNom);
169
		$chemins = array();
249
		$chemins = array();
170
		$chemins[] = $this->cheminCourrant.$this->projetNom.DS.$classe.'.php';
250
		$chemins[] = $this->cheminCourrant.$this->projetNom.DS.$classe.'.php';
Line 171... Line -...
171
		$chemins[] = $this->cheminCourrant.'commun'.DS.$classe.'.php';
-
 
172
 
251
		$chemins[] = $this->cheminCourrant.'commun'.DS.$classe.'.php';
173
		$retour = '';
252
 
174
		$service = null;
253
		$service = null;
175
		foreach ($chemins as $chemin) {
254
		foreach ($chemins as $chemin) {
176
			if (file_exists($chemin)) {
255
			if (file_exists($chemin)) {
177
				$service = new $classe($this->getBdd());
256
				$service = new $classe($this->getBdd());
178
				$ressourcesPourService = $this->filtrerRessourcesPourService();
257
				$ressourcesPourService = $this->filtrerRessourcesPourService();
179
				$this->cache = new CacheEflore($service, $this->projetNom, $this->serviceNom, Config::get('cache'));
258
				$this->cache = new CacheEflore($service, $this->projetNom, $this->serviceNom, Config::get('cache'));
180
				$retour = $this->cache->consulter($ressourcesPourService, $this->parametres);
259
				return $this->cache->consulter($ressourcesPourService, $this->parametres);
181
			}
260
			}
182
		}
261
		}
183
		if (is_null($service)) {
262
		if (is_null($service)) {
184
			$message = "La service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
263
			$message = "La service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
185
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
264
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
186
			throw new Exception($message, $code);
265
			throw new Exception($message, $code);
187
		}
266
		}
Line 188... Line 267...
188
		return $retour;
267
		return NULL;
189
	}
268
	}
190
 
269
 
Line 191... Line 270...
191
	private function chargerNomDuService() {
270
	private function chargerNomDuService() {
192
		$this->serviceNom = $this->ressources[1];
271
		$this->serviceNom = $this->ressources[1];
193
	}
-
 
194
 
272
	}
Line 195... Line 273...
195
	private function obtenirNomClasseService($mot) {
273
 
196
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
274
	private function obtenirNomClasseService($mot) {
197
		return $classeNom;
275
		return str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));