Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
1593 samuel 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 PlantNet extends RestService {
18
 
19
 
20
	/*
21
	 * url possibles :
22
	 * */
23
 
24
	private $parametres = array();
25
	private $ressources = array();
26
	private $methode = null;
27
	private $projetNom = array();
28
	private $serviceNom = array();
29
	private $cheminCourant = null;
30
 
31
	private $conteneur;
32
 
33
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
34
	protected $utilisationParametresBruts = true;
35
 
36
	public function __construct() {
37
		$this->cheminCourant = dirname(__FILE__).DS;
38
	}
39
 
40
	public function consulter($ressources, $parametres) {
41
		$this->methode = 'consulter';
42
		$resultat = '';
43
		$reponseHttp = new ReponseHttp();
44
		try {
45
                        $this->ressources = $ressources;
46
                        $this->parametres = $parametres;
47
 
48
 
49
			$this->conteneur = new Conteneur($this->parametres);
50
 
51
                        $this->projetNom = 'plantnet';
52
                        $this->serviceNom = 'changements';
53
 
54
                        // init projet
55
                        $projet = $this->projetNom;
56
                        $chemin = Config::get('chemin_configurations')."config_$projet.ini";
57
                        Config::charger($chemin);
58
 
59
                        $resultat = $this->initialiserService();
60
 
61
			$reponseHttp->setResultatService($resultat);
62
 
63
		} catch (Exception $e) {
64
			$reponseHttp->ajouterErreur($e);
65
		}
66
		$reponseHttp->emettreLesEntetes();
67
		$corps = $reponseHttp->getCorps();
68
		return $corps;
69
	}
70
 
71
 
72
 
73
 
74
 
75
	/*------------------------------------------------------------------------------------------------------------------
76
								CONFIGURATION DU SERVICE
77
	------------------------------------------------------------------------------------------------------------------*/
78
 
79
 
80
 
81
	private function initialiserService() {
82
 
83
		$classe = $this->obtenirNomClasseService($this->serviceNom);
84
		$chemins = array();
85
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
86
		$retour = '';
87
		$service = null;
88
		foreach ($chemins as $chemin) {
89
                  if (file_exists($chemin)) {
90
 
91
 
92
                    $this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
93
                    require_once $chemin;
94
 
95
                    $service = new $classe($this->conteneur);
96
                    $retour = $service->consulter($this->ressources, $this->parametres);
97
 
98
                  }
99
		}
100
 
101
		if (is_null($service)) {
102
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
103
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
104
			throw new Exception($message, $code);
105
		}
106
		return $retour;
107
	}
108
 
109
	private function obtenirNomClasseService($mot) {
110
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
111
		return $classeNom;
112
	}
113
}
114
?>