Completed
Pull Request — master (#364)
by Alessandro
04:31
created

NginxProxy::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php
2
3
/*
4
 * This file is part of the FOSHttpCache package.
5
 *
6
 * (c) FriendsOfSymfony <http://friendsofsymfony.github.com/>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace FOS\HttpCache\Test\Proxy;
13
14
class NginxProxy extends AbstractProxy
15
{
16
    protected $binary = 'nginx';
17
    protected $configFile;
18
    protected $port = 8080;
19
    protected $pid = '/tmp/foshttpcache-nginx.pid';
20
    protected $cacheDir;
21
22
    /**
23
     * Constructor.
24
     *
25
     * @param string $configFile Path to NGINX configuration file
26
     */
27
    public function __construct($configFile)
28
    {
29
        $this->setConfigFile($configFile);
30
        $this->setCacheDir(sys_get_temp_dir().DIRECTORY_SEPARATOR.'foshttpcache-nginx');
31
    }
32
33
    /**
34
     * {@inheritdoc}
35
     */
36
    public function start()
37
    {
38
        $this->runCommand(
39
            $this->getBinary(),
40
            [
41
                '-c', $this->getConfigFile(),
42
                '-g', 'pid '.$this->pid.';',
43
            ]
44
        );
45
46
        $this->waitFor($this->getIp(), $this->getPort(), 2000);
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function stop()
53
    {
54
        if (file_exists($this->pid)) {
55
            $this->runCommand('kill', [trim(file_get_contents($this->pid))]);
56
        }
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function clear()
63
    {
64
        $this->runCommand('rm', ['-rf', $this->getCacheDir()]);
65
        $this->start();
66
    }
67
68
    /**
69
     * @param string $cacheDir
70
     */
71
    public function setCacheDir($cacheDir)
72
    {
73
        $this->cacheDir = $cacheDir;
74
    }
75
76
    /**
77
     * @return string
78
     */
79
    public function getCacheDir()
80
    {
81
        return $this->cacheDir;
82
    }
83
}
84