|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Starlit App. |
|
4
|
|
|
* |
|
5
|
|
|
* @copyright Copyright (c) 2016 Starweb AB |
|
6
|
|
|
* @license BSD 3-Clause |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace Starlit\App\Provider; |
|
10
|
|
|
|
|
11
|
|
|
use Starlit\App\BaseApp; |
|
12
|
|
|
|
|
13
|
|
|
/** |
|
14
|
|
|
* @author Andreas Nilsson <http://github.com/jandreasn> |
|
15
|
|
|
*/ |
|
16
|
|
|
class StandardServiceProvider implements ServiceProviderInterface |
|
17
|
|
|
{ |
|
18
|
|
|
/** |
|
19
|
|
|
* @param BaseApp $app |
|
20
|
|
|
*/ |
|
21
|
|
|
public function register(BaseApp $app) |
|
22
|
|
|
{ |
|
23
|
21 |
|
$app->set('sessionStorage', function (BaseApp $app) { |
|
24
|
1 |
|
if ($app->isCli()) { |
|
25
|
1 |
|
return new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage(); |
|
26
|
|
|
} else { |
|
27
|
|
|
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage(); |
|
28
|
|
|
} |
|
29
|
21 |
|
}); |
|
30
|
|
|
|
|
31
|
21 |
|
$app->set('session', function (BaseApp $app) { |
|
32
|
1 |
|
return new \Symfony\Component\HttpFoundation\Session\Session($app->getNew('sessionStorage')); |
|
33
|
21 |
|
}); |
|
34
|
|
|
|
|
35
|
21 |
|
$app->set('router', function (BaseApp $app) { |
|
36
|
1 |
|
return new \Starlit\App\Router($app, $app->getConfig()->get('router', [])); |
|
37
|
21 |
|
}); |
|
38
|
|
|
|
|
39
|
21 |
|
$app->set('view', function (BaseApp $app) { |
|
40
|
3 |
|
return new \Starlit\App\View($app->getConfig()->get('view', [])); |
|
41
|
21 |
|
}); |
|
42
|
|
|
|
|
43
|
|
|
// Default response (force no cache) |
|
44
|
21 |
|
$app->set('response', function () { |
|
45
|
|
|
$response = new \Symfony\Component\HttpFoundation\Response(); |
|
46
|
|
|
|
|
47
|
|
|
$response->headers->addCacheControlDirective('no-cache', true); |
|
48
|
|
|
$response->headers->addCacheControlDirective('max-age', 0); |
|
49
|
|
|
$response->headers->addCacheControlDirective('must-revalidate', true); |
|
50
|
|
|
$response->headers->addCacheControlDirective('no-store', true); |
|
51
|
|
|
|
|
52
|
|
|
return $response; |
|
53
|
21 |
|
}); |
|
54
|
|
|
} |
|
55
|
|
|
} |
|
56
|
|
|
|