| Conditions | 2 |
| Paths | 2 |
| Total Lines | 16 |
| Code Lines | 9 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 46 | public function generateBanCommand(array $hosts, string $url = null): string |
||
| 47 | { |
||
| 48 | $hostsRegex = collect($hosts) |
||
| 49 | ->map(function (string $host) { |
||
| 50 | return "(^{$host}$)"; |
||
| 51 | }) |
||
| 52 | ->implode('|'); |
||
| 53 | |||
| 54 | $config = config('varnish'); |
||
| 55 | |||
| 56 | $urlRegex = ''; |
||
| 57 | if (! empty($url)) { |
||
| 58 | $urlRegex = " && req.url ~ {$url}"; |
||
| 59 | } |
||
| 60 | |||
| 61 | return "sudo varnishadm -S {$config['administrative_secret']} -T 127.0.0.1:{$config['administrative_port']} 'ban req.http.host ~ {$hostsRegex}{$urlRegex}'"; |
||
| 62 | } |
||
| 77 |