当前位置: 首页>>代码示例>>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;未经允许,请勿转载。