Subversion Repositories eFlore/Applications.del

Rev

Rev 1593 | Rev 1881 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1593 Rev 1795
1
<?php
1
<?php
-
 
2
// declare(encoding='UTF-8');
2
/**
3
/**
3
* Description :
-
 
4
* Classe principale de chargement des services d'eFlore.
4
* Classe principale de chargement des sous-services de Plantnet.
5
*
5
*
6
* Encodage en entrée : utf8
6
 * @category   DEL
7
* Encodage en sortie : utf8
7
 * @package    Services
8
* @package eflore-projets
8
 * @subpackage Plantnet
-
 
9
 * @version    0.1
9
* @author Jennifer DHÉ <jennifer.dhe@tela-botanica.org>
10
 * @author     Mathias CHOUET <mathias@tela-botanica.org>
10
* @author Delphine CAUQUIL <delphine@tela-botanica.org>
11
 * @author     Samuel DUFOUR-KOWALSKI <samuel.dufour@cirad.fr>
11
* @author Jean-Pascal MILCENT <jpm@tela-botanica.org>
12
 * @author     Jean-Pascal MILCENT <jpm@tela-botanica.org>
-
 
13
 * @author     Aurelien PERONNET <aurelien@tela-botanica.org>
12
* @license GPL v3 <http://www.gnu.org/licenses/gpl.txt>
14
 * @license    GPL v3 <http://www.gnu.org/licenses/gpl.txt>
13
* @license CECILL v2 <http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt>
15
 * @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
 * @copyright  1999-2014 Tela Botanica <accueil@tela-botanica.org>
16
*/
17
*/
17
class PlantNet extends RestService {
18
class PlantNet extends RestService {
18
 
-
 
19
	
-
 
20
	/*
-
 
21
	 * url possibles : 
-
 
22
	 * */
-
 
23
	
19
 
24
	private $parametres = array();
20
	private $parametres = array();
25
	private $ressources = array();
21
	private $ressources = array();
26
	private $methode = null;
22
	private $methode = null;
27
	private $projetNom = array();
23
	private $projetNom = array();
28
	private $serviceNom = array();
24
	private $serviceNom = array();
29
	private $cheminCourant = null;
25
	private $cheminCourant = null;
30
 
26
 
31
	private $conteneur;
27
	private $conteneur;
32
	
28
 
33
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
29
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
34
	protected $utilisationParametresBruts = true;
30
	protected $utilisationParametresBruts = true;
35
 
31
 
36
	public function __construct() {
32
	public function __construct() {
37
		$this->cheminCourant = dirname(__FILE__).DS;
33
		$this->cheminCourant = dirname(__FILE__).DS;
38
	}
34
	}
39
 
35
 
40
	public function consulter($ressources, $parametres) {
36
	public function consulter($ressources, $parametres) {
41
		$this->methode = 'consulter';
37
		$this->methode = 'consulter';
42
		$resultat = '';
38
		$resultat = '';
43
		$reponseHttp = new ReponseHttp();
39
		$reponseHttp = new ReponseHttp();
44
		try {
40
		try {
45
                        $this->ressources = $ressources;
41
                        $this->ressources = $ressources;
46
                        $this->parametres = $parametres;
42
                        $this->parametres = $parametres;
47
 
43
 
48
 
44
 
49
			$this->conteneur = new Conteneur($this->parametres);
45
			$this->conteneur = new Conteneur($this->parametres);
50
                        
46
 
51
                        $this->projetNom = 'plantnet';
47
                        $this->projetNom = 'plantnet';
52
                        $this->serviceNom = 'changements';
48
                        $this->serviceNom = 'changements';
53
 
49
 
54
                        // init projet
50
                        // init projet
55
                        $projet = $this->projetNom;
51
                        $projet = $this->projetNom;
56
                        $chemin = Config::get('chemin_configurations')."config_$projet.ini";
52
                        $chemin = Config::get('chemin_configurations')."config_$projet.ini";
57
                        Config::charger($chemin);
53
                        Config::charger($chemin);
58
                        
54
 
59
                        $resultat = $this->initialiserService();
55
                        $resultat = $this->initialiserService();
60
 
56
 
61
			$reponseHttp->setResultatService($resultat);
57
			$reponseHttp->setResultatService($resultat);
62
 
58
 
63
		} catch (Exception $e) {
59
		} catch (Exception $e) {
64
			$reponseHttp->ajouterErreur($e);
60
			$reponseHttp->ajouterErreur($e);
65
		}
61
		}
66
		$reponseHttp->emettreLesEntetes();
62
		$reponseHttp->emettreLesEntetes();
67
		$corps = $reponseHttp->getCorps();
63
		$corps = $reponseHttp->getCorps();
68
		return $corps;
64
		return $corps;
69
	}
65
	}
70
	
66
 
71
 
67
 
72
 
68
 
73
 
69
 
74
 
70
 
75
	/*------------------------------------------------------------------------------------------------------------------
71
	/*------------------------------------------------------------------------------------------------------------------
76
								CONFIGURATION DU SERVICE
72
								CONFIGURATION DU SERVICE
77
	------------------------------------------------------------------------------------------------------------------*/
73
	------------------------------------------------------------------------------------------------------------------*/
78
	
74
 
79
	
75
 
80
 
76
 
81
	private function initialiserService() {
77
	private function initialiserService() {
82
		
78
 
83
		$classe = $this->obtenirNomClasseService($this->serviceNom);
79
		$classe = $this->obtenirNomClasseService($this->serviceNom);
84
		$chemins = array();
80
		$chemins = array();
85
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
81
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
86
		$retour = '';
82
		$retour = '';
87
		$service = null;
83
		$service = null;
88
		foreach ($chemins as $chemin) {
84
		foreach ($chemins as $chemin) {
89
                  if (file_exists($chemin)) {
85
                  if (file_exists($chemin)) {
90
                    
86
 
91
                    
87
 
92
                    $this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
88
                    $this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
93
                    require_once $chemin;
89
                    require_once $chemin;
94
                    
90
 
95
                    $service = new $classe($this->conteneur);
91
                    $service = new $classe($this->conteneur);
96
                    $retour = $service->consulter($this->ressources, $this->parametres);
92
                    $retour = $service->consulter($this->ressources, $this->parametres);
97
                    
93
 
98
                  }
94
                  }
99
		}
95
		}
100
		
96
 
101
		if (is_null($service)) {
97
		if (is_null($service)) {
102
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
98
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
103
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
99
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
104
			throw new Exception($message, $code);
100
			throw new Exception($message, $code);
105
		}
101
		}
106
		return $retour;
102
		return $retour;
107
	}
103
	}
108
 
104
 
109
	private function obtenirNomClasseService($mot) {
105
	private function obtenirNomClasseService($mot) {
110
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
106
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
111
		return $classeNom;
107
		return $classeNom;
112
	}
108
	}
113
}
109
}
114
?>
110
?>