forked from damsfx/valet-windows
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathserver.php
More file actions
98 lines (76 loc) · 2.44 KB
/
server.php
File metadata and controls
98 lines (76 loc) · 2.44 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
97
98
<?php
require_once __DIR__ . '/cli/includes/require-drivers.php';
require_once __DIR__ . '/cli/Valet/Server.php';
use Valet\Server;
use Valet\Drivers\ValetDriver;
/**
* Define the user's "~/.config/valet" path.
*/
define('VALET_HOME_PATH', str_replace('\\', '/', $_SERVER['HOME'] . '/.config/valet'));
define('VALET_STATIC_PREFIX', '41c270e4-5535-4daa-b23e-c269744c2f45');
/**
* Load the Valet configuration.
*/
$valetConfig = json_decode(
file_get_contents(VALET_HOME_PATH . '/config.json'),
true
);
/** Load the Valet server instance. */
$server = new Server($valetConfig);
/**
* Parse the URI and site / host for the incoming request.
*/
$uri = $server->uriFromRequestUri($_SERVER['REQUEST_URI']);
$siteName = $server->siteNameFromHttpHost($_SERVER['HTTP_HOST']);
$valetSitePath = $server->sitePath($siteName);
/**
* Show 404 if the site path is not found.
*/
if (is_null($valetSitePath) && is_null($valetSitePath = $server->defaultSitePath())) {
$server->show404();
}
// Resolve the site path to an absolute path.
$valetSitePath = realpath($valetSitePath);
/**
* Find the appropriate Valet driver for the request.
*/
$valetDriver = null;
$valetDriver = ValetDriver::assign($valetSitePath, $siteName, $uri);
// Show 404 if no driver is found.
if (!$valetDriver) {
$server->show404();
}
// Set the ngrok server forwarded host
$server->setNgrokServerForwardedHost();
/**
* Attempt to load server environment variables.
*/
$valetDriver->loadServerEnvironmentVariables($valetSitePath, $siteName);
/**
* Allow driver to mutate incoming URL.
*/
$uri = $valetDriver->mutateUri($uri);
/**
* Determine if the incoming request is for a static file.
*/
$staticFilePath = $server->isRequestStaticFile($uri, $valetSitePath, $siteName, $valetDriver);
if ($staticFilePath) {
return $valetDriver->serveStaticFile($staticFilePath, $valetSitePath, $siteName, $uri);
}
/**
* Allow for drivers to take pre-loading actions (e.g. setting server variables).
*/
$valetDriver->beforeLoading($valetSitePath, $siteName, $uri);
/**
* Attempt to dispatch to a front controller.
*/
$frontControllerPath = $valetDriver->frontControllerPath($valetSitePath, $siteName, $uri);
if (!$frontControllerPath) {
$server->showDirectoryListingOr404($valetSitePath, $uri);
}
/**
* Change the working directory and require the front controller.
*/
// Change the working directory to the front controller's directory.
$server->changeDir($frontControllerPath);
require $frontControllerPath;