37 private $vclTemplateLocator;
42 private $sslOffloadedHeader;
47 private $designExceptions;
67 $designExceptions = []
69 $this->backendHost = $backendHost;
70 $this->backendPort = $backendPort;
71 $this->accessList = $accessList;
72 $this->gracePeriod = $gracePeriod;
73 $this->vclTemplateLocator = $vclTemplateLocator;
74 $this->sslOffloadedHeader = $sslOffloadedHeader;
75 $this->designExceptions = $designExceptions;
88 return strtr(
$template, $this->getReplacements());
96 private function getReplacements()
99 '/* {{ host }} */' => $this->getBackendHost(),
100 '/* {{ port }} */' => $this->getBackendPort(),
101 '/* {{ ips }} */' => $this->getTransformedAccessList(),
102 '/* {{ design_exceptions_code }} */' => $this->getRegexForDesignExceptions(),
106 '/* {{ ssl_offloaded_header }} */' => str_replace(
'_',
'-', $this->getSslOffloadedHeader()),
107 '/* {{ grace_period }} */' => $this->getGracePeriod(),
119 private function getRegexForDesignExceptions()
122 $tpl =
"%s (req.http.user-agent ~ \"%s\") {\n".
" hash_data(\"%s\");\n".
" }";
129 if (preg_match(
'/^[\W]{1}(.*)[\W]{1}(\w+)?$/',
$rule[
'regexp'], $matches)) {
130 if (!empty($matches[2])) {
131 $pattern = sprintf(
"(?%s)%s", $matches[2], $matches[1]);
135 $if =
$i == 0 ?
'if' :
' elsif';
154 private function getTransformedAccessList()
158 $this->getAccessList(),
159 function ($ips, $ip) use ($tpl) {
160 return $ips.sprintf($tpl, trim($ip)) .
"\n";
173 private function getAccessList()
175 return $this->accessList;
183 private function getBackendHost()
185 return $this->backendHost;
193 private function getBackendPort()
195 return $this->backendPort;
203 private function getGracePeriod()
205 return $this->gracePeriod;
213 private function getSslOffloadedHeader()
215 return $this->sslOffloadedHeader;
221 private function getDesignExceptions()
223 return $this->designExceptions;
__construct(VclTemplateLocatorInterface $vclTemplateLocator, $backendHost, $backendPort, $accessList, $gracePeriod, $sslOffloadedHeader, $designExceptions=[])