Google\Cloud\PubSub\V1\PublisherClient::__construct PHP Method

__construct() public method

Constructor.
public __construct ( array $options = [] )
$options array { Optional. Options for configuring the service API wrapper. @type string $serviceAddress The domain name of the API remote host. Default 'pubsub.googleapis.com'. @type mixed $port The port on which to connect to the remote host. Default 443. @type Grpc\ChannelCredentials $sslCreds A `ChannelCredentials` for use with an SSL-enabled channel. Default: a credentials object returned from Grpc\ChannelCredentials::createSsl() @type array $scopes A string array of scopes to use when acquiring credentials. Default the scopes for the Google Cloud Pub/Sub API. @type array $retryingOverride An associative array of string => RetryOptions, where the keys are method names (e.g. 'createFoo'), that overrides default retrying settings. A value of null indicates that the method in question should not retry. @type int $timeoutMillis The timeout in milliseconds to use for calls that don't use retries. For calls that use retries, set the timeout in RetryOptions. Default: 30000 (30 seconds) @type string $appName The codename of the calling service. Default 'gax'. @type string $appVersion The version of the calling service. Default: the current version of GAX. @type Google\Auth\CredentialsLoader $credentialsLoader A CredentialsLoader object created using the Google\Auth library. }
    public function __construct($options = [])
    {
        $defaultScopes = ['https://www.googleapis.com/auth/cloud-platform', 'https://www.googleapis.com/auth/pubsub'];
        $defaultOptions = ['serviceAddress' => self::SERVICE_ADDRESS, 'port' => self::DEFAULT_SERVICE_PORT, 'scopes' => $defaultScopes, 'retryingOverride' => null, 'timeoutMillis' => self::DEFAULT_TIMEOUT_MILLIS, 'appName' => 'gax', 'appVersion' => AgentHeaderDescriptor::getGaxVersion()];
        $options = array_merge($defaultOptions, $options);
        $headerDescriptor = new AgentHeaderDescriptor(['clientName' => $options['appName'], 'clientVersion' => $options['appVersion'], 'codeGenName' => self::_CODEGEN_NAME, 'codeGenVersion' => self::_CODEGEN_VERSION, 'gaxVersion' => AgentHeaderDescriptor::getGaxVersion(), 'phpVersion' => phpversion()]);
        $defaultDescriptors = ['headerDescriptor' => $headerDescriptor];
        $this->descriptors = ['createTopic' => $defaultDescriptors, 'publish' => $defaultDescriptors, 'getTopic' => $defaultDescriptors, 'listTopics' => $defaultDescriptors, 'listTopicSubscriptions' => $defaultDescriptors, 'deleteTopic' => $defaultDescriptors, 'setIamPolicy' => $defaultDescriptors, 'getIamPolicy' => $defaultDescriptors, 'testIamPermissions' => $defaultDescriptors];
        $pageStreamingDescriptors = self::getPageStreamingDescriptors();
        foreach ($pageStreamingDescriptors as $method => $pageStreamingDescriptor) {
            $this->descriptors[$method]['pageStreamingDescriptor'] = $pageStreamingDescriptor;
        }
        $clientConfigJsonString = file_get_contents(__DIR__ . '/resources/publisher_client_config.json');
        $clientConfig = json_decode($clientConfigJsonString, true);
        $this->defaultCallSettings = CallSettings::load('google.pubsub.v1.Publisher', $clientConfig, $options['retryingOverride'], GrpcConstants::getStatusCodeNames(), $options['timeoutMillis']);
        $this->scopes = $options['scopes'];
        $createStubOptions = [];
        if (array_key_exists('sslCreds', $options)) {
            $createStubOptions['sslCreds'] = $options['sslCreds'];
        }
        $grpcCredentialsHelperOptions = array_diff_key($options, $defaultOptions);
        $this->grpcCredentialsHelper = new GrpcCredentialsHelper($this->scopes, $grpcCredentialsHelperOptions);
        $createIamPolicyStubFunction = function ($hostname, $opts) {
            return new IAMPolicyGrpcClient($hostname, $opts);
        };
        $this->iamPolicyStub = $this->grpcCredentialsHelper->createStub($createIamPolicyStubFunction, $options['serviceAddress'], $options['port'], $createStubOptions);
        $createPublisherStubFunction = function ($hostname, $opts) {
            return new PublisherGrpcClient($hostname, $opts);
        };
        $this->publisherStub = $this->grpcCredentialsHelper->createStub($createPublisherStubFunction, $options['serviceAddress'], $options['port'], $createStubOptions);
    }