-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
55 lines (47 loc) · 1.36 KB
/
index.php
File metadata and controls
55 lines (47 loc) · 1.36 KB
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
/*
* Copyright (c) 2021.
* Marc Concepcion
* marcanthonyconcepcion@gmail.com
*/
$configuration = yaml_parse_file(__DIR__.'\resources\MarcPHPRESTAPIDemo.yaml');
define('Main_ERROR_LOG', $configuration['log']['filename']);
use JetBrains\PhpStorm\Pure;
require_once 'ModelViewController.php';
require_once 'SubscriberModeViewController.php';
require_once 'PDODatabaseRecords.php';
class Main
{
private Controller $controller;
#[Pure]
function __construct(Controller $controller)
{
$this->controller = $controller;
}
function execute()
{
try
{
$view_request = View::receiveRequest();
$view_response = $this->controller->processHTTP($view_request->request, $view_request->id);
View::sendResponse($view_response);
}
catch (HTTPError $error)
{
View::sendErrorResponse($error->getResponse(), $error->getMessage());
}
}
}
if (!debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS))
{
try
{
$main = new Main(new SubscriberController(new SubscriberModel(PDODatabaseRecords::get())));
$main->execute();
}
catch (Exception|Error $error)
{
View::sendErrorResponse((object)HTTP_INTERNAL_SERVER_ERROR, "Error in server. Please bear with us.");
error_log($error->getMessage() . PHP_EOL, 3, Main_ERROR_LOG);
}
}