-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
55 lines (41 loc) · 1.22 KB
/
index.php
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
use App\Database\PDODatabaseConnection;
use App\Database\PDOQueryBuilder;
use App\Helpers\Config;
require_once './vendor/autoload.php';
$config = Config::get('database', 'pdo_testing');
$pdoConnection = new PDODatabaseConnection($config);
$queryBuilder = new PDOQueryBuilder($pdoConnection->connect());
function json_response($data = null, $statusCode = 200)
{
header_remove();
header('Content-Type: application/json');
http_response_code($statusCode);
echo json_encode($data);
exit();
}
function request()
{
return json_decode(file_get_contents('php://input'), true);
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$queryBuilder->table('bugs')->create(request());
json_response(null, 200);
}
if ($_SERVER['REQUEST_METHOD'] === 'PUT') {
$queryBuilder->table('bugs')
->where('id', request()['id'])
->update(request());
json_response(null, 200);
}
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
$bug = $queryBuilder->table('bugs')
->find(request()['id']);
json_response($bug, 200);
}
if ($_SERVER['REQUEST_METHOD'] === 'DELETE') {
$bug = $queryBuilder->table('bugs')
->where('id', request()['id'])
->delete();
json_response(null, 204);
}