Subversion Repositories eFlore/Applications.del

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2212 arthur 1
<?php
2
// declare(encoding='UTF-8');
3
/**
4
* Classe principale de chargement des sous-services de Plantnet.
5
*
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>
17
*/
18
class PlantNet extends RestService {
19
 
20
	private $parametres = array();
21
	private $ressources = array();
22
	private $methode = null;
23
	private $projetNom = 'plantnet';
24
	private $serviceNom = 'changements';
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
		$reponseHttp = new ReponseHttp();
39
		try {
40
			$this->ressources = $ressources;
41
			$this->parametres = $parametres;
42
 
43
			$this->conteneur = new Conteneur($this->parametres);
44
 
45
			$resultat = $this->initialiserService();
46
			$reponseHttp->setResultatService($resultat);
47
		} catch (Exception $e) {
48
			$reponseHttp->ajouterErreur($e);
49
		}
50
		$reponseHttp->emettreLesEntetes();
51
		return $reponseHttp->getCorps();
52
	}
53
 
54
	/*------------------------------------------------------------------------------------------------------------------
55
								CONFIGURATION DU SERVICE
56
	------------------------------------------------------------------------------------------------------------------*/
57
	private function initialiserService() {
58
		$classe = $this->obtenirNomClasseService($this->serviceNom);
59
		$chemins = array();
60
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
61
		$retour = '';
62
		$service = null;
63
		foreach ($chemins as $chemin) {
64
			if (file_exists($chemin)) {
65
				require_once $chemin;
66
				$service = new $classe($this->conteneur);
67
				$retour = $service->consulter($this->ressources, $this->parametres);
68
			}
69
		}
70
 
71
		if (is_null($service)) {
72
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
73
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
74
			throw new Exception($message, $code);
75
		}
76
		return $retour;
77
	}
78
 
79
	private function obtenirNomClasseService($mot) {
80
		$classeNom = str_replace(' ', '', ucwords(strtolower(str_replace('-', ' ', $mot))));
81
		return $classeNom;
82
	}
83
}