forked from daveh/php-rest-api
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
42 lines (18 loc) · 664 Bytes
/
Copy pathindex.php
File metadata and controls
42 lines (18 loc) · 664 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
<?php
declare(strict_types=1);
spl_autoload_register(function ($class) {
require __DIR__ . "/src/$class.php";
});
set_error_handler("ErrorHandler::handleError");
set_exception_handler("ErrorHandler::handleException");
header("Content-type: application/json; charset=UTF-8");
$parts = explode("/", $_SERVER["REQUEST_URI"]);
if ($parts[1] != "products") {
http_response_code(404);
exit;
}
$id = $parts[2] ?? null;
$database = new Database("localhost", "product_db", "root", "");
$gateway = new ProductGateway($database);
$controller = new ProductController($gateway);
$controller->processRequest($_SERVER["REQUEST_METHOD"], $id);