Issues (19)

src/Components/Invoker.php (1 issue)

Labels
Severity
1
<?php
2
/**
3
 * HTTP RPC client init
4
 * User: moyo
5
 * Date: 13/12/2017
6
 * Time: 10:16 AM
7
 */
8
9
namespace Carno\HRPC\Client\Components;
10
11
use Carno\Cluster\Resources;
12
use Carno\Console\Component;
13
use Carno\Console\Contracts\Application;
14
use Carno\Console\Contracts\Bootable;
15
use Carno\Consul\Types\Tagging as SDTags;
0 ignored issues
show
The type Carno\Consul\Types\Tagging was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
16
use Carno\Container\DI;
17
use Carno\HRPC\Client\Clustered;
18
use Carno\HRPC\Client\Contracts\Defined;
19
use Carno\HRPC\Client\Dispatcher;
20
use Carno\HRPC\Client\Selector;
21
use Carno\HRPC\Client\Tagging;
22
use Carno\HTTP\Options as HOptions;
23
use Carno\Pool\Options as POptions;
24
use Carno\RPC\Client;
25
use Carno\RPC\Contracts\Client\Cluster as ClusterAPI;
26
use Carno\RPC\Contracts\Client\Invoker as InvokerAPI;
27
28
class Invoker extends Component implements Bootable
29
{
30
    /**
31
     * @var array
32
     */
33
    protected $dependencies = [Resources::class];
34
35
    /**
36
     * @param Application $app
37
     */
38
    public function starting(Application $app) : void
39
    {
40
        /**
41
         * @var SDTags $sdTags
42
         */
43
        if (DI::has(SDTags::class) && $sdTags = DI::get(SDTags::class)) {
44
            $tags = $sdTags->getTags();
45
        }
46
47
        // new global cluster
48
        $c = new Clustered(DI::get(Resources::class), ...($tags ?? []));
49
50
        // custom configure
51
        $c->configure(static function (string $server) use ($app) {
52
            return $app->conf()->bind(
53
                (new HOptions())
54
                    ->setTimeouts()
55
                    ->keepalive($app->conf()->bind(new POptions(), Defined::OPTS_POOL), "rpc:{$server}"),
56
                Defined::OPTS_HTTP
57
            );
58
        });
59
60
        // assign global client implement
61
        DI::set(ClusterAPI::class, $c);
62
        DI::set(InvokerAPI::class, $d = DI::object(Dispatcher::class));
63
64
        // assign global extensions manager of client
65
        Client::layers()->append(null, DI::object(Tagging::class), DI::object(Selector::class), $d);
66
    }
67
}
68