Total Complexity | 7 |
Total Lines | 72 |
Duplicated Lines | 0 % |
Coverage | 100% |
Changes | 0 |
1 | <?php |
||
14 | class NginxProxy extends AbstractProxy |
||
15 | { |
||
16 | protected $binary = 'nginx'; |
||
17 | |||
18 | protected $configFile; |
||
19 | |||
20 | protected $port = 8080; |
||
21 | |||
22 | protected $pid = '/tmp/foshttpcache-nginx.pid'; |
||
23 | |||
24 | protected $cacheDir; |
||
25 | |||
26 | /** |
||
27 | * Constructor. |
||
28 | * |
||
29 | * @param string $configFile Path to NGINX configuration file |
||
30 | */ |
||
31 | 6 | public function __construct($configFile) |
|
32 | { |
||
33 | 6 | $this->setConfigFile($configFile); |
|
34 | 6 | $this->setCacheDir(sys_get_temp_dir().DIRECTORY_SEPARATOR.'foshttpcache-nginx'); |
|
35 | 6 | } |
|
36 | |||
37 | /** |
||
38 | * {@inheritdoc} |
||
39 | */ |
||
40 | 5 | public function start() |
|
41 | { |
||
42 | 5 | $this->runCommand( |
|
43 | 5 | $this->getBinary(), |
|
44 | [ |
||
45 | 5 | '-c', $this->getConfigFile(), |
|
46 | 5 | '-g', 'pid '.$this->pid.';', |
|
47 | ] |
||
48 | ); |
||
49 | |||
50 | 5 | $this->waitFor($this->getIp(), $this->getPort(), 2000); |
|
51 | 5 | } |
|
52 | |||
53 | /** |
||
54 | * {@inheritdoc} |
||
55 | */ |
||
56 | 6 | public function stop() |
|
57 | { |
||
58 | 6 | if (file_exists($this->pid)) { |
|
59 | 5 | $this->runCommand('kill', [trim(file_get_contents($this->pid))]); |
|
60 | } |
||
61 | 6 | } |
|
62 | |||
63 | /** |
||
64 | * {@inheritdoc} |
||
65 | */ |
||
66 | 5 | public function clear() |
|
67 | { |
||
68 | 5 | $this->runCommand('rm', ['-rf', $this->getCacheDir()]); |
|
69 | 5 | $this->start(); |
|
70 | 5 | } |
|
71 | |||
72 | /** |
||
73 | * @param string $cacheDir |
||
74 | */ |
||
75 | 6 | public function setCacheDir($cacheDir) |
|
76 | { |
||
77 | 6 | $this->cacheDir = $cacheDir; |
|
78 | 6 | } |
|
79 | |||
80 | /** |
||
81 | * @return string |
||
82 | */ |
||
83 | 6 | public function getCacheDir() |
|
86 | } |
||
87 | } |
||
88 |