public function __construct()

in src/Config.php [40:74]


    public function __construct($target, $conf = null, ?CacheItemPoolInterface $cacheItemPool = null)
    {
        if ($conf == null) {
            // If there is no configure file, use the default gRPC channel.
            $this->gcp_call_invoker = new \Grpc\DefaultCallInvoker();
            return;
        }

        $gcp_channel = null;
        $url_host = parse_url($target, PHP_URL_HOST);
        $this->hostname = $url_host ? $url_host : $target;
        $channel_pool_key = $this->hostname . '.gcp.channel.' . getmypid();

        if (!$cacheItemPool) {
            $affinity_conf = $this->parseConfObject($conf);
            $gcp_call_invoker = new GCPCallInvoker($affinity_conf);
            $this->gcp_call_invoker = $gcp_call_invoker;
        } else {
            $item = $cacheItemPool->getItem($channel_pool_key);
            if ($item->isHit()) {
                // Channel pool for the $hostname API has already created.
                $gcp_call_invoker = unserialize($item->get());
            } else {
                $affinity_conf = $this->parseConfObject($conf);
                // Create GCP channel based on the information.
                $gcp_call_invoker = new GCPCallInvoker($affinity_conf);
            }
            $this->gcp_call_invoker = $gcp_call_invoker;
            register_shutdown_function(function ($gcp_call_invoker, $cacheItemPool, $item) {
                // Push the current gcp_channel back into the pool when the script finishes.
                $item->set(serialize($gcp_call_invoker));
                $cacheItemPool->save($item);
            }, $gcp_call_invoker, $cacheItemPool, $item);
        }
    }