Grpc\BaseStub::__construct PHP Méthode

__construct() public méthode

public __construct ( $hostname, $opts, $channel = null )
$hostname string
$opts array - 'update_metadata': (optional) a callback function which takes in a metadata array, and returns an updated metadata array - 'grpc.primary_user_agent': (optional) a user-agent string
$channel Channel An already created Channel object
    public function __construct($hostname, $opts, $channel = null)
    {
        $ssl_roots = file_get_contents(dirname(__FILE__) . '/../../../../etc/roots.pem');
        ChannelCredentials::setDefaultRootsPem($ssl_roots);
        $this->hostname = $hostname;
        $this->update_metadata = null;
        if (isset($opts['update_metadata'])) {
            if (is_callable($opts['update_metadata'])) {
                $this->update_metadata = $opts['update_metadata'];
            }
            unset($opts['update_metadata']);
        }
        $package_config = json_decode(file_get_contents(dirname(__FILE__) . '/../../composer.json'), true);
        if (!empty($opts['grpc.primary_user_agent'])) {
            $opts['grpc.primary_user_agent'] .= ' ';
        } else {
            $opts['grpc.primary_user_agent'] = '';
        }
        if (!empty($opts['grpc.ssl_target_name_override'])) {
            $this->hostname_override = $opts['grpc.ssl_target_name_override'];
        }
        $opts['grpc.primary_user_agent'] .= 'grpc-php/' . $package_config['version'];
        if (!array_key_exists('credentials', $opts)) {
            throw new \Exception("The opts['credentials'] key is now " . 'required. Please see one of the ' . 'ChannelCredentials::create methods');
        }
        if ($channel) {
            if (!is_a($channel, 'Channel')) {
                throw new \Exception('The channel argument is not a' . 'Channel object');
            }
            $this->channel = $channel;
        } else {
            $this->channel = new Channel($hostname, $opts);
        }
    }

Usage Example

 public function __construct($hostname, $opts)
 {
     parent::__construct($hostname, $opts);
 }
All Usage Examples Of Grpc\BaseStub::__construct