當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。