1 | <?php |
||
8 | class Varnish |
||
9 | { |
||
10 | /** |
||
11 | * @param string|array $host |
||
12 | * |
||
13 | * @return \Symfony\Component\Process\Process |
||
14 | */ |
||
15 | public function flush($host = null) |
||
23 | |||
24 | /** |
||
25 | * @param array|string $host |
||
26 | * |
||
27 | * @return array |
||
28 | */ |
||
29 | protected function getHosts($host = null): array |
||
39 | |||
40 | public function generateBanCommand(array $hosts): string |
||
41 | { |
||
42 | if (! is_array($hosts)) { |
||
43 | $hosts = [$hosts]; |
||
44 | } |
||
45 | |||
46 | $hostsRegex = collect($hosts) |
||
47 | ->map(function (string $host) { |
||
48 | return "(^{$host}$)"; |
||
49 | }) |
||
50 | ->implode('|'); |
||
51 | |||
52 | $config = config('laravel-varnish'); |
||
53 | |||
54 | return "sudo varnishadm -S {$config['secret']} -T 127.0.0.1:{$config['administrative_port']} 'ban req.http.host ~ {$hostsRegex}'"; |
||
55 | } |
||
56 | |||
57 | protected function executeCommand(string $command): Process |
||
69 | } |
||
70 |