Subversion Repositories eFlore/Applications.del

Compare Revisions

Ignore whitespace Rev 1815 → Rev 1816

/trunk/services/modules/0.1/Nomstaxons.php
16,12 → 16,11
*/
class Nomstaxons extends RestService {
 
 
private $parametres = array();
private $ressources = array();
private $methode = null;
private $projetNom = array();
private $serviceNom = array();
private $serviceNom = 'nomstaxons';
private $sousServiceNom = null;
private $cheminCourant = null;
 
private $conteneur;
35,10 → 34,18
 
public function consulter($ressources, $parametres) {
$this->methode = 'consulter';
$resultat = '';
$this->initialiserRessourcesEtParametres($ressources, $parametres);
return $this->executerService();
}
 
private function initialiserRessourcesEtParametres($ressources, $parametres = array()) {
$this->ressources = $ressources;
$this->parametres = $parametres;
}
 
private function executerService() {
$reponseHttp = new ReponseHttp();
try {
$this->initialiserRessourcesEtParametres($ressources, $parametres);
$this->conteneur = new Conteneur($this->parametres);
$resultat = $this->traiterRessources();
$reponseHttp->setResultatService($resultat);
50,59 → 57,71
return $corps;
}
 
private function initialiserRessourcesEtParametres($ressources, $parametres) {
$this->ressources = $ressources;
$this->parametres = $parametres;
}
 
private function traiterRessources() {
$retour = '';
$this->initialiserProjet();
$this->analyserRessources();
$retour = $this->initialiserService();
return $retour;
}
 
/*------------------------------------------------------------------------------------------------------------------
CONFIGURATION DU PROJET
------------------------------------------------------------------------------------------------------------------*/
private function initialiserProjet() {
$this->projetNom = 'nomstaxons';
$this->chargerConfigProjet();
private function analyserRessources() {
if ($this->methode == 'consulter') {
if (count($this->ressources) == 0
&& $this->verifierPresenceParametre('masque.nom')
&& $this->verifierPresenceParametre('masque.referentiel')) {
$this->sousServiceNom = 'liste-taxons';
}
}
if ($this->sousServiceNom == null) {
$this->lancerMessageErreurRessource();
}
}
 
private function chargerConfigProjet() {
$projet = $this->projetNom;
$chemin = Config::get('chemin_configurations')."config_$projet.ini";
Config::charger($chemin);
private function verifierPresenceParametre($cle) {
if (isset($this->parametres[$cle]) && trim($this->parametres[$cle]) == '') {
$message = "Le service demandé '{$this->serviceNom}' ".
"nécessite l'utilisation de paramètres (non vide) : masque.nom & masque.referentiel\n";
throw new Exception($message, RestServeur::HTTP_CODE_ECHEC_CONDITION);
}
return true;
}
 
/*------------------------------------------------------------------------------------------------------------------
CONFIGURATION DU SERVICE
------------------------------------------------------------------------------------------------------------------*/
private function lancerMessageErreurRessource() {
$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
$message = "La ressource demandée '$ressource' ".
"n'est pas disponible pour le service ".$this->serviceNom." !\n".
"Les URLs disponibles sont : \n".
" - en GET : nomstaxons (paramètres : masque.nom & masque.referentiel) \n";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
 
private function initialiserService() {
$this->chargerNomService();
 
$classe = $this->obtenirNomClasseService($this->serviceNom);
$classe = $this->obtenirNomClasseService($this->sousServiceNom);
$chemins = array();
$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
$chemins[] = $this->cheminCourant.$this->serviceNom.DS.$classe.'.php';
$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
$retour = '';
$service = null;
 
foreach ($chemins as $chemin) {
if (file_exists($chemin)) {
$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
require_once $chemin;
$service = new $classe($this->conteneur);
if ($this->methode == 'consulter') {
$retour = $service->consulter($this->ressources, $this->parametres);
$retour = $service->consulter();
} else {
//TODO : throw exception
$message = "Le sous-service '{$this->sousServiceNom}' du service '{$this->serviceNom}' ".
"ne possède pas de méthode '{$this->methode}' !";
$code = RestServeur::HTTP_NON_IMPLEMENTE;
throw new Exception($message, $code);
}
}
}
 
if (is_null($service)) {
$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
$ressource = $this->sousServiceNom.'/'.implode('/', $this->ressources);
$message = "Le classe '$classe' correspondant à la ressource '$ressource' ".
"est introuvable par le service '{$this->serviceNom}' !";
$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
throw new Exception($message, $code);
}
109,14 → 128,8
return $retour;
}
 
private function chargerNomService() {
// si la méthode est POST, on ajouter un commentaire
$this->serviceNom = 'liste-taxons';
}
 
private function obtenirNomClasseService($mot) {
$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
return $classeNom;
}
}
?>
}