-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.php
More file actions
50 lines (32 loc) · 1011 Bytes
/
index.php
File metadata and controls
50 lines (32 loc) · 1011 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
42
43
44
45
46
47
<?php
use Controller\ProjectController;
use Http\Request;
use Http\Response;
use Http\Router;
use Repository\Database\ProjectRepository as DatabaseProjectRepository;
use Repository\ProjectRepository;
include_once 'config.php';
include_once 'routes.php';
// Autoloading
spl_autoload_register(function($className) {
$path = __DIR__ . DIRECTORY_SEPARATOR .
str_replace("\\", DIRECTORY_SEPARATOR, $className) . ".php";
require_once $path;
});
// Create request
$request = Request::createFromGlobals();
// Create connection and repo, controllers
$pdo = new PDO($dsn, $username, $password);
$projectRepository = new DatabaseProjectRepository(
$pdo
);
$controllers = [
'Controller\ProjectController' => new ProjectController($projectRepository)
];
// Routing
$router = new Router($routes);
$route = $router->match($request);
$controller = $controllers[$route['controller']];
$action = $route['action'];
$response = $controller->$action();
$response->send();