Router::servers()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
nc 1
nop 0
1
<?php
2
/**
3
 * Services router (named service -> implemented class)
4
 * User: moyo
5
 * Date: 20/09/2017
6
 * Time: 4:09 PM
7
 */
8
9
namespace Carno\RPC\Service;
10
11
use Carno\RPC\Chips\RTServer;
12
13
class Router
14
{
15
    use RTServer;
16
17
    /**
18
     * @var array
19
     */
20
    private $servers = [];
21
22
    /**
23
     * @var array
24
     */
25
    private $invokers = [];
26
27
    /**
28
     * @param Specification $service
29
     * @param string $implementer
30
     * @return static
31
     */
32
    public function add(Specification $service, string $implementer) : self
33
    {
34
        $this->invokers[$service->getServer()][$service->getService()] = [$service, $implementer];
35
        return $this;
36
    }
37
38
    /**
39
     * [Specification,implementer]
40
     * @param string $server
41
     * @param string $service
42
     * @return array
43
     */
44
    public function get(string $server, string $service) : array
45
    {
46
        return $this->invokers[$server][$service] ?? [];
47
    }
48
49
    /**
50
     * @param string $server
51
     * @return static
52
     */
53
    public function serving(string $server) : self
54
    {
55
        $this->servers = array_unique(array_merge($this->servers, [$server]));
56
        return $this;
57
    }
58
59
    /**
60
     * get all implemented servers
61
     * @return array
62
     */
63
    public function servers() : array
64
    {
65
        return $this->servers;
66
    }
67
68
    /**
69
     * [[Specification,implementer]]
70
     * @param string $server
71
     * @return array
72
     */
73
    public function services(string $server) : array
74
    {
75
        return $this->invokers[$server] ?? [];
76
    }
77
}
78