Subversion Repositories eFlore/Applications.del

Rev

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

Rev 1700 Rev 1707
Line 1... Line 1...
1
<?php
1
<?php
2
/**
2
/**
3
* Description :
-
 
4
* Classe principale de chargement des services d'eFlore.
3
 * Classe principale de chargement des sous-services d'accès aux infos sur les communes.
5
*
4
 *
6
* Encodage en entrée : utf8
5
 * Encodage en entrée : utf8
7
* Encodage en sortie : utf8
6
 * Encodage en sortie : utf8
-
 
7
 *
-
 
8
 * @category	DEL
8
* @package eflore-projets
9
 * @package		Services
-
 
10
 * @subpackage	Communes
-
 
11
 * @version		0.1
9
* @author Jennifer DHÉ <jennifer.dhe@tela-botanica.org>
12
 * @author		Jennifer DHÉ <jennifer.dhe@tela-botanica.org>
10
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
13
 * @author		Delphine CAUQUIL <delphine@tela-botanica.org>
11
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
14
 * @author		Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license		GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @license		CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
* @version 0.1
-
 
15
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
17
 * @copyright	©1999-2014, Tela Botanica (<accueil@tela-botanica.org>)
16
*/
18
 */
17
class Communes extends RestService {
19
class Communes extends RestService {
Line 18... Line 20...
18
 
20
 
19
	private $parametres = array();
21
	private $parametres = array();
20
	private $ressources = array();
22
	private $ressources = array();
21
	private $methode = null;
23
	private $methode = null;
22
	private $projetNom = array();
24
	private $serviceNom = 'communes';
23
	private $serviceNom = array();
25
	private $sousServiceNom = null;
Line 24... Line 26...
24
	private $cheminCourant = null;
26
	private $cheminCourant = null;
Line 25... Line 27...
25
 
27
 
Line 32... Line 34...
32
		$this->cheminCourant = dirname(__FILE__).DS;
34
		$this->cheminCourant = dirname(__FILE__).DS;
33
	}
35
	}
Line 34... Line 36...
34
 
36
 
35
	public function consulter($ressources, $parametres) {
37
	public function consulter($ressources, $parametres) {
-
 
38
		$this->methode = 'consulter';
-
 
39
		$this->initialiserRessourcesEtParametres($ressources, $parametres);
-
 
40
		return $this->executerService();
-
 
41
	}
-
 
42
 
36
		$this->methode = 'consulter';
43
	private function initialiserRessourcesEtParametres($ressources, $parametres = array()) {
-
 
44
		$this->ressources = $ressources;
-
 
45
		$this->parametres = $parametres;
-
 
46
	}
-
 
47
 
37
		$resultat = '';
48
	private function executerService() {
38
		$reponseHttp = new ReponseHttp();
49
		$reponseHttp = new ReponseHttp();
39
		try {
-
 
40
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
50
		try {
41
			$this->conteneur = new Conteneur($this->parametres);
51
			$this->conteneur = new Conteneur($this->parametres);
42
			$resultat = $this->traiterRessources();
52
			$resultat = $this->traiterRessources();
43
			$reponseHttp->setResultatService($resultat);
53
			$reponseHttp->setResultatService($resultat);
44
		} catch (Exception $e) {
54
		} catch (Exception $e) {
Line 47... Line 57...
47
		$reponseHttp->emettreLesEntetes();
57
		$reponseHttp->emettreLesEntetes();
48
		$corps = $reponseHttp->getCorps();
58
		$corps = $reponseHttp->getCorps();
49
		return $corps;
59
		return $corps;
50
	}
60
	}
Line 51... Line -...
51
 
-
 
52
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
-
 
53
		$this->ressources = $ressources;
-
 
54
		$this->parametres = $parametres;
-
 
55
	}
-
 
56
 
61
 
57
	private function traiterRessources() {
62
	private function traiterRessources() {
58
		$retour = '';
63
		$this->chargerConfigService();
59
		$this->initialiserProjet();
64
		$this->analyserRessources();
60
		$retour = $this->initialiserService();
65
		$retour = $this->initialiserService();
61
		return $retour;
66
		return $retour;
Line 62... Line -...
62
	}
-
 
63
 
-
 
64
	/*------------------------------------------------------------------------------------------------------------------
-
 
65
										CONFIGURATION DU PROJET
67
	}
66
	------------------------------------------------------------------------------------------------------------------*/
68
 
67
	private function initialiserProjet() {
69
	private function chargerConfigService() {
68
		$this->projetNom = 'communes';
70
		$chemin = Config::get('chemin_configurations')."config_{$this->serviceNom}.ini";
Line 69... Line 71...
69
		$this->chargerConfigProjet();
71
		Config::charger($chemin);
-
 
72
	}
70
	}
73
 
-
 
74
	private function analyserRessources() {
-
 
75
		if ($this->methode == 'consulter') {
-
 
76
			if (count($this->ressources) == 0) {
-
 
77
				if ($this->verifierPresenceParametre('masque.nom')) {
71
 
78
					$this->sousServiceNom = 'liste-communes';
-
 
79
				} else {
-
 
80
					$message = "Le service demandé '{$this->serviceNom}' ".
-
 
81
						"nécessite l'utilisation d'un paramètre (non vide) : masque.nom \n";
-
 
82
					$code = RestServeur::HTTP_CODE_ECHEC_CONDITION;
-
 
83
					throw new Exception($message, $code);
72
	private function chargerConfigProjet() {
84
				}
-
 
85
			}
-
 
86
		}
73
		$projet = $this->projetNom;
87
		if ($this->sousServiceNom == null) {
Line 74... Line 88...
74
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
88
			$this->lancerMessageErreurRessource();
75
		Config::charger($chemin);
89
		}
76
	}
90
	}
77
 
91
 
-
 
92
	private function verifierPresenceParametre($cle) {
78
	/*------------------------------------------------------------------------------------------------------------------
93
		$ok = false;
-
 
94
		if (isset($this->parametres[$cle]) && trim($this->parametres[$cle]) != '') {
Line -... Line 95...
-
 
95
			$ok = true;
-
 
96
		}
-
 
97
		return $ok;
-
 
98
	}
-
 
99
 
-
 
100
	private function lancerMessageErreurRessource() {
-
 
101
		$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
-
 
102
		$message = "La ressource demandée '$ressource' ".
-
 
103
			"n'est pas disponible pour le service ".$this->serviceNom." !\n".
-
 
104
			"Les URLs disponibles sont : \n".
-
 
105
			" - en GET : communes (paramètres : masque.nom) \n";
79
								CONFIGURATION DU SERVICE
106
		$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
80
	------------------------------------------------------------------------------------------------------------------*/
107
		throw new Exception($message, $code);
81
	private function initialiserService() {
108
	}
82
		$this->chargerNomService();
109
 
83
 
110
	private function initialiserService() {
84
		$classe = $this->obtenirNomClasseService($this->serviceNom);
111
		$classe = $this->obtenirNomClasseService($this->sousServiceNom);
-
 
112
		$chemins = array();
85
		$chemins = array();
113
		$chemins[] = $this->cheminCourant.$this->serviceNom.DS.$classe.'.php';
86
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
114
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
87
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
115
		$retour = '';
88
		$retour = '';
116
		$service = null;
89
		$service = null;
117
 
90
		foreach ($chemins as $chemin) {
118
		foreach ($chemins as $chemin) {
91
			if (file_exists($chemin)) {
119
			if (file_exists($chemin)) {
92
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
120
				$this->conteneur->chargerConfiguration('config_'.$this->serviceNom.'.ini');
-
 
121
				require_once $chemin;
-
 
122
				$service = new $classe($this->conteneur);
-
 
123
				if ($this->methode == 'consulter') {
93
				require_once $chemin;
124
					$retour = $service->consulter($this->ressources, $this->parametres);
94
				$service = new $classe($this->conteneur);
125
				} else {
95
				if ($this->methode == 'consulter') {
126
					$message = "Le sous-service '{$this->sousServiceNom}' du service '{$this->serviceNom}' ".
96
					$retour = $service->consulter($this->ressources, $this->parametres);
127
						"ne possède pas de méthode '{$this->methode}' !";
Line 97... Line 128...
97
				} else {
128
					$code = RestServeur::HTTP_NON_IMPLEMENTE;
-
 
129
					throw new Exception($message, $code);
98
					//TODO : throw exception
130
				}
-
 
131
			}
99
				}
132
		}
100
			}
133
 
101
		}
134
		if (is_null($service)) {
102
 
135
			$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
103
		if (is_null($service)) {
136
			$message = "Le classe '$classe' correspondant à la ressource '$ressource' ".
Line 104... Line -...
104
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
-
 
105
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
-
 
106
			throw new Exception($message, $code);
-
 
107
		}
-
 
108
		return $retour;
-
 
109
	}
137
				"est introuvable par le service '{$this->serviceNom}' !";
110
 
138
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
111
	private function chargerNomService() {
139
			throw new Exception($message, $code);
112
		// si la méthode est POST, on ajouter un commentaire
140
		}
113
		$this->serviceNom = 'liste-communes';
-
 
114
	}
-
 
115
 
141
		return $retour;
-
 
142
	}
116
	private function obtenirNomClasseService($mot) {
143