Subversion Repositories eFlore/Applications.del

Rev

Rev 943 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 943 Rev 1795
1
<?php
1
<?php
-
 
2
// declare(encoding='UTF-8');
2
/**
3
/**
3
* Description :
-
 
4
* Classe principale de chargement des services d'eFlore.
4
 * Classe principale de chargement des sous-services Noms et Taxons utilisés par DEL.
5
*
5
 *
6
* Encodage en entrée : utf8
6
 * @category   DEL
7
* Encodage en sortie : utf8
7
 * @package    Services
8
* @package eflore-projets
8
 * @subpackage NomsTaxons
9
* @author Jennifer DHÉ <jennifer.dhe@tela-botanica.org>
9
 * @version    0.1
10
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
10
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
11
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
11
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
-
 
12
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
12
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
14
 * @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)
15
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
16
*/
16
 */
17
class Nomstaxons extends RestService {
17
class Nomstaxons extends RestService {
18
 
18
 
19
	
19
 
20
	private $parametres = array();
20
	private $parametres = array();
21
	private $ressources = array();
21
	private $ressources = array();
22
	private $methode = null;
22
	private $methode = null;
23
	private $projetNom = array();
23
	private $projetNom = array();
24
	private $serviceNom = array();
24
	private $serviceNom = array();
25
	private $cheminCourant = null;
25
	private $cheminCourant = null;
26
 
26
 
27
	private $conteneur;
27
	private $conteneur;
28
	
28
 
29
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
29
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
30
	protected $utilisationParametresBruts = true;
30
	protected $utilisationParametresBruts = true;
31
 
31
 
32
	public function __construct() {
32
	public function __construct() {
33
		$this->cheminCourant = dirname(__FILE__).DS;
33
		$this->cheminCourant = dirname(__FILE__).DS;
34
	}
34
	}
35
 
35
 
36
	public function consulter($ressources, $parametres) {
36
	public function consulter($ressources, $parametres) {
37
		$this->methode = 'consulter';
37
		$this->methode = 'consulter';
38
		$resultat = '';
38
		$resultat = '';
39
		$reponseHttp = new ReponseHttp();
39
		$reponseHttp = new ReponseHttp();
40
		try {
40
		try {
41
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
41
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
42
			$this->conteneur = new Conteneur($this->parametres);
42
			$this->conteneur = new Conteneur($this->parametres);
43
			$resultat = $this->traiterRessources();
43
			$resultat = $this->traiterRessources();
44
			$reponseHttp->setResultatService($resultat);
44
			$reponseHttp->setResultatService($resultat);
45
		} catch (Exception $e) {
45
		} catch (Exception $e) {
46
			$reponseHttp->ajouterErreur($e);
46
			$reponseHttp->ajouterErreur($e);
47
		}
47
		}
48
		$reponseHttp->emettreLesEntetes();
48
		$reponseHttp->emettreLesEntetes();
49
		$corps = $reponseHttp->getCorps();
49
		$corps = $reponseHttp->getCorps();
50
		return $corps;
50
		return $corps;
51
	}
51
	}
52
	
52
 
53
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
53
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
54
		$this->ressources = $ressources;
54
		$this->ressources = $ressources;
55
		$this->parametres = $parametres;
55
		$this->parametres = $parametres;
56
	}
56
	}
57
 
57
 
58
	private function traiterRessources() {
58
	private function traiterRessources() {
59
		$retour = '';
59
		$retour = '';
60
		$this->initialiserProjet();
60
		$this->initialiserProjet();
61
		$retour = $this->initialiserService();
61
		$retour = $this->initialiserService();
62
		return $retour;
62
		return $retour;
63
	}
63
	}
64
 
64
 
65
	/*------------------------------------------------------------------------------------------------------------------
65
	/*------------------------------------------------------------------------------------------------------------------
66
										CONFIGURATION DU PROJET
66
										CONFIGURATION DU PROJET
67
	------------------------------------------------------------------------------------------------------------------*/
67
	------------------------------------------------------------------------------------------------------------------*/
68
	private function initialiserProjet() {
68
	private function initialiserProjet() {
69
		$this->projetNom = 'nomstaxons';
69
		$this->projetNom = 'nomstaxons';
70
		$this->chargerConfigProjet();
70
		$this->chargerConfigProjet();
71
	}
71
	}
72
 
72
 
73
	private function chargerConfigProjet() {
73
	private function chargerConfigProjet() {
74
		$projet = $this->projetNom;
74
		$projet = $this->projetNom;
75
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
75
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
76
		Config::charger($chemin);
76
		Config::charger($chemin);
77
	}
77
	}
78
 
78
 
79
	/*------------------------------------------------------------------------------------------------------------------
79
	/*------------------------------------------------------------------------------------------------------------------
80
								CONFIGURATION DU SERVICE
80
								CONFIGURATION DU SERVICE
81
	------------------------------------------------------------------------------------------------------------------*/
81
	------------------------------------------------------------------------------------------------------------------*/
82
	private function initialiserService() {
82
	private function initialiserService() {
83
		$this->chargerNomService();
83
		$this->chargerNomService();
84
				
84
 
85
		$classe = $this->obtenirNomClasseService($this->serviceNom);
85
		$classe = $this->obtenirNomClasseService($this->serviceNom);
86
		$chemins = array();
86
		$chemins = array();
87
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
87
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
88
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
88
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
89
		$retour = '';
89
		$retour = '';
90
		$service = null;
90
		$service = null;
91
		foreach ($chemins as $chemin) {
91
		foreach ($chemins as $chemin) {
92
			if (file_exists($chemin)) {
92
			if (file_exists($chemin)) {
93
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
93
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
94
				require_once $chemin;
94
				require_once $chemin;
95
				$service = new $classe($this->conteneur);
95
				$service = new $classe($this->conteneur);
96
				if ($this->methode == 'consulter') {
96
				if ($this->methode == 'consulter') {
97
					$retour = $service->consulter($this->ressources, $this->parametres);
97
					$retour = $service->consulter($this->ressources, $this->parametres);
98
				} else {
98
				} else {
99
					//TODO : throw exception
99
					//TODO : throw exception
100
				}
100
				}
101
			}
101
			}
102
		}
102
		}
103
		
103
 
104
		if (is_null($service)) {
104
		if (is_null($service)) {
105
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
105
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
106
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
106
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
107
			throw new Exception($message, $code);
107
			throw new Exception($message, $code);
108
		}
108
		}
109
		return $retour;
109
		return $retour;
110
	}
110
	}
111
	
111
 
112
	private function chargerNomService() {
112
	private function chargerNomService() {
113
		// si la méthode est POST, on ajouter un commentaire
113
		// si la méthode est POST, on ajouter un commentaire
114
		$this->serviceNom = 'liste-taxons';
114
		$this->serviceNom = 'liste-taxons';
115
	}
115
	}
116
 
116
 
117
	private function obtenirNomClasseService($mot) {
117
	private function obtenirNomClasseService($mot) {
118
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
118
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
119
		return $classeNom;
119
		return $classeNom;
120
	}
120
	}
121
}
121
}
122
?>
122
?>