Completed
Pull Request — master (#444)
by Yanick
02:45
created

LiteSpeedProxy::clear()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 18

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 18
rs 9.6666
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 DirectoryIterator;
15
16
class LiteSpeedProxy extends AbstractProxy
17
{
18
    protected $binary = '/usr/local/lsws/bin/lswsctrl';
19
20
    protected $port = 8080;
21
22
    protected $cacheDir = '/usr/local/lsws/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 (false !== strpos($process->getOutput(), 'litespeed is running with PID')) {
36
            return;
37
        }
38
39
        // Starting deamonized
40
        $this->runCommand([
41
            $this->getBinary(),
42
            'start',
43
        ], true);
44
45
        $this->waitFor($this->getIp(), $this->getPort(), 2000);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51
    public function stop()
52
    {
53
        $this->runCommand([
54
            $this->getBinary(),
55
            'stop',
56
        ], true);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62
    public function clear()
63
    {
64
        // Runs as sudo to make sure it can be removed
65
        $this->runCommand([
66
            'rm',
67
            '-rf',
68
            $this->getCacheDir(),
69
        ], true);
70
71
        // Does not run as sudo to make sure it's created using the correct user
72
        $this->runCommand([
73
            'mkdir',
74
            '-p',
75
            $this->getCacheDir(),
76
        ]);
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