当前位置: 首页>>代码示例>>PHP>>正文


PHP Client::setDefaultOption方法代码示例

本文整理汇总了PHP中GuzzleHttp\Client::setDefaultOption方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::setDefaultOption方法的具体用法?PHP Client::setDefaultOption怎么用?PHP Client::setDefaultOption使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在GuzzleHttp\Client的用法示例。


在下文中一共展示了Client::setDefaultOption方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getGuzzleClient

 /**
  * Setup Guzzle client
  *
  * @return Client
  */
 public function getGuzzleClient()
 {
     $client = new Client(['base_url' => $this->url]);
     $client->setDefaultOption('headers', ['Accept' => 'application/vnd.' . $this->name . '.' . $this->version . '+json', 'Authorization' => $this->auth->getGuzzleOptions('token')]);
     $client->setDefaultOption('auth', $this->auth->getGuzzleOptions('auth'));
     $client->setDefaultOption('exceptions', $this->auth->getGuzzleOptions('exceptions'));
     return $client;
 }
开发者ID:theconceptstore,项目名称:jwt-api-client,代码行数:13,代码来源:ApiClient.php

示例2: __construct

 /**
  * @param string $token
  * @param Client|ClientInterface $client
  * @throws \Exception
  */
 public function __construct($token, ClientInterface $client = null)
 {
     if (is_null($client)) {
         $client = new \GuzzleHttp\Client();
     }
     $this->client = $client;
     $this->client->setDefaultOption('headers', ['loaderio-auth' => $token]);
 }
开发者ID:shin1x1,项目名称:loaderio-runner,代码行数:13,代码来源:Client.php

示例3: Client

 function __construct(array $config)
 {
     $this->config = $config;
     $this->requiredFields = ['api_token', 'inbox_id'];
     $this->validateConfig();
     $this->mailtrap = new Client(['base_url' => $this->base_url]);
     $this->mailtrap->setDefaultOption('query', ['api_token' => $this->config['api_token']]);
 }
开发者ID:psyao,项目名称:mailtester,代码行数:8,代码来源:MailTrap.php

示例4: getClient

 /**
  * @return Client|null
  */
 protected static function getClient()
 {
     if (self::$client === NULL) {
         self::$client = new Client(['base_uri' => Bitcodin::getBaseUrl()]);
         if (Bitcodin::isHttpsEnabled()) {
             self::$client->setDefaultOption('verify', __DIR__ . '/cacert.pem');
         }
     }
     return self::$client;
 }
开发者ID:bitmovin,项目名称:bitcodin-php,代码行数:13,代码来源:ApiResource.php

示例5: _initialize

 public function _initialize()
 {
     $url = "https://mailtrap.io/";
     $this->mailtrap = new \GuzzleHttp\Client(['base_uri' => $url, 'timeout' => 1.0]);
     if (isset($this->config['guzzleRequestOptions'])) {
         foreach ($this->config['guzzleRequestOptions'] as $option => $value) {
             $this->mailtrap->setDefaultOption($option, $value);
         }
     }
 }
开发者ID:ericmartel,项目名称:codeception-email-mailtrap,代码行数:10,代码来源:Mailtrap.php

示例6: getClient

 /**
  * Get a configured client, creating one if one hasn't been set by
  * setClient().
  *
  * @return Client
  */
 public function getClient()
 {
     if (!$this->client) {
         $this->client = new Client();
         $headers = $this->client->getDefaultOption('headers');
         $headers['User-Agent'] = 'PkpPlnBot 1.0; http://pkp.sfu.ca';
         $this->client->setDefaultOption('headers', $headers);
     }
     return $this->client;
 }
开发者ID:ubermichael,项目名称:pkppln-php,代码行数:16,代码来源:HarvestCommand.php

示例7: _initialize

 public function _initialize()
 {
     $url = trim($this->config['url'], '/') . ':' . $this->config['port'];
     $this->mailhog = new \GuzzleHttp\Client(['base_uri' => $url, 'timeout' => 1.0]);
     if (isset($this->config['guzzleRequestOptions'])) {
         foreach ($this->config['guzzleRequestOptions'] as $option => $value) {
             $this->mailhog->setDefaultOption($option, $value);
         }
     }
 }
开发者ID:ericmartel,项目名称:codeception-email-mailhog,代码行数:10,代码来源:MailHog.php

示例8: setTinderAuthenticationToken

 /**
  * @param $token
  * @throws Exception
  */
 private function setTinderAuthenticationToken($token)
 {
     if (strlen($token) != 36) {
         throw new Exception("The supplied Tinder Authentication Token is not in UUID4 format, it should be 36 characters long (including dashes).");
     }
     //if(!preg_match("^[0-9A-F]{8}-[0-9A-F]{4}-4[0-9A-F]{3}-[89AB][0-9A-F]{3}-[0-9A-F]{12}$", $token))
     //    throw new Exception("The supplied Tinder Authentication Token is not in UUID4 format.");
     $this->tinderAuthenticationToken = $token;
     $this->guzzleClient->setDefaultOption('headers/X-Auth-Token', $token);
 }
开发者ID:adewra,项目名称:tinder,代码行数:14,代码来源:TinderClient.php

示例9: registerGuzzle

 /**
  * Register the Guzzle driver.
  *
  * @return void
  */
 protected function registerGuzzle()
 {
     $this->app->singleton('http', function ($app) {
         $client = new Client(['base_url' => "https://{$app['school']}.magister.net/api/"]);
         $client->setDefaultOption('exceptions', false);
         $client->setDefaultOption('cookies', new SessionCookieJar($app['cookie']));
         CacheSubscriber::attach($client);
         return $client;
     });
 }
开发者ID:JeroenJochems,项目名称:Magister,代码行数:15,代码来源:HttpServiceProvider.php

示例10: factory

 public static function factory($config = array(), $logger = null)
 {
     $client = new Client(['base_url' => $config['base_url'] . '/']);
     $client->setDefaultOption('headers', array('Authorization' => 'Bearer ' . $config['access_token']));
     $client->setDefaultOption('config', ['curl' => [CURLOPT_SSLVERSION => 1]]);
     if ($logger !== null) {
         $subscriber = new LogSubscriber($logger, ">>>>>>>>\n{request}\n<<<<<<<<\n{response}");
         $client->getEmitter()->attach($subscriber);
     }
     return $client;
 }
开发者ID:ignited,项目名称:flysystem-onedrive,代码行数:11,代码来源:OneDriveClient.php

示例11: setDefaultOptions

 /**
  * Sets the default options to the client
  */
 private function setDefaultOptions()
 {
     // Either use user bundle or the system bundle if nothing is specified
     if ($this->certificateManager->listCertificates() !== []) {
         $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath());
     } else {
         $this->client->setDefaultOption('verify', $this->certificateManager->getAbsoluteBundlePath(null));
     }
     $this->client->setDefaultOption('headers/User-Agent', 'ownCloud Server Crawler');
     if ($this->getProxyUri() !== '') {
         $this->client->setDefaultOption('proxy', $this->getProxyUri());
     }
 }
开发者ID:nseps,项目名称:core,代码行数:16,代码来源:client.php

示例12: setDefaultOptions

 /**
  * Sets the default options to the client
  */
 private function setDefaultOptions()
 {
     // Either use default bundle or the user bundle if nothing is specified
     if ($this->certificateManager->listCertificates() !== []) {
         $dataDir = $this->config->getSystemValue('datadirectory');
         $this->client->setDefaultOption('verify', $dataDir . '/' . $this->certificateManager->getCertificateBundle());
     } else {
         $this->client->setDefaultOption('verify', \OC::$SERVERROOT . '/config/ca-bundle.crt');
     }
     $this->client->setDefaultOption('headers/User-Agent', 'ownCloud Server Crawler');
     if ($this->getProxyUri() !== '') {
         $this->client->setDefaultOption('proxy', $this->getProxyUri());
     }
 }
开发者ID:unrealbato,项目名称:core,代码行数:17,代码来源:client.php

示例13: getClient

 /**
  * @return \GuzzleHttp\Client
  */
 protected function getClient()
 {
     $config = $this->getConfiguration();
     $client = new Client(['base_url' => 'https://rest.nexmo.com', 'defaults' => ['body' => ['api_key' => $config['api_key'], 'api_secret' => $config['api_secret'], 'from' => $config['account_from_number']]]]);
     $client->setDefaultOption('body/api_key', $config['api_key']);
     return $client;
 }
开发者ID:onema,项目名称:nexmo-cli,代码行数:10,代码来源:BaseCommand.php

示例14: downloadAction

 /**
  * @Request({"update": "json"})
  * @Response("json")
  */
 public function downloadAction($update = null)
 {
     try {
         if ($update) {
             $this['session']->set('system.update', $update);
         } else {
             throw new Exception(__('Unable to find update.'));
         }
         $this['session']->set('system.updateDir', $path = $this->temp . '/' . sha1(uniqid()));
         $client = new Client();
         $client->setDefaultOption('query/api_key', $this->apiKey);
         $downloader = new PackageDownloader($client);
         $downloader->downloadFile($path, $update['url'], $update['shasum']);
         $response = ['message' => __('Copying files...'), 'step' => $this['url']->route('@system/update/copy'), 'progress' => 33];
     } catch (ArchiveExtractionException $e) {
         $response = ['error' => __('Package extraction failed.')];
     } catch (ChecksumVerificationException $e) {
         $response = ['error' => __('Package checksum verification failed.')];
     } catch (UnauthorizedDownloadException $e) {
         $response = ['error' => __('Invalid API key.')];
     } catch (DownloadErrorException $e) {
         $response = ['error' => __('Package download failed.')];
     } catch (NotWritableException $e) {
         $response = ['error' => __('Path is not writable.')];
     } catch (Exception $e) {
         $response = ['error' => $e->getMessage()];
     }
     return $response;
 }
开发者ID:amirkheirabadi,项目名称:pagekit,代码行数:33,代码来源:UpdateController.php

示例15: testAuthenticateClient

 public function testAuthenticateClient()
 {
     $guzzle = new Client(['base_url' => 'http://example.com/api']);
     $guzzle->setDefaultOption('headers', ['X-Test' => '1']);
     $expiresIn = 5000;
     $expires = time() + $expiresIn;
     $mock = new Mock([new Response(200, [], Stream::factory(json_encode((object) ['headerToken' => 1234, 'queryToken' => 4321, 'expiresIn' => $expiresIn]))), new Response(200, [], Stream::factory(json_encode((object) ['data' => [1, 2, 3]]))), new Response(200, [], Stream::factory(json_encode((object) ['data' => [1, 2, 3]])))]);
     $guzzle->getEmitter()->attach($mock);
     $history = new History();
     $guzzle->getEmitter()->attach($history);
     $restClient = new RestClient($guzzle);
     $attrs = ['first' => 1, 'second' => 'two'];
     $api = ['authentication' => ['loginRequest' => ['endpoint' => 'login', 'params' => ['par' => ['attr' => 'first']], 'headers' => ['X-Header' => ['attr' => 'second']], 'method' => 'POST'], 'apiRequest' => ['headers' => ['X-Test-Auth' => 'headerToken'], 'query' => ['qToken' => 'queryToken']], 'expires' => ['response' => 'expiresIn', 'relative' => true]]];
     $auth = new Login($attrs, $api);
     $auth->authenticateClient($restClient);
     $request = $restClient->createRequest(['endpoint' => '/']);
     $restClient->download($request);
     $restClient->download($request);
     // test creation of the login request
     self::assertEquals($attrs['second'], $history->getIterator()[0]['request']->getHeader('X-Header'));
     self::assertEquals(json_encode(['par' => $attrs['first']]), (string) $history->getIterator()[0]['request']->getBody());
     // test signature of the api request
     self::assertEquals(1234, $history->getIterator()[1]['request']->getHeader('X-Test-Auth'));
     self::assertEquals('qToken=4321', (string) $history->getIterator()[1]['request']->getQuery());
     self::assertEquals(1234, $history->getIterator()[2]['request']->getHeader('X-Test-Auth'));
     self::assertEquals('qToken=4321', (string) $history->getIterator()[2]['request']->getQuery());
     $expiry = self::getProperty($restClient->getClient()->getEmitter()->listeners('before')[0][0], 'expires');
     self::assertGreaterThan($expires - 2, $expiry);
     self::assertLessThan($expires + 2, $expiry);
 }
开发者ID:keboola,项目名称:generic-extractor,代码行数:30,代码来源:LoginTest.php


注:本文中的GuzzleHttp\Client::setDefaultOption方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。