Endpoints::connecting()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 3
c 1
b 0
f 1
dl 0
loc 6
rs 10
cc 2
nc 2
nop 1
1
<?php
2
/**
3
 * Target endpoints
4
 * User: moyo
5
 * Date: 30/10/2017
6
 * Time: 3:12 PM
7
 */
8
9
namespace Carno\HRPC\Client;
10
11
use Carno\Cluster\Managed;
12
use Carno\Container\DI;
13
use Carno\HRPC\Client\Contracts\Defined;
14
use Carno\HTTP\Client;
15
use Carno\HTTP\Options;
16
use Carno\Net\Endpoint;
17
use Carno\Promise\Promised;
18
19
class Endpoints extends Managed
20
{
21
    /**
22
     * @var bool
23
     */
24
    protected $strict = false;
25
26
    /**
27
     * @var string
28
     */
29
    protected $type = 'rpc';
30
31
    /**
32
     * @var Options
33
     */
34
    private $options = null;
35
36
    /**
37
     * Clustered constructor.
38
     * @param string $server
39
     * @param array $tags
40
     * @param Options $options
41
     */
42
    public function __construct(string $server, array $tags, Options $options)
43
    {
44
        $this->tags = $tags;
45
        $this->server = $server;
46
        $this->options = $options;
47
    }
48
49
    /**
50
     * @param string ...$tags
51
     * @return Client
52
     */
53
    public function select(string ...$tags)
54
    {
55
        return $this->picking(...$tags);
56
    }
57
58
    /**
59
     * @param Endpoint $endpoint
60
     * @return Client
61
     */
62
    protected function connecting(Endpoint $endpoint)
63
    {
64
        if ($hjc = $endpoint->option(Defined::HJ_CLIENT)) {
65
            return DI::object($hjc, $this->options, $endpoint);
66
        }
67
        return new Client($this->options, $endpoint->address());
68
    }
69
70
    /**
71
     * @param Client $connected
72
     * @return Promised
73
     */
74
    protected function disconnecting($connected) : Promised
75
    {
76
        return $connected->close();
77
    }
78
}
79