1 | <?php |
||
26 | class MultiplexerClient implements BanCapable, PurgeCapable, RefreshCapable, TagCapable |
||
27 | { |
||
28 | /** |
||
29 | * @var ProxyClient[] |
||
30 | */ |
||
31 | private $proxyClients; |
||
32 | |||
33 | /** |
||
34 | * MultiplexerClient constructor. |
||
35 | * |
||
36 | * @param ProxyClient[] $proxyClients The list of Proxy clients |
||
37 | 7 | */ |
|
38 | public function __construct(array $proxyClients) |
||
51 | |||
52 | /** |
||
53 | * Forwards to all clients. |
||
54 | * |
||
55 | * @param array $headers HTTP headers that path must match to be banned |
||
56 | * |
||
57 | 1 | * @return $this |
|
58 | */ |
||
59 | 1 | public function ban(array $headers) |
|
65 | |||
66 | /** |
||
67 | * Forwards to all clients. |
||
68 | * |
||
69 | * @param string $path Regular expression pattern for URI to invalidate |
||
70 | * @param string $contentType Regular expression pattern for the content type to limit banning, for instance |
||
71 | * 'text' |
||
72 | * @param array|string $hosts Regular expression of a host name or list of exact host names to limit banning |
||
73 | * |
||
74 | 1 | * @return $this |
|
75 | */ |
||
76 | 1 | public function banPath($path, $contentType = null, $hosts = null) |
|
82 | |||
83 | /** |
||
84 | * Forwards to all clients. |
||
85 | * |
||
86 | * @throws ExceptionCollection If any errors occurred during flush |
||
87 | * |
||
88 | 1 | * @return int The number of cache invalidations performed per caching server |
|
89 | */ |
||
90 | 1 | public function flush() |
|
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | public function getTagsHeaderValue(array $tags) |
||
104 | { |
||
105 | return $this->invokeFirst(TagCapable::class, 'getTagsHeaderValue', [$tags]); |
||
106 | 1 | } |
|
107 | |||
108 | 1 | /** |
|
109 | * {@inheritdoc} |
||
110 | 1 | */ |
|
111 | public function getTagsHeaderName() |
||
112 | { |
||
113 | return $this->invokeFirst(TagCapable::class, 'getTagsHeaderName', []); |
||
114 | } |
||
115 | |||
116 | /** |
||
117 | * Forwards tag invalidation request to all clients. |
||
118 | * |
||
119 | * {@inheritdoc} |
||
120 | * |
||
121 | 1 | * @param array $tags |
|
122 | * |
||
123 | 1 | * @return $this |
|
124 | */ |
||
125 | 1 | public function invalidateTags(array $tags) |
|
131 | |||
132 | /** |
||
133 | * Forwards to all clients. |
||
134 | * |
||
135 | 4 | * @param string $url Path or URL to purge |
|
136 | * @param array $headers Extra HTTP headers to send to the caching proxy (optional) |
||
137 | 4 | * |
|
138 | 4 | * @return $this |
|
139 | 4 | */ |
|
140 | public function purge($url, array $headers = array()) |
||
146 | |||
147 | /** |
||
148 | * Forwards to all clients. |
||
149 | * |
||
150 | * @param string $url Path or URL to refresh |
||
151 | * @param array $headers Extra HTTP headers to send to the caching proxy (optional) |
||
152 | * |
||
153 | * @return $this |
||
154 | */ |
||
155 | public function refresh($url, array $headers = []) |
||
161 | |||
162 | /** |
||
163 | * Invoke the given $method on all available ProxyClients implementing the |
||
164 | * given $interface. |
||
165 | * |
||
166 | * @param string $interface The FQN of the interface |
||
167 | * @param string $method The method to invoke |
||
168 | * @param array $arguments The arguments to be passed to the method |
||
169 | */ |
||
170 | private function invoke($interface, $method, array $arguments) |
||
176 | |||
177 | /** |
||
178 | * Invoke the given $method on the first available ProxyClient implementing |
||
179 | * the given $interface. |
||
180 | * |
||
181 | * @param string $interface The FQN of the interface |
||
182 | * @param string $method The method to invoke |
||
183 | * @param array $arguments The arguments to be passed to the method |
||
184 | * |
||
185 | * @return mixed Return value of ProxyClient method call |
||
186 | */ |
||
187 | private function invokeFirst($interface, $method, array $arguments) |
||
193 | |||
194 | /** |
||
195 | * Get proxy clients that implement a feature interface |
||
196 | * |
||
197 | * @param string $interface |
||
198 | * |
||
199 | * @return ProxyClient[] |
||
200 | */ |
||
201 | private function getProxyClients($interface) |
||
210 | } |
||
211 |