-
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathgo.php
More file actions
96 lines (89 loc) · 2.67 KB
/
go.php
File metadata and controls
96 lines (89 loc) · 2.67 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* Welcome to the PHP.GT WebEngine!
*
* This file is the entry point to the WebEngine. Sometimes this is referred to
* as the "bootstrap" file. Read more about the whole request-response
* lifecycle in the documentation:
* https://github.com/PhpGt/WebEngine/wiki/From-request-to-response
*/
use Gt\Config\ConfigFactory;
use Gt\Logger\Log;
use Gt\Logger\LogConfig;
use Gt\Logger\LogLevel;
use GT\WebEngine\Application;
$projectRoot = dirname($_SERVER["DOCUMENT_ROOT"]);
chdir($projectRoot);
ini_set("display_errors", "on");
ini_set("html_errors", "false");
/**
* Step 1 - Composer:
* Require the Composer autoloader before doing anything else, so config and
* logging are available even for static-file requests.
* @link https://getcomposer.org/doc/00-intro.md
*/
$vendorDirectoryList = [
$projectRoot,
__DIR__,
];
foreach($vendorDirectoryList as $dir) {
$autoloadPath = "$dir/vendor/autoload.php";
if(file_exists($autoloadPath)) {
require $autoloadPath;
break;
}
}
$configFactory = new ConfigFactory();
$config = $configFactory->createForProject(
$projectRoot,
__DIR__ . "/config.default.ini"
);
$minimumLogLevel = strtoupper($config->getString("logger.level") ?: LogLevel::DEBUG);
if(!in_array($minimumLogLevel, LogLevel::ALL_LEVELS, true)) {
$minimumLogLevel = LogLevel::DEBUG;
}
LogConfig::setDefaultHandlerLevel($minimumLogLevel);
/**
* Step 2 - Static files:
* Before any code is executed, return false here if a static file is requested.
* When running the PHP inbuilt server, this will output the static file.
* Other webservers should not get to this point, but it's safe to prevent
* unnecessary execution.
*/
$uri = urldecode(parse_url($_SERVER["REQUEST_URI"], PHP_URL_PATH));
if(is_file($_SERVER["DOCUMENT_ROOT"] . $uri)) {
if($config->getBool("logger.log_static_requests")) {
Log::info("HTTP 200", [
"uri" => $uri,
]);
}
return false;
}
/**
* Step 3 - setup:
* An optional setup.php file can be included in the project root, which will
* simply be executed directly here. This is useful for configuring the PHP
* environment across the project, but shouldn't be necessary for most projects.
*
* The file is required inside a static function to prevent leaking variable
* scope between go.php and setup.php.
*/
if(file_exists("setup.php")) {
ob_start();
(static function():void {
require("setup.php");
})();
}
/**
* Step 4 - Go!
* That's all we need to start the request-response lifecycle.
* Buckle up and enjoy the ride!
* @link https://github.com/PhpGt/WebEngine/wiki/From-request-to-response
*/
$app = new Application($config);
$app->start();
if(file_exists("teardown.php")) {
(static function():void {
require("teardown.php");
})();
}