Subversion Repositories eFlore/Applications.del

Rev

Rev 935 | Rev 1707 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
935 gduche 1
<?php
2
/**
3
* Description :
4
* Classe principale de chargement des services d'eFlore.
5
*
6
* Encodage en entrée : utf8
7
* Encodage en sortie : utf8
8
* @package eflore-projets
9
* @author Jennifer DHÉ <jennifer.dhe@tela-botanica.org>
10
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
11
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
* @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
* @version 0.1
15
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
16
*/
17
class Communes extends RestService {
18
 
19
	private $parametres = array();
20
	private $ressources = array();
21
	private $methode = null;
22
	private $projetNom = array();
23
	private $serviceNom = array();
24
	private $cheminCourant = null;
25
 
26
	private $conteneur;
1700 jpm 27
 
935 gduche 28
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
29
	protected $utilisationParametresBruts = true;
30
 
31
	public function __construct() {
32
		$this->cheminCourant = dirname(__FILE__).DS;
33
	}
34
 
35
	public function consulter($ressources, $parametres) {
36
		$this->methode = 'consulter';
37
		$resultat = '';
38
		$reponseHttp = new ReponseHttp();
39
		try {
40
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
41
			$this->conteneur = new Conteneur($this->parametres);
42
			$resultat = $this->traiterRessources();
43
			$reponseHttp->setResultatService($resultat);
44
		} catch (Exception $e) {
45
			$reponseHttp->ajouterErreur($e);
46
		}
47
		$reponseHttp->emettreLesEntetes();
48
		$corps = $reponseHttp->getCorps();
49
		return $corps;
50
	}
1700 jpm 51
 
935 gduche 52
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
53
		$this->ressources = $ressources;
54
		$this->parametres = $parametres;
55
	}
56
 
57
	private function traiterRessources() {
58
		$retour = '';
59
		$this->initialiserProjet();
60
		$retour = $this->initialiserService();
61
		return $retour;
62
	}
63
 
64
	/*------------------------------------------------------------------------------------------------------------------
65
										CONFIGURATION DU PROJET
66
	------------------------------------------------------------------------------------------------------------------*/
67
	private function initialiserProjet() {
68
		$this->projetNom = 'communes';
69
		$this->chargerConfigProjet();
70
	}
71
 
72
	private function chargerConfigProjet() {
73
		$projet = $this->projetNom;
74
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
75
		Config::charger($chemin);
76
	}
77
 
78
	/*------------------------------------------------------------------------------------------------------------------
79
								CONFIGURATION DU SERVICE
80
	------------------------------------------------------------------------------------------------------------------*/
81
	private function initialiserService() {
82
		$this->chargerNomService();
1700 jpm 83
 
935 gduche 84
		$classe = $this->obtenirNomClasseService($this->serviceNom);
85
		$chemins = array();
86
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
87
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
88
		$retour = '';
89
		$service = null;
90
		foreach ($chemins as $chemin) {
91
			if (file_exists($chemin)) {
92
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
93
				require_once $chemin;
94
				$service = new $classe($this->conteneur);
95
				if ($this->methode == 'consulter') {
96
					$retour = $service->consulter($this->ressources, $this->parametres);
97
				} else {
98
					//TODO : throw exception
99
				}
100
			}
101
		}
1700 jpm 102
 
935 gduche 103
		if (is_null($service)) {
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
	}
1700 jpm 110
 
935 gduche 111
	private function chargerNomService() {
112
		// si la méthode est POST, on ajouter un commentaire
113
		$this->serviceNom = 'liste-communes';
114
	}
115
 
116
	private function obtenirNomClasseService($mot) {
117
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
118
		return $classeNom;
119
	}
120
}
121
?>