45 |
mathias |
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 $contenu;
|
|
|
10 |
}
|
|
|
11 |
|
|
|
12 |
private function envoyerEnteteContenu($encodage, $mime) {
|
|
|
13 |
if (!is_null($mime) && !is_null($encodage)) {
|
|
|
14 |
header("Content-Type: $mime; charset=$encodage");
|
|
|
15 |
} else if (!is_null($mime) && is_null($encodage)) {
|
|
|
16 |
header("Content-Type: $mime");
|
|
|
17 |
}
|
|
|
18 |
}
|
|
|
19 |
|
|
|
20 |
public function envoyerContenuJson($donnees = null, $encodage = 'utf-8') {
|
|
|
21 |
$contenu = json_encode($donnees);
|
|
|
22 |
$this->envoyerEnteteContenu($encodage, 'application/json');
|
|
|
23 |
echo $contenu;
|
|
|
24 |
exit;
|
|
|
25 |
}
|
|
|
26 |
|
|
|
27 |
protected function envoyerAuth($message_accueil, $message_echec) {
|
|
|
28 |
header('HTTP/1.0 401 Unauthorized');
|
|
|
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');
|
|
|
31 |
print $message_echec;
|
|
|
32 |
exit(0);
|
|
|
33 |
}
|
|
|
34 |
|
|
|
35 |
protected function envoyerErreur($e) {
|
|
|
36 |
RestServeur::envoyerEnteteStatutHttp($e->getCode());
|
|
|
37 |
echo $e->getMessage();
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
protected function envoyerCreationEffectuee() {
|
|
|
41 |
header('HTTP/1.1 201 Created');
|
|
|
42 |
echo "OK";
|
|
|
43 |
}
|
|
|
44 |
}
|
30 |
aurelien |
45 |
?>
|