Subversion Repositories eFlore/Applications.del

Rev

Rev 1779 | Details | Compare with Previous | 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
 
1877 jpm 19
 
1593 samuel 20
	/*
1877 jpm 21
	 * url possibles :
1593 samuel 22
	 * */
1877 jpm 23
 
1593 samuel 24
	private $parametres = array();
25
	private $ressources = array();
26
	private $methode = null;
1877 jpm 27
	private $projetNom = 'plantnet';
28
	private $serviceNom = 'changements';
1593 samuel 29
	private $cheminCourant = null;
30
 
31
	private $conteneur;
1877 jpm 32
 
1593 samuel 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
                        $resultat = $this->initialiserService();
52
 
53
			$reponseHttp->setResultatService($resultat);
54
 
55
		} catch (Exception $e) {
56
			$reponseHttp->ajouterErreur($e);
57
		}
58
		$reponseHttp->emettreLesEntetes();
59
		$corps = $reponseHttp->getCorps();
60
		return $corps;
61
	}
62
 
63
 
64
 
65
 
1877 jpm 66
 
1593 samuel 67
	/*------------------------------------------------------------------------------------------------------------------
68
								CONFIGURATION DU SERVICE
69
	------------------------------------------------------------------------------------------------------------------*/
70
 
1877 jpm 71
 
72
 
1593 samuel 73
	private function initialiserService() {
1877 jpm 74
 
1593 samuel 75
		$classe = $this->obtenirNomClasseService($this->serviceNom);
76
		$chemins = array();
77
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
78
		$retour = '';
79
		$service = null;
80
		foreach ($chemins as $chemin) {
81
                  if (file_exists($chemin)) {
82
                    require_once $chemin;
1877 jpm 83
 
1593 samuel 84
                    $service = new $classe($this->conteneur);
85
                    $retour = $service->consulter($this->ressources, $this->parametres);
1877 jpm 86
 
1593 samuel 87
                  }
88
		}
1877 jpm 89
 
1593 samuel 90
		if (is_null($service)) {
91
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
92
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
93
			throw new Exception($message, $code);
94
		}
95
		return $retour;
96
	}
97
 
98
	private function obtenirNomClasseService($mot) {
99
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
100
		return $classeNom;
101
	}
102
}
103
?>