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 |
|
|
|
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 |
CONFIGURATION DU PROJET
|
|
|
67 |
------------------------------------------------------------------------------------------------------------------*/
|
|
|
68 |
private function initialiserProjet() {
|
|
|
69 |
$this->projetNom = 'communes';
|
|
|
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();
|
|
|
84 |
|
|
|
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 |
}
|
|
|
103 |
|
|
|
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 |
}
|
|
|
111 |
|
|
|
112 |
private function chargerNomService() {
|
|
|
113 |
// si la méthode est POST, on ajouter un commentaire
|
|
|
114 |
$this->serviceNom = 'liste-communes';
|
|
|
115 |
}
|
|
|
116 |
|
|
|
117 |
private function obtenirNomClasseService($mot) {
|
|
|
118 |
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
|
|
|
119 |
return $classeNom;
|
|
|
120 |
}
|
|
|
121 |
}
|
|
|
122 |
?>
|