-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
32 lines (23 loc) · 816 Bytes
/
index.php
File metadata and controls
32 lines (23 loc) · 816 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
<?php
require 'vendor/autoload.php';
use Bramus\Router\Router;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Output\BufferedOutput;
$router = new Router();
$router->post('/create', function() {
$output = new BufferedOutput();
$table = new Table($output);
$input = json_decode(file_get_contents('php://input'), true);
header('Content-Type: text/plain');
// Ensure all keys are provided
if (!isset($input['table']['headers'], $input['table']['rows'])) {
http_response_code(400);
echo json_encode(['error' => 'Incorrect json format!']);
return;
}
$table->setHeaders($input['table']['headers']);
$table->addRows($input['table']['rows']);
$table->render();
echo $output->fetch();
});
$router->run();