Subversion Repositories eFlore/Applications.del

Rev

Rev 1057 | Rev 1795 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1057 Rev 1661
Line 12... Line 12...
12
* @version 0.1
12
* @version 0.1
13
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
13
* @copyright 1999-2011 Tela Botanica (accueil@tela-botanica.org)
14
*/
14
*/
15
class Syndication extends RestService {
15
class Syndication extends RestService {
Line 16... Line -...
16
 
-
 
17
	
16
 
18
	private $parametres = array();
17
	private $parametres = array();
19
	private $ressources = array();
18
	private $ressources = array();
20
	private $methode = null;
19
	private $methode = null;
21
	private $projetNom = array();
20
	private $projetNom = array();
22
	private $serviceNom = array();
21
	private $serviceNom = array();
23
	private $cheminCourant = null;
22
	private $cheminCourant = null;
24
	private $squelette_dossier = null;
23
	private $squelette_dossier = null;
Line 25... Line 24...
25
	private $formats_autorises = null;
24
	private $formats_autorises = null;
26
 
25
 
27
	private $conteneur;
26
	private $conteneur;
28
	
27
 
Line 29... Line 28...
29
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
28
	/** Indique si oui (true) ou non (false), on veut utiliser les paramètres bruts. */
30
	protected $utilisationParametresBruts = true;
29
	protected $utilisationParametresBruts = true;
31
 
30
 
32
	public function __construct() {
31
	public function __construct() {
Line 33... Line 32...
33
		$this->cheminCourant = dirname(__FILE__).DS;
32
		$this->cheminCourant = dirname(__FILE__).DS;
34
		$this->squelette_dossier = dirname(__FILE__).DIRECTORY_SEPARATOR.'syndication'.DIRECTORY_SEPARATOR.'squelettes'.DIRECTORY_SEPARATOR;
33
		$this->squelette_dossier = dirname(__FILE__).DS.'syndication'.DS.'squelettes'.DS;
35
	}
34
	}
Line 50... Line 49...
50
		}
49
		}
51
		$reponseHttp->emettreLesEntetes();
50
		$reponseHttp->emettreLesEntetes();
52
		$corps = $reponseHttp->getCorps();
51
		$corps = $reponseHttp->getCorps();
53
		return $corps;
52
		return $corps;
54
	}
53
	}
55
	
54
 
56
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
55
	private function initialiserRessourcesEtParametres($ressources, $parametres) {
57
		$this->ressources = $ressources;
56
		$this->ressources = $ressources;
58
		$this->parametres = $parametres;
57
		$this->parametres = $parametres;
59
	}
58
	}
60
	
59
 
61
	private function verifierRessourcesEtParametres() {
60
	private function verifierRessourcesEtParametres() {
62
		
-
 
63
		$servicesDispos = Config::get('servicesDispo');
61
		$servicesDispos = Config::get('servicesDispo');
64
		if (!isset($this->ressources[0]) || !in_array($this->ressources[0], explode(',',$servicesDispos))) {
62
		if (!isset($this->ressources[0]) || !in_array($this->ressources[0], explode(',',$servicesDispos))) {
65
			$message = "Vous devez indiquer un nom de service valide, les services disponibles sont ".$servicesDispos;
63
			$message = "Vous devez indiquer un nom de service valide, les services disponibles sont ".$servicesDispos;
66
			$code = RestServeur::HTTP_CODE_ERREUR;
64
			$code = RestServeur::HTTP_CODE_ERREUR;
67
			throw new Exception($message, $code);
65
			throw new Exception($message, $code);
68
		}
66
		}
69
		
67
 
70
		$chaineFormatsAutorises = Config::get('formatsRss');
68
		$chaineFormatsAutorises = Config::get('formatsRss');
71
		$this->formats_autorises = explode(',', $chaineFormatsAutorises);
69
		$this->formats_autorises = explode(',', $chaineFormatsAutorises);
72
		if (!isset($this->ressources[1]) || !in_array($this->ressources[1], $this->formats_autorises)) {
70
		if (!isset($this->ressources[1]) || !in_array($this->ressources[1], $this->formats_autorises)) {
73
			$message = "Vous devez indiquer un format de flux valide, les formats acceptés sont ".$chaineFormatsAutorises;
71
			$message = "Vous devez indiquer un format de flux valide, les formats acceptés sont ".$chaineFormatsAutorises;
74
			$code = RestServeur::HTTP_CODE_ERREUR;
72
			$code = RestServeur::HTTP_CODE_ERREUR;
Line 79... Line 77...
79
	}
77
	}
Line 80... Line 78...
80
 
78
 
81
	private function traiterRessources() {
79
	private function traiterRessources() {
82
		$retour = '';
80
		$retour = '';
83
		$retour = $this->initialiserService();
-
 
84
 
81
		$retour = $this->initialiserService();
85
		return $retour;
82
		return $retour;
86
	}
83
	}
87
	
84
 
88
	private function creerResultatService($donnees) {
85
	private function creerResultatService($donnees) {
89
		$resultat = new ResultatService();
86
		$resultat = new ResultatService();
90
		$resultat->mime = $this->getTypeMime();
87
		$resultat->mime = $this->getTypeMime();
91
		$resultat->corps = SquelettePhp::analyser($this->squelette_dossier.$this->format.'.tpl.xml', $donnees);
-
 
92
		
88
		$resultat->corps = SquelettePhp::analyser($this->squelette_dossier.$this->format.'.tpl.xml', $donnees);
93
		return $resultat;
89
		return $resultat;
Line 94... Line 90...
94
	}
90
	}
95
 
91
 
Line 110... Line 106...
110
	/*------------------------------------------------------------------------------------------------------------------
106
	/*------------------------------------------------------------------------------------------------------------------
111
								CONFIGURATION DU SERVICE
107
								CONFIGURATION DU SERVICE
112
	------------------------------------------------------------------------------------------------------------------*/
108
	------------------------------------------------------------------------------------------------------------------*/
113
	private function initialiserService() {
109
	private function initialiserService() {
114
		$this->chargerNomService();
110
		$this->chargerNomService();
115
				
111
 
116
		$classe = $this->obtenirNomClasseService($this->serviceNom);
112
		$classe = $this->obtenirNomClasseService($this->serviceNom);
117
		$chemins = array();
113
		$chemins = array();
118
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
114
		$chemins[] = $this->cheminCourant.$this->projetNom.DS.$classe.'.php';
119
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
115
		$chemins[] = $this->cheminCourant.'commun'.DS.$classe.'.php';
120
		$retour = '';
116
		$retour = '';
121
		$service = null;
117
		$service = null;
122
		foreach ($chemins as $chemin) {
118
		foreach ($chemins as $chemin) {
123
			if (file_exists($chemin)) {
119
			if (file_exists($chemin)) {
124
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');	
120
				$this->conteneur->chargerConfiguration('config_'.$this->projetNom.'.ini');
125
				require_once $chemin;
121
				require_once $chemin;
126
				$service = new $classe($this->conteneur);
122
				$service = new $classe($this->conteneur);
127
				if ($this->methode == 'consulter') {
123
				if ($this->methode == 'consulter') {
128
					$retour = $service->consulter($this->ressources, $this->parametres);
124
					$retour = $service->consulter($this->ressources, $this->parametres);
129
				}
125
				}
130
			}
126
			}
131
		}
127
		}
132
		
128
 
133
		if (is_null($service)) {
129
		if (is_null($service)) {
134
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
130
			$message = "Le service demandé '{$this->serviceNom}' n'existe pas dans le projet {$this->projetNom} !";
135
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
131
			$code = RestServeur::HTTP_CODE_RESSOURCE_INTROUVABLE;
136
			throw new Exception($message, $code);
132
			throw new Exception($message, $code);
137
		}
133
		}
138
		return $retour;
134
		return $retour;
139
	}
135
	}
140
	
136
 
141
	private function chargerNomService() {
137
	private function chargerNomService() {
142
		if (!isset($this->ressources[0])) {
138
		if (!isset($this->ressources[0])) {
143
			$message = "Vous devez indiquer un nom de service";
139
			$message = "Vous devez indiquer un nom de service";
144
			$code = RestServeur::HTTP_CODE_ERREUR;
140
			$code = RestServeur::HTTP_CODE_ERREUR;
145
			throw new Exception($message, $code);
141
			throw new Exception($message, $code);
Line 150... Line 146...
150
 
146
 
151
	private function obtenirNomClasseService($mot) {
147
	private function obtenirNomClasseService($mot) {
152
		$classeNom = 'Syndication'.ucwords($mot);
148
		$classeNom = 'Syndication'.ucwords($mot);
153
		return $classeNom;
149
		return $classeNom;
154
	}
150
	}
155
	
151
 
156
	private function getTypeMime() {
152
	private function getTypeMime() {
157
		$mime = '';
153
		$mime = '';
158
		switch ($this->format) {
154
		switch ($this->format) {
159
			case 'atom' :
155
			case 'atom' :