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

NginxProxy   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 0
loc 70
ccs 0
cts 35
cp 0
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A start() 0 12 1
A stop() 0 6 2
A clear() 0 5 1
A setCacheDir() 0 4 1
A getCacheDir() 0 4 1
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