-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.php
80 lines (68 loc) · 2.34 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
69
70
71
72
73
74
75
76
77
78
79
80
<?php
require_once __DIR__ . '/../vendor/autoload.php';
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
use Silex\Provider\HttpFragmentServiceProvider;
use Silex\Provider\HttpCacheServiceProvider;
$app = new Silex\Application();
$app['debug'] = true;
$app->register(new Silex\Provider\TwigServiceProvider(), ['twig.path' => __DIR__.'/../views']);
$app->register(new HttpFragmentServiceProvider());
$app->register(new HttpCacheServiceProvider());
$app->register(new Silex\Provider\TranslationServiceProvider(), ['locale_fallbacks' => ['en']]);
$app['locale'] = 'en';
$app['translator.domains'] = [
'messages' => [
'en' => [
'welcome' => 'Welcome to the site',
'rendered' => 'Rendered at %date%',
'example' => 'An example page'
],
'nl' => [
'welcome' => 'Welkom op de site',
'rendered' => 'Samengesteld op %date%',
'example' => 'Een voorbeeldpagina'
]
]
];
$app->before(function (Request $request) use ($app){
$app['translator']->setLocale($request->getPreferredLanguage());
});
$app->after(function(Request $request, Response $response) use ($app){
$date = new DateTime();
$date->add(new DateInterval('PT'.$response->getTtl().'S'));
$response
->setExpires($date)
->setVary('Accept-Language')
->setETag(md5($response->getContent()))
->isNotModified($request);
});
$app->get('/', function () use($app) {
$response = new Response($app['twig']->render('index.twig'),200);
$response
->setSharedMaxAge(5)
->setPublic();
return $response;
})->bind('home');
$app->get('/header', function () use($app) {
$response = new Response($app['twig']->render('header.twig'),200);
$response
->setPrivate()
->setSharedMaxAge(0);
return $response;
})->bind('header');
$app->get('/footer', function () use($app) {
$response = new Response($app['twig']->render('footer.twig'),200);
$response
->setSharedMaxAge(10)
->setPublic();
return $response;
})->bind('footer');
$app->get('/nav', function () use($app) {
$response = new Response($app['twig']->render('nav.twig'),200);
$response
->setSharedMaxAge(20)
->setPublic();
return $response;
})->bind('nav');
$app->run();