-
-
Notifications
You must be signed in to change notification settings - Fork 6
/
go.php
58 lines (56 loc) · 1.62 KB
/
go.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
56
57
58
<?php
/**
* Welcome to the PHP.Gt WebEngine!
*
* This file is the entry point to the WebEngine. The whole request-response
* lifecycle is documented at:
* https://github.com/PhpGt/WebEngine/wiki/From-request-to-response
*/
chdir(dirname($_SERVER["DOCUMENT_ROOT"]));
ini_set("display_errors", "on");
ini_set("html_errors", "false");
/**
* 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(strstr($uri, ".")
|| is_file($_SERVER["DOCUMENT_ROOT"] . $uri)) {
return false;
}
/**
* Require the Composer autoloader, so the rest of the script can locate
* classes by their namespace, rather than having to know where on disk the
* files exist.
* @link https://getcomposer.org/doc/00-intro.md
*/
foreach([dirname($_SERVER["DOCUMENT_ROOT"]), __DIR__] as $dir) {
$autoloadPath = "$dir/vendor/autoload.php";
if(file_exists($autoloadPath)) {
/** @noinspection PhpIncludeInspection */
require $autoloadPath;
break;
}
}
/**
* 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
*/
if(file_exists("init.php")) {
require("init.php");
}
$lifecycle = new Gt\WebEngine\Middleware\Lifecycle();
try {
$lifecycle->start();
}
catch(Exception $e) {
if(function_exists("exception_handler")) {
call_user_func("exception_handler", $e);
}
else {
throw $e;
}
}