1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace OpenVPN\Laravel; |
4
|
|
|
|
5
|
|
|
use OpenVPN\Config; |
6
|
|
|
use OpenVPN\Generator; |
7
|
|
|
use OpenVPN\Import; |
8
|
|
|
use OpenVPN\Interfaces\ConfigInterface; |
9
|
|
|
use OpenVPN\Interfaces\GeneratorInterface; |
10
|
|
|
use OpenVPN\Interfaces\ImportInterface; |
11
|
|
|
|
12
|
|
|
class Wrapper |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Get client configuration of OpenVPN |
16
|
|
|
* |
17
|
|
|
* @param array $params |
18
|
|
|
* |
19
|
|
|
* @return \OpenVPN\Interfaces\ConfigInterface |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function client(array $params = []): ConfigInterface |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$configs = config('openvpn-client'); |
24
|
|
|
$configs = array_merge($configs, $params); |
25
|
|
|
$object = new Config($configs); |
26
|
|
|
|
27
|
|
|
return $object->client(); |
28
|
|
|
} |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* Get server configuration of OpenVPN |
32
|
|
|
* |
33
|
|
|
* @param array $params |
34
|
|
|
* |
35
|
|
|
* @return \OpenVPN\Interfaces\ConfigInterface |
36
|
|
|
*/ |
37
|
|
View Code Duplication |
public function server(array $params = []): ConfigInterface |
|
|
|
|
38
|
|
|
{ |
39
|
|
|
$configs = config('openvpn-server'); |
40
|
|
|
$configs = array_merge($configs, $params); |
41
|
|
|
|
42
|
|
|
return new Config($configs); |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* Get instance of config generator |
47
|
|
|
* |
48
|
|
|
* @param \OpenVPN\Interfaces\ConfigInterface $config |
49
|
|
|
* |
50
|
|
|
* @return \OpenVPN\Interfaces\GeneratorInterface |
51
|
|
|
*/ |
52
|
|
|
public function generator(ConfigInterface $config): GeneratorInterface |
53
|
|
|
{ |
54
|
|
|
return new Generator($config); |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get instance of config importer |
59
|
|
|
* |
60
|
|
|
* @param string|null $filename |
61
|
|
|
* @param bool $isContent |
62
|
|
|
* |
63
|
|
|
* @return \OpenVPN\Interfaces\ImportInterface |
64
|
|
|
*/ |
65
|
|
|
public function importer(string $filename = null, bool $isContent = false): ImportInterface |
66
|
|
|
{ |
67
|
|
|
return new Import($filename, $isContent); |
68
|
|
|
} |
69
|
|
|
} |
70
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.