13
13
14
14
use FOS \JsRoutingBundle \Extractor \ExposedRoutesExtractorInterface ;
15
15
use FOS \JsRoutingBundle \Response \RoutesResponse ;
16
+ use FOS \JsRoutingBundle \Util \CacheControlConfig ;
16
17
use Symfony \Component \Config \ConfigCache ;
17
18
use Symfony \Component \HttpFoundation \Request ;
18
19
use Symfony \Component \HttpFoundation \Response ;
@@ -32,14 +33,14 @@ class Controller
32
33
protected $ serializer ;
33
34
34
35
/**
35
- * @var \FOS\JsRoutingBundle\Extractor\ ExposedRoutesExtractorInterface
36
+ * @var ExposedRoutesExtractorInterface
36
37
*/
37
38
protected $ exposedRoutesExtractor ;
38
39
39
40
/**
40
- * @var array
41
+ * @var CacheControlConfig
41
42
*/
42
- protected $ cacheControl ;
43
+ protected $ cacheControlConfig ;
43
44
44
45
/**
45
46
* @var boolean
@@ -56,10 +57,10 @@ class Controller
56
57
*/
57
58
public function __construct ($ serializer , ExposedRoutesExtractorInterface $ exposedRoutesExtractor , array $ cacheControl = array (), $ debug = false )
58
59
{
59
- $ this ->serializer = $ serializer ;
60
+ $ this ->serializer = $ serializer ;
60
61
$ this ->exposedRoutesExtractor = $ exposedRoutesExtractor ;
61
- $ this ->cacheControl = $ cacheControl ;
62
- $ this ->debug = $ debug ;
62
+ $ this ->cacheControlConfig = new CacheControlConfig ( $ cacheControl) ;
63
+ $ this ->debug = $ debug ;
63
64
}
64
65
65
66
/**
@@ -104,38 +105,7 @@ public function indexAction(Request $request, $_format)
104
105
}
105
106
106
107
$ response = new Response ($ content , 200 , array ('Content-Type ' => $ request ->getMimeType ($ _format )));
107
-
108
- return $ this ->setCacheHeaders ($ response );
109
- }
110
-
111
- /**
112
- * @param Response $response
113
- *
114
- * @return Response
115
- */
116
- protected function setCacheHeaders (Response $ response )
117
- {
118
- if (empty ($ this ->cacheControl ['enabled ' ])) {
119
- return $ response ;
120
- }
121
-
122
- $ this ->cacheControl ['public ' ] ? $ response ->setPublic () : $ response ->setPrivate ();
123
-
124
- if (is_integer ($ this ->cacheControl ['maxage ' ])) {
125
- $ response ->setMaxAge ($ this ->cacheControl ['maxage ' ]);
126
- }
127
-
128
- if (is_integer ($ this ->cacheControl ['smaxage ' ])) {
129
- $ response ->setSharedMaxAge ($ this ->cacheControl ['smaxage ' ]);
130
- }
131
-
132
- if ($ this ->cacheControl ['expires ' ] !== null ) {
133
- $ response ->setExpires (new \DateTime ($ this ->cacheControl ['expires ' ]));
134
- }
135
-
136
- if (!empty ($ this ->cacheControl ['vary ' ])) {
137
- $ response ->setVary ($ this ->cacheControl ['vary ' ]);
138
- }
108
+ $ this ->cacheControlConfig ->apply ($ response );
139
109
140
110
return $ response ;
141
111
}
0 commit comments