NginxProxy::clear()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 2
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
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
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()
84
    {
85 6
        return $this->cacheDir;
86
    }
87
}
88