Subversion Repositories eFlore/Applications.del

Rev

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

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