Total Complexity | 5 |
Total Lines | 63 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
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 |
||
76 | } |
||
77 | } |
||
78 |