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
|
|
|
use Starlit\App\Router; |
13
|
|
|
use Starlit\App\RouterInterface; |
14
|
|
|
use Starlit\App\View; |
15
|
|
|
use Starlit\App\ViewInterface; |
16
|
|
|
use Symfony\Component\HttpFoundation\Response; |
17
|
|
|
use Symfony\Component\HttpFoundation\Session\Session; |
18
|
|
|
use Symfony\Component\HttpFoundation\Session\SessionInterface; |
19
|
|
|
use Symfony\Component\HttpFoundation\Session\Storage\SessionStorageInterface; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @author Andreas Nilsson <http://github.com/jandreasn> |
23
|
|
|
*/ |
24
|
|
|
class StandardServiceProvider implements ServiceProviderInterface |
25
|
|
|
{ |
26
|
|
|
/** |
27
|
|
|
* @param BaseApp $app |
28
|
|
|
*/ |
29
|
22 |
|
public function register(BaseApp $app) |
30
|
|
|
{ |
31
|
22 |
|
$app->alias('sessionStorage', SessionStorageInterface::class); |
32
|
22 |
|
$app->set(SessionStorageInterface::class, function (BaseApp $app) { |
33
|
1 |
|
if ($app->isCli()) { |
34
|
1 |
|
return new \Symfony\Component\HttpFoundation\Session\Storage\MockArraySessionStorage(); |
35
|
|
|
} |
36
|
|
|
return new \Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage(); |
37
|
22 |
|
}); |
38
|
|
|
|
39
|
22 |
|
$app->alias('session', SessionInterface::class); |
40
|
22 |
|
$app->set(SessionInterface::class, Session::class); |
41
|
|
|
|
42
|
22 |
|
$app->alias('router', RouterInterface::class); |
43
|
22 |
|
$app->set(RouterInterface::class, function (BaseApp $app) { |
44
|
1 |
|
return new Router($app, $app->getConfig()->get('router', [])); |
45
|
22 |
|
}); |
46
|
|
|
|
47
|
22 |
|
$app->alias('view', ViewInterface::class); |
48
|
22 |
|
$app->set(ViewInterface::class, function (BaseApp $app) { |
49
|
3 |
|
return new View($app->getConfig()->get('view', [])); |
50
|
22 |
|
}); |
51
|
|
|
|
52
|
|
|
// Default response (force no cache) |
53
|
22 |
|
$app->alias('response', Response::class); |
54
|
22 |
|
$app->set(Response::class, function () { |
55
|
|
|
$response = new Response(); |
56
|
|
|
|
57
|
|
|
$response->headers->addCacheControlDirective('no-cache', true); |
58
|
|
|
$response->headers->addCacheControlDirective('max-age', 0); |
59
|
|
|
$response->headers->addCacheControlDirective('must-revalidate', true); |
60
|
|
|
$response->headers->addCacheControlDirective('no-store', true); |
61
|
|
|
|
62
|
|
|
return $response; |
63
|
22 |
|
}); |
64
|
|
|
} |
65
|
|
|
} |
66
|
|
|
|