當前位置: 首頁>>代碼示例>>PHP>>正文


PHP self::setUserAgent方法代碼示例

本文整理匯總了PHP中self::setUserAgent方法的典型用法代碼示例。如果您正苦於以下問題:PHP self::setUserAgent方法的具體用法?PHP self::setUserAgent怎麽用?PHP self::setUserAgent使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在self的用法示例。


在下文中一共展示了self::setUserAgent方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: factory

 /**
  * @param array $config
  * @return \Guzzle\Service\Client|BasecampClient
  * @throws \Guzzle\Common\Exception\InvalidArgumentException
  */
 public static function factory($config = array())
 {
     $default = array('base_url' => 'https://basecamp.com/{user_id}/api/{version}/', 'version' => 'v1', 'auth' => 'http', 'token' => null, 'username' => null, 'password' => null);
     $required = array('user_id', 'app_name', 'app_contact');
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config);
     if ($config['auth'] === 'http') {
         if (!isset($config['username'], $config['password'])) {
             throw new InvalidArgumentException("Config must contain username and password when using http auth");
         }
         $authorization = 'Basic ' . base64_encode($config['username'] . ':' . $config['password']);
     }
     if ($config['auth'] === 'oauth') {
         if (!isset($config['token'])) {
             throw new InvalidArgumentException("Config must contain token when using oauth");
         }
         $authorization = sprintf('Bearer %s', $config['token']);
     }
     if (!isset($authorization)) {
         throw new InvalidArgumentException("Config must contain valid authentication method");
     }
     // Attach a service description to the client
     $description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
     $client->setDescription($description);
     // Set required User-Agent
     $client->setUserAgent(sprintf('%s (%s)', $config['app_name'], $config['app_contact']));
     $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
         $event['request']->addHeader('Authorization', $authorization);
     });
     return $client;
 }
開發者ID:netvlies,項目名稱:basecamp-php,代碼行數:36,代碼來源:BasecampClient.php

示例2: factory

 /**
  * @param array $config
  * @return \Guzzle\Service\Client|ImageRelayClient
  * @throws \Guzzle\Common\Exception\InvalidArgumentException
  */
 public static function factory($config = array())
 {
     $default = array('base_url' => 'https://{imagerelay_url}/api/v2/', 'imagerelay_url' => 'subdomain.imagerelay.com');
     $config = Collection::fromConfig($config, $default);
     $client = new self($config->get('base_url'), $config);
     if ($config['auth'] === 'http') {
         if (!isset($config['username'], $config['password'])) {
             throw new InvalidArgumentException("Username and password required when using http auth.");
         }
         $authorization = 'Basic ' . base64_encode($config['username'] . ':' . $config['password']);
     }
     if ($config['auth'] === 'oauth') {
         if (!isset($config['token'])) {
             throw new InvalidArgumentException("Access token required when using oauth.");
         }
         $authorization = sprintf('Bearer %s', $config['token']);
     }
     if (!isset($authorization)) {
         throw new InvalidArgumentException("Must use either http or oauth authentication method.");
     }
     // Attach a service description to the client
     $description = ServiceDescription::factory(__DIR__ . '/Resources/api.php');
     $client->setDescription($description);
     // Set required User-Agent
     $client->setUserAgent(sprintf('%s (%s)', $config['app_name'], $config['app_contact']));
     $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
         $event['request']->addHeader('Authorization', $authorization);
     });
     return $client;
 }
開發者ID:imagerelay,項目名稱:imagerelay-php,代碼行數:35,代碼來源:ImageRelayClient.php

示例3: factory

 /**
  * @param array $config
  * @return \Guzzle\Service\Client|BasecampClient
  * @throws \Guzzle\Common\Exception\InvalidArgumentException
  */
 public static function factory($config = array())
 {
     $default = array('base_url' => 'https://basecamp.com/', 'version' => 'v1', 'token' => null, 'user_agent' => null, 'auth_method' => 'oauth');
     $required = [];
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config);
     if (empty($config['token'])) {
         throw new InvalidArgumentException("Config must contain token when using oath");
     }
     $authorization = sprintf('Bearer %s', $config['token']);
     if (!isset($authorization)) {
         throw new InvalidArgumentException("Config must contain valid authentication method");
     }
     // Attach a service description to the client
     $description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
     $client->setDescription($description);
     // Set required User-Agent
     $client->setUserAgent($config['user_agent']);
     $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($authorization) {
         $event['request']->addHeader('Authorization', $authorization);
     });
     // Add cache plugin
     $cachePlugin = new CachePlugin(['storage' => new DefaultCacheStorage(new DoctrineCacheAdapter(new ApcCache()))]);
     $client->addSubscriber($cachePlugin);
     return $client;
 }
開發者ID:bigset1,項目名稱:blueridge,代碼行數:31,代碼來源:BasecampClient.php

示例4: factory

 /**
  * Factory method to create the client, add the service description, and set
  * the user again
  *
  * @param array $config
  *
  * @return Client
  */
 public static function factory($config = array())
 {
     $client = new self();
     $description = ServiceDescription::factory(__DIR__ . '/Config/endpoints.json');
     $client->setDescription($description);
     $client->setUserAgent('Shelf/' . Version::VERSION, true);
     return $client;
 }
開發者ID:janiv,項目名稱:shelf,代碼行數:16,代碼來源:Client.php

示例5: factory

 /**
  * Creates a basic auth client with the supplied configuration options
  *
  * @param array $config
  * @return Client|IntercomBasicAuthClient
  */
 public static function factory($config = [])
 {
     $client = new self();
     $config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
     $client->configure($config);
     $client->setBasicAuth($config->get('app_id'), $config->get('api_key'));
     $client->setUserAgent('intercom-php/1.2.3', true);
     return $client;
 }
開發者ID:AntoineLemaire,項目名稱:intercom-php,代碼行數:15,代碼來源:IntercomBasicAuthClient.php

示例6: factory

 /**
  * Creates a basic auth client with the supplied configuration options
  *
  * @param array $config
  * @return Client|TestFairyBasicAuthClient
  */
 public static function factory($config = array())
 {
     $client = new self();
     $config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
     $client->configure($config);
     $client->setBasicAuth($config->get('email'), $config->get('api_key'));
     $client->setUserAgent('testfairy-php/1.0.0', true);
     return $client;
 }
開發者ID:angmarian,項目名稱:testfairy-php-api,代碼行數:15,代碼來源:TestFairyBasicAuthClient.php

示例7: factory

 /**
  * Creates a client token auth client with the supplied configuration options
  *
  * @param array $config
  * @return Client|IntercomBasicAuthClient
  */
 public static function factory($config = array())
 {
     $client = new self();
     $config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
     $client->configure($config);
     $client->setBasicAuth($config->get('client_uuid'), $config->get('client_key'));
     $client->setUserAgent('intercom-php/1.4.0', true);
     $client->setDefaultOption('query/app_id', $config->get('app_id'));
     return $client;
 }
開發者ID:scup,項目名稱:intercom-php,代碼行數:16,代碼來源:IntercomClientTokenAuthClient.php

示例8: factory

 /**
  * {@inheritDoc}
  */
 public static function factory($config = array())
 {
     $defaultOptions = array('base_url' => '{scheme}://{hostname}', 'hostname' => 'api.mgrt.net', 'scheme' => 'https');
     $requiredOptions = array('public_key', 'private_key');
     $config = Collection::fromConfig($config, $defaultOptions, $requiredOptions);
     $description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
     $client = new self($config->get('base_url'), $config);
     $client->setDefaultOption('auth', array($config['public_key'], $config['private_key'], 'Basic'));
     $client->setDescription($description);
     $client->setUserAgent(sprintf('mgrt-php/%s guzzle/%s PHP/%s', \Mgrt\Version::VERSION, \Guzzle\Common\Version::VERSION, PHP_VERSION));
     return $client;
 }
開發者ID:mgrt,項目名稱:mgrt-php,代碼行數:15,代碼來源:Client.php

示例9: factory

 /**
  * Factory method to create a new MediawikiApiClient
  *
  * @param array|Collection $config Configuration data. Array keys:
  *    base_url - Base URL of web service
  *
  * @throws InvalidArgumentException
  * @return MediawikiApiClient
  */
 public static function factory($config = array())
 {
     $required = array('base_url');
     $config = Collection::fromConfig($config, array(), $required);
     $client = new self($config->get('base_url'));
     $cookiePlugin = new CookiePlugin(new ArrayCookieJar());
     $client->addSubscriber($cookiePlugin);
     $client->setConfig($config);
     $client->setUserAgent('addwiki-guzzle-mediawiki-client');
     $client->setDescription(ServiceDescription::factory(dirname(__DIR__) . DIRECTORY_SEPARATOR . 'data' . DIRECTORY_SEPARATOR . 'mediawiki.json'));
     return $client;
 }
開發者ID:addshore,項目名稱:guzzle-mediawiki-client,代碼行數:21,代碼來源:MediawikiApiClient.php

示例10: factory

 /**
  * Factory method to create a new Swagger Docs client.
  * @param array|Collection $config Configuration data
  * @return SwaggerClient
  */
 public static function factory($config = array())
 {
     // no default base url, but must be passed
     $default = array();
     $required = array('base_url');
     // Merge in default settings and validate the config
     $config = Collection::fromConfig($config, $default, $required);
     // Create a new instance of self
     $client = new self($config->get('base_url'), $config);
     // describe service from JSON file.
     $service = ServiceDescription::factory(__DIR__ . '/Resources/service.json');
     // Prefix Loco identifier to user agent string
     $client->setUserAgent($service->getName() . '/' . $service->getApiVersion(), true);
     return $client->setDescription($service);
 }
開發者ID:rodsouto,項目名稱:swizzle,代碼行數:20,代碼來源:SwaggerClient.php

示例11: factory

 /**
  * @param array $config
  * @return SistrixClient
  * @throws \Guzzle\Common\Exception\InvalidArgumentException
  */
 public static function factory($config = array())
 {
     $default = array('base_url' => 'http://api.sistrix.net/', 'format' => 'json');
     $required = array('api_key');
     foreach ($required as $value) {
         if (empty($config[$value])) {
             throw new InvalidArgumentException("Argument '{$value}' must not be blank.");
         }
     }
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config);
     $client->setDefaultOption('query', array('api_key' => $config->get('api_key'), 'format' => $config->get('format')));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/ServiceDescriptionSistrix.json'));
     $client->setUserAgent('OnlineMarketingApiToolkit');
     return $client;
 }
開發者ID:LukasGrebe,項目名稱:online-marketing-api-toolkit,代碼行數:21,代碼來源:SistrixClient.php

示例12: factory

 public static function factory($config = [])
 {
     $client = new self();
     $config = Collection::fromConfig($config, $client->getDefaultConfig(), static::$required);
     $client->configure($config);
     $client->setUserAgent(self::USER_AGENT, true);
     self::$consumer_key = $config->get('consumer_key');
     self::$consumer_secret = $config->get('consumer_secret');
     self::$application_name = $config->get('application_name');
     // add a listener to alter every requests and authenticate them through Semantria weird oAuth
     $client->getEventDispatcher()->addListener('command.before_send', function (Event $event) use($client) {
         $command = $event['command'];
         $request = $client->oAuthRequest($command->getRequest());
     });
     return $client;
 }
開發者ID:wisembly,項目名稱:semantria-php,代碼行數:16,代碼來源:SemantriaAuthClient.php

示例13: factory

 /**
  * @param array $config
  * @return MozClient
  * @throws \Guzzle\Common\Exception\InvalidArgumentException
  */
 public static function factory($config = array())
 {
     $default = array('base_url' => 'http://lsapi.seomoz.com', 'expiresSeconds' => '3600');
     $required = array('AccessID', 'SecretKey');
     foreach ($required as $value) {
         if (empty($config[$value])) {
             throw new InvalidArgumentException("Argument '{$value}' must not be blank.");
         }
     }
     $config = Collection::fromConfig($config, $default, $required);
     $credentials = self::calculateCredentials($config->get('AccessID'), $config->get('SecretKey'), $config->get('expiresInterval'));
     $client = new self($config->get('base_url'), $config);
     $client->setDefaultOption('query', array('AccessID' => $config->get('AccessID'), 'Expires' => $credentials['expires'], 'Signature' => $credentials['signature']));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/ServiceDescriptionMoz.json'));
     $client->setUserAgent('OnlineMarketingApiToolkit');
     return $client;
 }
開發者ID:LukasGrebe,項目名稱:online-marketing-api-toolkit,代碼行數:22,代碼來源:MozClient.php

示例14: factory

 /**
  * @param array $config
  * @return SeokicksClient
  * @throws \Guzzle\Common\Exception\InvalidArgumentException
  */
 public static function factory($config = array())
 {
     $default = array("base_url" => "http://www.seokicks.de/SEOkicksService/V1/");
     $required = array('appid');
     foreach ($required as $value) {
         if (empty($config[$value])) {
             throw new InvalidArgumentException("Argument '{$value}' must not be blank.");
         }
     }
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config);
     $client->setDefaultOption('query', array('appid' => $config['appid']));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/ServiceDescriptionSeokicks.json'));
     $client->setUserAgent('OnlineMarketingApiToolkit');
     /*
      * Seokicks send javascript and not json as response
      */
     $plugin = new ForceContenttypePlugin();
     $client->addSubscriber($plugin);
     return $client;
 }
開發者ID:LukasGrebe,項目名稱:online-marketing-api-toolkit,代碼行數:26,代碼來源:SeokicksClient.php

示例15: factory

 /**
  * {@inheritDoc}
  */
 public static function factory($config = array())
 {
     $defaults = array('base_url' => 'https://www.mtxserv.fr/api/{version}/', 'version' => 'v1', 'grant_type' => 'https://www.mtxserv.fr/grants/api_key', 'has_authentification' => true, 'oauth2_token' => 'https://www.mtxserv.fr/oauth/v2/token');
     $required = array('client_id', 'client_secret', 'api_key');
     $config = Collection::fromConfig($config, $defaults, $required);
     $client = new self($config->get('base_url'), $config);
     // Set services descriptions
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/product.php'));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/admin.php'));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/viewer.php'));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/game.php'));
     // Add authentification
     if ($config->get('has_authentification')) {
         $client->getEventDispatcher()->addListener('request.before_send', function (\Guzzle\Common\Event $event) use($config) {
             $event['request']->getQuery()->set('access_token', Client::retrieveAccessToken($config));
         });
     }
     // Set user agent
     $client->setUserAgent('mTxServ SDK PHP');
     return $client;
 }
開發者ID:mtxserv,項目名稱:mtxserv-php,代碼行數:24,代碼來源:Client.php


注:本文中的self::setUserAgent方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。