Subversion Repositories eFlore/Applications.del

Rev

Rev 1174 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
803 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 Utilisateurs extends RestService {
18
 
19
 
20
	private $parametres = array();
21
	private $ressources = array();
22
	private $methode = null;
23
	private $projetNom = array();
24
	private $serviceNom = array();
25
	private $cheminCourant = null;
26
 
27
	private $conteneur;
28
 
29
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
30
	protected $utilisationParametresBruts = true;
31
 
32
	public function __construct() {
33
		$this->cheminCourant = dirname(__FILE__).DS;
34
	}
35
 
36
	public function consulter($ressources, $parametres) {
37
		$this->methode = 'consulter';
38
		$resultat = '';
39
		$reponseHttp = new ReponseHttp();
40
		try {
41
			$this->initialiserRessourcesEtParametres($ressources, $parametres);
42
			$this->conteneur = new Conteneur($this->parametres);
43
			$resultat = $this->traiterRessources();
44
			$reponseHttp->setResultatService($resultat);
45
		} catch (Exception $e) {
46
			$reponseHttp->ajouterErreur($e);
47
		}
48
		$reponseHttp->emettreLesEntetes();
49
		$corps = $reponseHttp->getCorps();
50
		return $corps;
51
	}
52
 
53
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
54
		$this->ressources = $ressources;
55
		$this->parametres = $parametres;
56
	}
57
 
58
	private function traiterRessources() {
59
		$retour = '';
60
		$this->initialiserProjet();
61
		$retour = $this->initialiserService();
62
		return $retour;
63
	}
64
 
65
 
66
	/*------------------------------------------------------------------------------------------------------------------
67
										CONFIGURATION DU PROJET
68
	------------------------------------------------------------------------------------------------------------------*/
69
	private function initialiserProjet() {
70
		$this->projetNom = 'utilisateurs';
71
		$this->chargerConfigProjet();
72
	}
73
 
74
	private function chargerConfigProjet() {
75
		$projet = $this->projetNom;
76
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
77
		Config::charger($chemin);
78
	}
79
 
80
	/*------------------------------------------------------------------------------------------------------------------
81
								CONFIGURATION DU SERVICE
82
	------------------------------------------------------------------------------------------------------------------*/
83
	private function initialiserService() {
84
 
85
		$this->chargerNomService();
86
 
87
		$classe = $this->obtenirNomClasseService($this->serviceNom);
88
		$chemins = array();
89
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
90
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
91
		$retour = '';
92
		$service = null;
93
		foreach ($chemins as $chemin) {
94
			if (file_exists($chemin)) {
95
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
96
 
97
				require_once $chemin;
98
				$service = new $classe($this->conteneur);
99
				if ($this->methode == 'consulter') {
100
					$retour = $service->consulter($this->ressources, $this->parametres);
101
				} elseif ($this->methode == 'ajouter') {
102
					$retour = $service->ajouter($this->ressources, $this->parametres);
103
				}
104
			}
105
		}
106
 
107
		if (is_null($service)) {
108
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
109
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
110
			throw new Exception($message, $code);
111
		}
112
		return $retour;
113
	}
114
 
115
	private function chargerNomService() {
116
		//S'il n'y a pas de ressources => envoyer sur identification anonyme
117
		if (!isset($this->ressources) || empty($this->ressources)) {
118
			$this->serviceNom = 'identification-anonyme';
119
		} else {
120
			//S'il y a 1 ressource et que celle ci est 'deconnecter', envoyer vers deconnecter
121
			if (sizeof($this->ressources) == 1 && ($this->ressources[0] == 'deconnecter')) {
122
				$this->serviceNom = 'deconnecter';
123
			} else if (sizeof($this->ressources) == 2) {
124
				$this->serviceNom = 'connecter';
125
			} else {
126
				$this->serviceNom = 'identification-anonyme';
127
			}
128
		}
129
	}
130
 
131
	private function obtenirNomClasseService($mot) {
132
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
133
		return $classeNom;
134
	}
135
 
136
 
137
}
138
?>