1313
1414use FOS \JsRoutingBundle \Extractor \ExposedRoutesExtractorInterface ;
1515use FOS \JsRoutingBundle \Response \RoutesResponse ;
16+ use FOS \JsRoutingBundle \Util \CacheControlConfig ;
1617use Symfony \Component \Config \ConfigCache ;
1718use Symfony \Component \HttpFoundation \Request ;
1819use Symfony \Component \HttpFoundation \Response ;
@@ -32,14 +33,14 @@ class Controller
3233 protected $ serializer ;
3334
3435 /**
35- * @var \FOS\JsRoutingBundle\Extractor\ ExposedRoutesExtractorInterface
36+ * @var ExposedRoutesExtractorInterface
3637 */
3738 protected $ exposedRoutesExtractor ;
3839
3940 /**
40- * @var array
41+ * @var CacheControlConfig
4142 */
42- protected $ cacheControl ;
43+ protected $ cacheControlConfig ;
4344
4445 /**
4546 * @var boolean
@@ -56,10 +57,10 @@ class Controller
5657 */
5758 public function __construct ($ serializer , ExposedRoutesExtractorInterface $ exposedRoutesExtractor , array $ cacheControl = array (), $ debug = false )
5859 {
59- $ this ->serializer = $ serializer ;
60+ $ this ->serializer = $ serializer ;
6061 $ this ->exposedRoutesExtractor = $ exposedRoutesExtractor ;
61- $ this ->cacheControl = $ cacheControl ;
62- $ this ->debug = $ debug ;
62+ $ this ->cacheControlConfig = new CacheControlConfig ( $ cacheControl) ;
63+ $ this ->debug = $ debug ;
6364 }
6465
6566 /**
@@ -104,38 +105,7 @@ public function indexAction(Request $request, $_format)
104105 }
105106
106107 $ 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 );
139109
140110 return $ response ;
141111 }
0 commit comments