Completed
Pull Request — master (#444)
by Yanick
18:04 queued 03:05
created

LiteSpeedProxy::clear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

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