Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
943 gduche 1
<?php
1795 jpm 2
// declare(encoding='UTF-8');
943 gduche 3
/**
1795 jpm 4
 * Classe principale de chargement des sous-services Noms et Taxons utilisés par DEL.
5
 *
6
 * @category   DEL
7
 * @package    Services
8
 * @subpackage NomsTaxons
9
 * @version    0.1
10
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
11
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
13
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
16
 */
943 gduche 17
class Nomstaxons extends RestService {
18
 
1795 jpm 19
 
943 gduche 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;
1795 jpm 28
 
943 gduche 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
	}
1795 jpm 52
 
943 gduche 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
										CONFIGURATION DU PROJET
67
	------------------------------------------------------------------------------------------------------------------*/
68
	private function initialiserProjet() {
69
		$this->projetNom = 'nomstaxons';
70
		$this->chargerConfigProjet();
71
	}
72
 
73
	private function chargerConfigProjet() {
74
		$projet = $this->projetNom;
75
		$chemin = Config::get('chemin_configurations')."config_$projet.ini";
76
		Config::charger($chemin);
77
	}
78
 
79
	/*------------------------------------------------------------------------------------------------------------------
80
								CONFIGURATION DU SERVICE
81
	------------------------------------------------------------------------------------------------------------------*/
82
	private function initialiserService() {
83
		$this->chargerNomService();
1795 jpm 84
 
943 gduche 85
		$classe = $this->obtenirNomClasseService($this->serviceNom);
86
		$chemins = array();
87
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
88
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
89
		$retour = '';
90
		$service = null;
91
		foreach ($chemins as $chemin) {
92
			if (file_exists($chemin)) {
93
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
94
				require_once $chemin;
95
				$service = new $classe($this->conteneur);
96
				if ($this->methode == 'consulter') {
97
					$retour = $service->consulter($this->ressources, $this->parametres);
98
				} else {
99
					//TODO : throw exception
100
				}
101
			}
102
		}
1795 jpm 103
 
943 gduche 104
		if (is_null($service)) {
105
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
106
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
107
			throw new Exception($message, $code);
108
		}
109
		return $retour;
110
	}
1795 jpm 111
 
943 gduche 112
	private function chargerNomService() {
113
		// si la méthode est POST, on ajouter un commentaire
114
		$this->serviceNom = 'liste-taxons';
115
	}
116
 
117
	private function obtenirNomClasseService($mot) {
118
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
119
		return $classeNom;
120
	}
121
}
122
?>