-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.php
More file actions
41 lines (29 loc) · 952 Bytes
/
server.php
File metadata and controls
41 lines (29 loc) · 952 Bytes
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
<?php
$uri = urldecode(
parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH)
);
if ($uri !== '/' && file_exists(__DIR__ .'/public'. $uri)) {
return false;
}
require_once 'errors.php';
require_once 'defines.php';
require_once 'vendor/autoload.php';
$uri = trim($uri, '/');
$request = $uri===''? 'home': $uri;
$request .= preg_match('/\//', $request)? '': '/index';
$request = explode('/', $request);
$controller = $request[0];
$controller = str_replace(' ', '', ucwords( str_replace('-', ' ', $controller)));
array_shift($request);
$method = $request[0] ?? 'index';
$method = str_replace(' ', '', ucwords(str_replace('-', ' ', $method) ));
$method = lcfirst($method);
array_shift($request);
//
if(!file_exists("src/Controllers/{$controller}.php")) {
$controller = "Error";
$method = 'notFound';
}
$controller = "TeedShow\\Controllers\\{$controller}";
$controller = new $controller;
$controller->execute($method, $request);