-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.php
65 lines (50 loc) · 1.35 KB
/
server.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
59
60
61
62
63
64
65
<?php
include(__DIR__.'/cli/includes/constants.php');
/**
* Show the 404 "Not Found" page.
*/
function show_valet_404()
{
http_response_code(404);
require __DIR__.'/cli/templates/404.html';
exit;
}
/**
* Parse the URI and site / host for the incoming request.
*/
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
$valetSitePath = CADDY_HOME_PATH . '/site';
$siteName = basename(getcwd());
/**
* Find the appropriate Valet driver for the request.
*/
$valetDriver = null;
require __DIR__.'/cli/drivers/require.php';
$valetDriver = ValetDriver::assign($valetSitePath, $siteName, $uri);
if (! $valetDriver) {
show_valet_404();
}
/**
* Allow driver to mutate incoming URL.
*/
$uri = $valetDriver->mutateUri($uri);
/**
* Determine if the incoming request is for a static file.
*/
$isPhpFile = pathinfo($uri, PATHINFO_EXTENSION) === 'php';
if ($uri !== '/' && ! $isPhpFile && $staticFilePath = $valetDriver->isStaticFile($valetSitePath, $siteName, $uri)) {
return $valetDriver->serveStaticFile($staticFilePath, $valetSitePath, $siteName, $uri);
}
/**
* Attempt to dispatch to a front controller.
*/
$frontControllerPath = $valetDriver->frontControllerPath(
$valetSitePath, $siteName, $uri
);
if (! $frontControllerPath) {
show_valet_404();
}
chdir(dirname($frontControllerPath));
require $frontControllerPath;