Subversion Repositories eFlore/Applications.del

Rev

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

Rev Author Line No. Line
1593 samuel 1
<?php
1795 jpm 2
// declare(encoding='UTF-8');
1593 samuel 3
/**
1795 jpm 4
* Classe principale de chargement des sous-services de Plantnet.
1593 samuel 5
*
1795 jpm 6
 * @category   DEL
7
 * @package    Services
8
 * @subpackage Plantnet
9
 * @version    0.1
10
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
11
 * @author     Samuel DUFOUR-KOWALSKI <samuel.dufour@cirad.fr>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
15
 * @license    CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
16
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
1593 samuel 17
*/
18
class PlantNet extends RestService {
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;
1795 jpm 28
 
1593 samuel 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->ressources = $ressources;
42
                        $this->parametres = $parametres;
43
 
44
 
45
			$this->conteneur = new Conteneur($this->parametres);
1795 jpm 46
 
1593 samuel 47
                        $this->projetNom = 'plantnet';
48
                        $this->serviceNom = 'changements';
49
 
50
                        // init projet
51
                        $projet = $this->projetNom;
52
                        $chemin = Config::get('chemin_configurations')."config_$projet.ini";
53
                        Config::charger($chemin);
1795 jpm 54
 
1593 samuel 55
                        $resultat = $this->initialiserService();
56
 
57
			$reponseHttp->setResultatService($resultat);
58
 
59
		} catch (Exception $e) {
60
			$reponseHttp->ajouterErreur($e);
61
		}
62
		$reponseHttp->emettreLesEntetes();
63
		$corps = $reponseHttp->getCorps();
64
		return $corps;
65
	}
66
 
67
 
68
 
69
 
1795 jpm 70
 
1593 samuel 71
	/*------------------------------------------------------------------------------------------------------------------
72
								CONFIGURATION DU SERVICE
73
	------------------------------------------------------------------------------------------------------------------*/
74
 
1795 jpm 75
 
76
 
1593 samuel 77
	private function initialiserService() {
1795 jpm 78
 
1593 samuel 79
		$classe = $this->obtenirNomClasseService($this->serviceNom);
80
		$chemins = array();
81
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
82
		$retour = '';
83
		$service = null;
84
		foreach ($chemins as $chemin) {
85
                  if (file_exists($chemin)) {
1795 jpm 86
 
87
 
1593 samuel 88
                    $this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
89
                    require_once $chemin;
1795 jpm 90
 
1593 samuel 91
                    $service = new $classe($this->conteneur);
92
                    $retour = $service->consulter($this->ressources, $this->parametres);
1795 jpm 93
 
1593 samuel 94
                  }
95
		}
1795 jpm 96
 
1593 samuel 97
		if (is_null($service)) {
98
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
99
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
100
			throw new Exception($message, $code);
101
		}
102
		return $retour;
103
	}
104
 
105
	private function obtenirNomClasseService($mot) {
106
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
107
		return $classeNom;
108
	}
109
}
110
?>