Content-Negotiation with the help of Renderer and Formatters

This commit is contained in:
Gilles Crettenand
2015-06-02 02:02:40 +02:00
parent c0159f4b79
commit 7e0a38e989
7 changed files with 241 additions and 23 deletions

29
Lib/Renderer.php Normal file
View File

@@ -0,0 +1,29 @@
<?php
namespace BSR\Lib;
use BSR\Lib\Formatter\Formatter;
class Renderer {
private static $statusMessages = array(
200 => 'Ok',
400 => 'Bad request',
404 => 'Not Found',
403 => 'Not Authorized',
500 => 'Server Error',
);
public function __construct() {
ob_start();
}
public function render($status, $data) {
header(sprintf('HTTP/1.0 %s %s', $status, self::$statusMessages[$status]));
ob_clean();
flush();
$formatter = Formatter::getFormatter();
$formatter->render($data);
}
}