Completed
Pull Request — master (#444)
by Yanick
03:20
created

LiteSpeedProxy::setCacheDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 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
use Symfony\Component\Process\Exception\ProcessFailedException;
15
16
class LiteSpeedProxy extends AbstractProxy
17
{
18
    protected $binary = '/usr/local/lsws/bin/lswsctrl';
19
20
    protected $port = 8080;
21
22
    protected $cacheDir = 'cachedata';
23
24
    /**
25
     * {@inheritdoc}
26
     */
27
    public function start()
28
    {
29
        $process = $this->runCommand([
30
            $this->getBinary(),
31
            'status',
32
        ], true);
33
34
        // Already running
35
        if ('terminated' !== $process->getStatus()) {
36
            return;
37
        }
38
39
        $this->runCommand([
40
            $this->getBinary(),
41
            'start',
42
        ], true);
43
44
        $this->waitFor($this->getIp(), $this->getPort(), 2000);
45
    }
46
47
    /**
48
     * {@inheritdoc}
49
     */
50
    public function stop()
51
    {
52
        $process = $this->runCommand([
53
            $this->getBinary(),
54
            'status',
55
        ], true);
56
57
        // Already stopped
58
        if ('terminated' === $process->getStatus()) {
59
            return;
60
        }
61
62
        $this->runCommand([
63
            $this->getBinary(),
64
            'stop',
65
        ], true);
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function clear()
72
    {
73
        $this->runCommand([
74
            'rm',
75
            '-rf',
76
            $this->getCacheDir(),
77
        ]);
78
        $this->start();
79
    }
80
81
    /**
82
     * @param string $cacheDir
83
     */
84
    public function setCacheDir($cacheDir)
85
    {
86
        $this->cacheDir = $cacheDir;
87
    }
88
89
    /**
90
     * @return string
91
     */
92
    public function getCacheDir()
93
    {
94
        return $this->cacheDir;
95
    }
96
}
97