Subversion Repositories eFlore/Applications.del

Rev

Rev 1881 | 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;
1881 jpm 23
	private $projetNom = 'plantnet';
24
	private $serviceNom = 'changements';
1593 samuel 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
		$reponseHttp = new ReponseHttp();
39
		try {
1881 jpm 40
			$this->ressources = $ressources;
41
			$this->parametres = $parametres;
1593 samuel 42
 
43
			$this->conteneur = new Conteneur($this->parametres);
1795 jpm 44
 
1881 jpm 45
			$resultat = $this->initialiserService();
1593 samuel 46
			$reponseHttp->setResultatService($resultat);
47
		} catch (Exception $e) {
48
			$reponseHttp->ajouterErreur($e);
49
		}
50
		$reponseHttp->emettreLesEntetes();
1881 jpm 51
		return $reponseHttp->getCorps();
1593 samuel 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) {
1881 jpm 64
			if (file_exists($chemin)) {
65
				require_once $chemin;
66
				$service = new $classe($this->conteneur);
67
				$retour = $service->consulter($this->ressources, $this->parametres);
68
			}
1593 samuel 69
		}
1795 jpm 70
 
1593 samuel 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
	}
1881 jpm 83
}