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

LiteSpeedProxy   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 2
dl 0
loc 86
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A start() 0 25 2
A stop() 0 7 1
A clear() 0 18 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 LiteSpeedProxy extends AbstractProxy
15
{
16
    protected $binary = '/usr/local/lsws/bin/lswsctrl';
17
18
    protected $port = 8080;
19
20
    protected $cacheDir = '/usr/local/lsws/cachedata';
21
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function start()
26
    {
27
        $process = $this->runCommand([
28
            $this->getBinary(),
29
            'status',
30
        ], true);
31
32
        // Already running, restart
33
        if (false !== strpos($process->getOutput(), 'litespeed is running with PID')) {
34
            $this->runCommand([
35
                $this->getBinary(),
36
                'restart',
37
            ], true);
38
39
            return;
40
        }
41
42
        // Otherwise start
43
        $this->runCommand([
44
            $this->getBinary(),
45
            'start',
46
        ], true);
47
48
        $this->waitFor($this->getIp(), $this->getPort(), 2000);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54
    public function stop()
55
    {
56
        $this->runCommand([
57
            $this->getBinary(),
58
            'stop',
59
        ], true);
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function clear()
66
    {
67
        // Runs as sudo to make sure it can be removed
68
        $this->runCommand([
69
            'rm',
70
            '-rf',
71
            $this->getCacheDir(),
72
        ], true);
73
74
        // Does not run as sudo to make sure it's created using the correct user
75
        $this->runCommand([
76
            'mkdir',
77
            '-p',
78
            $this->getCacheDir(),
79
        ]);
80
81
        $this->start();
82
    }
83
84
    /**
85
     * @param string $cacheDir
86
     */
87
    public function setCacheDir($cacheDir)
88
    {
89
        $this->cacheDir = $cacheDir;
90
    }
91
92
    /**
93
     * @return string
94
     */
95
    public function getCacheDir()
96
    {
97
        return $this->cacheDir;
98
    }
99
}
100