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