1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/* |
4
|
|
|
* This file is part of the FOSHttpCacheBundle package. |
5
|
|
|
* |
6
|
|
|
* (c) FriendsOfSymfony <http://friendsofsymfony.github.com/> |
7
|
|
|
* |
8
|
|
|
* For the full copyright and license information, please view the LICENSE |
9
|
|
|
* file that was distributed with this source code. |
10
|
|
|
*/ |
11
|
|
|
|
12
|
|
|
namespace FOS\HttpCacheBundle; |
13
|
|
|
|
14
|
|
|
use FOS\HttpCache\SymfonyCache\CacheEvent; |
15
|
|
|
use FOS\HttpCache\SymfonyCache\UserContextSubscriber; |
16
|
|
|
use Symfony\Bundle\FrameworkBundle\HttpCache\HttpCache as BaseHttpCache; |
17
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcher; |
18
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
19
|
|
|
use Symfony\Component\EventDispatcher\EventSubscriberInterface; |
20
|
|
|
use Symfony\Component\HttpFoundation\Request; |
21
|
|
|
use Symfony\Component\HttpKernel\HttpKernelInterface; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Base class for enhanced Symfony reverse proxy based on the symfony FrameworkBundle HttpCache. |
25
|
|
|
* |
26
|
|
|
* @deprecated Use FOS\HttpCacheBundle\SymfonyCache\EventDispatchingHttpCache instead. |
27
|
|
|
* |
28
|
|
|
* @author Jérôme Vieilledent <[email protected]> (courtesy of eZ Systems AS) |
29
|
|
|
* |
30
|
|
|
* {@inheritdoc} |
31
|
|
|
*/ |
32
|
|
|
abstract class HttpCache extends BaseHttpCache |
33
|
|
|
{ |
34
|
|
|
/** |
35
|
|
|
* Hash for anonymous user. |
36
|
|
|
* |
37
|
|
|
* @deprecated Use the options on UserContextSubscriber instead |
38
|
|
|
*/ |
39
|
|
|
const ANONYMOUS_HASH = '38015b703d82206ebc01d17a39c727e5'; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* Accept header value to be used to request the user hash to the backend application. |
43
|
|
|
* It must match the one defined in FOSHttpCacheBundle's configuration. |
44
|
|
|
* |
45
|
|
|
* @deprecated Use the options on UserContextSubscriber instead |
46
|
|
|
*/ |
47
|
|
|
const USER_HASH_ACCEPT_HEADER = 'application/vnd.fos.user-context-hash'; |
48
|
|
|
|
49
|
|
|
/** |
50
|
|
|
* Name of the header the user context hash will be stored into. |
51
|
|
|
* It must match the one defined in FOSHttpCacheBundle's configuration. |
52
|
|
|
* |
53
|
|
|
* @deprecated Use the options on UserContextSubscriber instead |
54
|
|
|
*/ |
55
|
|
|
const USER_HASH_HEADER = 'X-User-Context-Hash'; |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* URI used with the forwarded request for user context hash generation. |
59
|
|
|
* |
60
|
|
|
* @deprecated Use the options on UserContextSubscriber instead |
61
|
|
|
*/ |
62
|
|
|
const USER_HASH_URI = '/_fos_user_context_hash'; |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* HTTP Method used with the forwarded request for user context hash generation. |
66
|
|
|
* |
67
|
|
|
* @deprecated Use the options on UserContextSubscriber instead |
68
|
|
|
*/ |
69
|
|
|
const USER_HASH_METHOD = 'GET'; |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Prefix for session names. |
73
|
|
|
* Must match your session configuration. |
74
|
|
|
* |
75
|
|
|
* @deprecated Use the options on UserContextSubscriber instead |
76
|
|
|
*/ |
77
|
|
|
const SESSION_NAME_PREFIX = 'PHPSESSID'; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var UserContextSubscriber |
81
|
|
|
*/ |
82
|
|
|
private $subscriber; |
83
|
|
|
|
84
|
4 |
|
public function __construct(HttpKernelInterface $kernel, $cacheDir = null) |
85
|
|
|
{ |
86
|
4 |
|
parent::__construct($kernel, $cacheDir); |
87
|
|
|
|
88
|
4 |
|
$this->subscriber = new UserContextSubscriber(array( |
89
|
4 |
|
'anonymous_hash' => static::ANONYMOUS_HASH, |
|
|
|
|
90
|
4 |
|
'user_hash_accept_header' => static::USER_HASH_ACCEPT_HEADER, |
|
|
|
|
91
|
4 |
|
'user_hash_header' => static::USER_HASH_HEADER, |
|
|
|
|
92
|
4 |
|
'user_hash_uri' => static::USER_HASH_URI, |
|
|
|
|
93
|
4 |
|
'user_hash_method' => static::USER_HASH_METHOD, |
|
|
|
|
94
|
4 |
|
'session_name_prefix' => static::SESSION_NAME_PREFIX, |
|
|
|
|
95
|
4 |
|
)); |
96
|
4 |
|
} |
97
|
|
|
|
98
|
4 |
|
public function handle(Request $request, $type = HttpKernelInterface::MASTER_REQUEST, $catch = true) |
99
|
|
|
{ |
100
|
4 |
|
$event = new CacheEvent($this, $request); |
101
|
4 |
|
$this->subscriber->preHandle($event); |
102
|
4 |
|
if ($event->getResponse()) { |
103
|
2 |
|
return $event->getResponse(); |
104
|
|
|
} |
105
|
|
|
|
106
|
2 |
|
return parent::handle($request, $type, $catch); |
107
|
|
|
} |
108
|
|
|
} |
109
|
|
|
|
This class constant has been deprecated. The supplier of the class has supplied an explanatory message.
The explanatory message should give you some clue as to whether and when the constant will be removed from the class and what other constant to use instead.