-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
49 lines (37 loc) · 1.31 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
<?php
declare(strict_types=1);
namespace App;
use App\Config\Config;
use App\Config\Database;
use App\Controllers\NoteController;
use App\Controllers\UserController;
use App\Services\NoteServices;
use App\Services\UserServices;
use App\Utils\ErrorHandler;
use App\Utils\Helpers;
use App\Utils\ResponseCodes;
// Auto Loading Classes
require __DIR__ . "/src/Config/autoloader.php";
// Setting error and exception handlers
set_error_handler([ErrorHandler::class, 'handelError']);
set_exception_handler([ErrorHandler::class, 'handelException']);
header("Content-type: Application/json; charset=UTF-8");
$end_point = Helpers::get_end_point($_SERVER['REQUEST_URI']);
$id = Helpers::getId($_SERVER['REQUEST_URI']);
$database = new Database(Config::DB_CONFIG);
switch ($end_point) {
case 'notes':
$userServices = new UserServices($database);
$noteServices = new NoteServices($database);
$controller = new NoteController($noteServices, $userServices);
break;
case 'users':
$userServices = new UserServices($database);
$controller = new UserController($userServices);
break;
default:
http_response_code(ResponseCodes::NOT_FOUND);
echo json_encode(["error" => "Not Found"]);
exit;
}
$controller->processRequest($_SERVER['REQUEST_METHOD'], $id);