-
Notifications
You must be signed in to change notification settings - Fork 48
/
index.php
68 lines (59 loc) · 1.51 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require_once 'vendor/autoload.php';
use Relay\Relay;
$request = Zend\Diactoros\ServerRequestFactory::fromGlobals(
$_SERVER,
$_GET,
$_POST,
$_COOKIE,
$_FILES
);
$loader = new Twig_Loader_Filesystem('.');
$twig = new \Twig_Environment($loader, array(
'debug' => true,
'cache' => false,
));
$router = new Aura\Router\RouterContainer();
$map = $router->getMap();
$map->get('todo.list', '/', function ($request) use ($twig) {
$tasks = [
[
'id' => 1,
'description' => 'Aprender inglés',
'done' => false
],
[
'id' => 1,
'description' => 'Hacer la tarea',
'done' => true
],
[
'id' => 1,
'description' => 'Pasear al perro',
'done' => false
],
[
'id' => 1,
'description' => 'Ver el curso de introducción a PHP',
'done' => false
]
];
$response = new Zend\Diactoros\Response\HtmlResponse($twig->render('template.twig', [
'tasks' => $tasks
]));
return $response;
});
$relay = new Relay([
new Middlewares\AuraRouter($router),
new Middlewares\RequestHandler()
]);
$response = $relay->handle($request);
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}
echo $response->getBody();