17
17
use FOS \HttpCache \ProxyClient \Invalidation \PurgeInterface ;
18
18
use FOS \HttpCache \ProxyClient \Invalidation \RefreshInterface ;
19
19
use FOS \HttpCache \ProxyClient \Invalidation \TagsInterface ;
20
- use Http \Client \HttpAsyncClient ;
21
20
use Http \Message \MessageFactory ;
22
- use Symfony \Component \OptionsResolver \OptionsResolver ;
23
21
24
22
/**
25
23
* Varnish HTTP cache invalidator.
26
24
*
25
+ * Additional constructor options:
26
+ * - tags_header Header for tagging responses, defaults to X-Cache-Tags
27
+ *
27
28
* @author David de Boer <[email protected] >
28
29
*/
29
30
class Varnish extends AbstractProxyClient implements BanInterface, PurgeInterface, RefreshInterface, TagsInterface
@@ -46,38 +47,6 @@ class Varnish extends AbstractProxyClient implements BanInterface, PurgeInterfac
46
47
self ::HTTP_HEADER_CONTENT_TYPE => self ::REGEX_MATCH_ALL
47
48
];
48
49
49
- /**
50
- * Has a base URI been set?
51
- *
52
- * @var bool
53
- */
54
- private $ baseUriSet ;
55
-
56
- /**
57
- * @var string
58
- */
59
- private $ tagsHeader ;
60
-
61
- /**
62
- * {@inheritdoc}
63
- *
64
- * Additional options:
65
- *
66
- * - tags_header Header for tagging responses, defaults to X-Cache-Tags
67
- *
68
- * @param string $tagsHeader
69
- */
70
- public function __construct (
71
- array $ servers ,
72
- array $ options = [],
73
- HttpAsyncClient $ httpClient = null ,
74
- MessageFactory $ messageFactory = null
75
- ) {
76
- parent ::__construct ($ servers , $ options , $ httpClient , $ messageFactory );
77
- $ this ->baseUriSet = $ this ->options ['base_uri ' ] !== null ;
78
- $ this ->tagsHeader = $ this ->options ['tags_header ' ];
79
- }
80
-
81
50
/**
82
51
* Set the default headers that get merged with the provided headers in self::ban().
83
52
*
@@ -107,7 +76,7 @@ public function invalidateTags(array $tags)
107
76
{
108
77
$ tagExpression = sprintf ('(%s)(,.+)?$ ' , implode ('| ' , array_map ('preg_quote ' , $ this ->escapeTags ($ tags ))));
109
78
110
- return $ this ->ban ([$ this ->tagsHeader => $ tagExpression ]);
79
+ return $ this ->ban ([$ this ->options [ ' tags_header ' ] => $ tagExpression ]);
111
80
}
112
81
113
82
/**
@@ -125,7 +94,7 @@ public function getTagsHeaderValue(array $tags)
125
94
*/
126
95
public function getTagsHeaderName ()
127
96
{
128
- return $ this ->tagsHeader ;
97
+ return $ this ->options [ ' tags_header ' ] ;
129
98
}
130
99
131
100
/**
@@ -215,7 +184,7 @@ protected function queueRequest($method, $url, array $headers = [])
215
184
$ request = $ this ->messageFactory ->createRequest ($ method , $ url , $ headers );
216
185
217
186
if (self ::HTTP_METHOD_BAN !== $ method
218
- && ! $ this ->baseUriSet
187
+ && null === $ this ->options [ ' base_uri ' ]
219
188
&& !$ request ->getHeaderLine ('Host ' )
220
189
) {
221
190
throw MissingHostException::missingHost ($ url );
0 commit comments