Subversion Repositories Applications.wikini

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
29 aurelien 1
<?php
2
abstract class Service extends RestService {
3
 
4
	//+----------------------------------------------------------------------------------------------------------------+
5
	// GESTION de l'ENVOIE au NAVIGATEUR
6
 
7
	protected function formaterEnJsonp($donnees = null, $encodage = 'utf-8') {
8
		$contenu = $_GET['callback'].'('.json_encode($donnees).');';
9
		return $this->preparerEnvoie($contenu, 'text/html', $encodage);
10
	}
11
 
12
	protected function formaterEnJson($donnees = null, $encodage = 'utf-8') {
13
		$contenu = json_encode($donnees);
14
		return $this->preparerEnvoie($contenu, 'application/json', $encodage);
15
	}
16
 
17
	private function preparerEnvoie($sortie = 'OK', $mime = 'text/html', $encodage = 'utf-8') {
18
		$this->envoyerEnteteContenu($encodage, $mime);
19
		return $sortie;
20
	}
21
 
22
	private function envoyerEnteteContenu($encodage, $mime) {
23
		if (!is_null($mime) && !is_null($encodage)) {
24
			header("Content-Type: $mime; charset=$encodage");
25
		} else if (!is_null($mime) && is_null($encodage)) {
26
			header("Content-Type: $mime");
27
		}
28
	}
29
 
30
	protected function envoyerAuth($message_accueil, $message_echec) {
31
		header('HTTP/1.0 401 Unauthorized');
32
		header('WWW-Authenticate: Basic realm="'.mb_convert_encoding($message_accueil, 'ISO-8859-1', 'UTF-8').'"');
33
		header('Content-type: text/plain; charset=UTF-8');
34
		print $message_echec;
35
		exit(0);
36
	}
37
}
38
?>