Subversion Repositories Applications.wikini

Rev

Rev 45 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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