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