-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
50 lines (39 loc) · 1.13 KB
/
index.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
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
class Router
{
private $routes = [];
public function addRoute($method, $path, $callback)
{
$this->routes[$method][$path] = $callback;
}
public function run($method, $uri)
{
if (!isset($this->routes[$method])) {
http_response_code(405);
echo "Método não permitido";
return;
}
foreach ($this->routes[$method] as $path => $callback) {
if ($uri === $path) {
$callback();
return;
}
}
http_response_code(404);
echo "Página não encontrada";
}
}
$router = new Router();
$router->addRoute('GET', '/agenda/', function () {
include('./controllers/homeController.php');
});
$router->addRoute('GET', '/agenda/#', function () {
include('./controllers/#Controller.php');
});
$router->addRoute('POST', '/agenda/agendamentocreate', function () {
include('./models/formularioAgendamentoCreate.php');
});
$router->run($_SERVER['REQUEST_METHOD'], $_SERVER['REQUEST_URI']);