Completed
Push — master ( ad721e...9c02d3 )
by Garveen
04:01
created

Server::getWrapper()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
namespace Laravoole;
3
4
use Exception;
5
use ReflectionClass;
6
7
use Laravoole\Wrapper\ServerInterface;
8
9
class Server
10
{
11
    protected $wrapper;
12
13
    protected $startingCallbacks = [];
14
15 20
    public function __construct($wrapper, $wrapper_file = '')
16
    {
17 20
        if (!class_exists($wrapper)) {
18
            require $wrapper_file;
19
        }
20 20
        $ref = new ReflectionClass($wrapper);
21 20
        if(!$ref->implementsInterface(ServerInterface::class)) {
22
            throw new Exception("$wrapper must be instance of Laravoole\\Wrapper\\ServerInterface", 1);
23
        }
24
25 20
        $this->wrapper = $wrapper;
26 20
    }
27
28
    public function getWrapper()
29
    {
30
        return $this->wrapper;
31
    }
32
33 20
    public function start($configs)
34
    {
35 20
        require __DIR__ . '/Mime.php';
36 20
        $wrapper = new $this->wrapper($configs['host'], $configs['port']);
37 20
        $wrapper->init($configs);
38 20
        return $wrapper->start();
39
    }
40
41
}
42