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


PHP self::getEventDispatcher方法代码示例

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


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

示例1: factory

 public static function factory($config = array())
 {
     // provide a hash of default client configuration options
     $default = array('base_url' => 'http://127.0.0.1/', 'api_id' => 1, 'private_key' => 'fbdce19f94b158e72ae6020cc5126642a9d42d086419c015ad2b6dd429312410');
     // the following values are required when creating the client
     $required = array('base_url', 'api_id', 'private_key');
     // merge in default settings and validate the config
     $config = \Guzzle\Common\Collection::fromConfig($config, $default, $required);
     // create a new client
     $client = new self($config->get('base_url'), $config);
     $client->setDefaultOption('headers/API_ID', $config->get('api_id'));
     $client->getEventDispatcher()->addListener('client.create_request', function (\Guzzle\Common\Event $event) use($config) {
         // Guzzle\Http\Message\Request
         $data = $event['request']->getQuery();
         // Guzzle\Http\Message\EntityEnclosingRequest
         if ($event['request'] instanceof Guzzle\Http\Message\EntityEnclosingRequest) {
             $data->overwriteWith($event['request']->getPostFields());
         }
         $time = (string) time();
         $message = $time . $config->get('api_id') . implode($data->toArray());
         $hash = hash_hmac('sha256', $message, $config->get('private_key'));
         $event['request']->setHeader('API_TIME', $time)->setHeader('API_HASH', $hash);
         unset($data, $time, $message, $hash);
     });
     return $client;
 }
开发者ID:flyingbuddha,项目名称:eyas,代码行数:26,代码来源:TestClient.php

示例2: 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

示例3: factory

 public static function factory($config = array())
 {
     // The following values are required when creating the client
     $required = array('base_url', 'username', 'password');
     // Merge in default settings and validate the config
     $config = Collection::fromConfig($config, array(), $required);
     // Create a new sData client
     $client = new self($config->get('base_url'), $config);
     // JSON by default
     $client->setDefaultOption('query/format', 'json');
     // Authentication
     $client->setDefaultOption('auth', array($config->get('username'), $config->get('password'), 'Basic'));
     // Strip the BOM from results
     $client->addSubscriber(new StripBomPlugin());
     // Optional logging
     if ($config->get('log')) {
         $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) {
             $req = $event['request'];
             \Log::info('sData', ['request' => $req->getMethod() . ' ' . $req->getResource()]);
         });
     }
     // Set the service description
     $services = \Config::get('sdata::services');
     if (!empty($services)) {
         $client->setDescription(ServiceDescription::factory($services));
     }
     // Done
     return $client;
 }
开发者ID:cviebrock,项目名称:sdata-laravel,代码行数:29,代码来源:Sdata.php

示例4: 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

示例5: 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

示例6: factory

 public static function factory($config = array())
 {
     if (isset($config['developer_mode']) && is_bool($config['developer_mode'])) {
         $developerMode = $config['developer_mode'];
     } else {
         $developerMode = false;
     }
     $baseUrl = array('https://api.auspost.com.au', 'https://devcentre.auspost.com.au/myapi');
     // Ignore unnecessary user-specified configuration values
     if ($developerMode) {
         unset($config['email_address']);
         unset($config['password']);
     }
     unset($config['base_url']);
     $default = array('developer_mode' => $developerMode, 'base_url' => $baseUrl[$developerMode], 'email_address' => 'anonymous@auspost.com.au', 'password' => 'password');
     $required = array('developer_mode', 'base_url', 'email_address', "password");
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config);
     $client->getConfig()->setPath('request.options/headers/Authorization', 'Basic ' . base64_encode($config->get('email_address') . ':' . $config->get('password')));
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/service.json'));
     $client->setSslVerification(false);
     $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) {
         $request = $event['request'];
         $request->addCookie('OBBasicAuth', 'fromDialog');
     });
     return $client;
 }
开发者ID:bencorlett,项目名称:auspost-api-php,代码行数:27,代码来源:DeliveryChoiceClient.php

示例7: factory

 /**
  * Factory method to create a new ComputeClient
  *
  * @static
  *
  *
  * @param array|Collection $config Configuration data. Array keys:
  *                                 base_url - Base URL of web service
  *                                 token - Authentication token
  *                                 tenant_id Tenant id
  *
  * @return \Guzzle\Common\FromConfigInterface|ComputeClient|\Guzzle\Service\Client
  */
 public static function factory($config = array())
 {
     $default = array();
     $required = array('base_url', 'token', 'tenant_id');
     $config = Inspector::prepareConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config->get('token'), $config->get('tenant_id'));
     $client->setConfig($config);
     $client->getEventDispatcher()->addSubscriber(new AuthenticationObserver());
     return $client;
 }
开发者ID:shcloudservices,项目名称:guzzle-openstack,代码行数:23,代码来源:ComputeClient.php

示例8: factory

 /**
  * Factory method to create a new MixGuzzleClient
  * The following keys and values are available options:
  * - base_url: base url of the mixpanel web service (optional)
  * - scheme: URI scheme: http or https (optional, defaults to http)
  * - api_key: your Mixpanel api key (required)
  * - api_secret: your Mixpanel api secret (required)
  * - expire: timeout in seconds for all api requests (optional, defaults to 30)
  * @param array $config configuration data
  * @return MixGuzzleClient
  */
 public static function factory($config = array())
 {
     $default = array('base_url' => '{scheme}://mixpanel.com/api/2.0/', 'scheme' => 'http', 'expire' => 30);
     $required = array('api_key', 'api_secret');
     $config = Collection::fromConfig($config, $default, $required);
     $client = new self($config->get('base_url'), $config);
     $auth = new Plugin\MixGuzzleAuthPlugin($config['api_key'], $config['api_secret'], $config['expire']);
     $client->getEventDispatcher()->addSubscriber($auth);
     //attach a service description to the client
     $description = ServiceDescription::factory(__DIR__ . '/service.json');
     $client->setDescription($description);
     return $client;
 }
开发者ID:jlinn,项目名称:mixguzzle,代码行数:24,代码来源:MixGuzzleClient.php

示例9: 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

示例10: factory

 public static function factory($config = array())
 {
     // default config values
     $default = array('base_url' => 'https://localbitcoins.com/api', 'debug' => false);
     $config = Collection::fromConfig($config, $default, array('base_url'));
     $client = new self($config->get('base_url'), $config);
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/Resources/localbtc.json'));
     // optiona debugging
     if ($config->get('debug')) {
         $client->addSubscriber(LogPlugin::getDebugPlugin());
     }
     // oauth2 hook
     $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) use($config) {
         $event['request']->getQuery()->set('access_token', $config['access_token']);
     });
     return $client;
 }
开发者ID:lox,项目名称:localbtc-php,代码行数:17,代码来源:Client.php

示例11: factory

 /**
  * Factory method to create a new Mojio client
  *
  * @param array|Collection $config Configuration data. Array keys:
  *    host - Base URL host.  Default: data.api.hackthedrive.com
  *    base_url - Base URL of web service.  Default: {{scheme}}://{{host}}/{{version}}
  *    app_id - Mojio App ID
  *    secret_key - Mojio App Secret Key
  *    token - Optional Token ID
  *
  * @return S3Client
  */
 public static function factory($config = array())
 {
     $defaults = array('scheme' => 'http', 'host' => 'data.api.hackthedrive.com', 'base_url' => '{scheme}://{host}/{version}', 'oauth_base_url' => '{scheme}://{host}/oauth2', 'app_id' => null, 'secret_key' => null, 'version' => 'v1');
     $required = array('base_url', 'app_id', 'secret_key', 'version', 'oauth_base_url');
     $config = Collection::fromConfig($config, $defaults, $required);
     $client = new self($config->get('base_url'), $config);
     // Attach a service description to the client
     $description = ServiceDescription::factory(__DIR__ . '/service.json');
     $client->setDescription($description);
     $client->getEventDispatcher()->addListener('request.before_send', function (Event $event) {
         $request = $event['request'];
         $token = $request->getClient()->getTokenId();
         if ($token) {
             $request->setHeader('MojioApiToken', $token);
         }
     });
     return $client;
 }
开发者ID:i3-hackathon,项目名称:bmw-php-sdk,代码行数:30,代码来源:Client.php

示例12: factory

 /**
  * @param array $config
  * @return API
  */
 public static function factory($config = array())
 {
     // Provide a hash of default client configuration options
     $default = array('base_url' => 'https://www.eventbrite.com/', 'format' => 'json');
     // The following values are required when creating the client
     $required = array('base_url', 'format', 'app_key');
     // Merge in default settings and validate the config
     $config = Collection::fromConfig($config, $default, $required);
     // Create a new client
     $client = new self($config->get('base_url') . $config->get('format') . '/', $config);
     // Set the service description
     $client->setDescription(ServiceDescription::factory(__DIR__ . '/eventbrite.json'));
     // Add a listener so that we append our API key to all requests
     $client->getEventDispatcher()->addListener('client.create_request', function (Event $e) {
         $e['request']->getQuery()->set('app_key', $e['client']->getConfig('app_key'));
     });
     return $client;
 }
开发者ID:undernewmanagement,项目名称:eventbrite-php5,代码行数:22,代码来源:API.php

示例13: factory

 public static function factory($config = array())
 {
     $default = array('ssl' => false, 'tid' => null);
     $required = array('ssl');
     $config = Collection::fromConfig($config, $default, $required);
     $baseUrl = $config->get('ssl') === true ? 'https://ssl.google-analytics.com' : 'http://www.google-analytics.com';
     $client = new self($baseUrl, $config);
     $description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
     $client->setDescription($description);
     if (true === isset($config['tid'])) {
         $client->getEventDispatcher()->addListener('command.before_prepare', function (\Guzzle\Common\Event $e) use($config) {
             if (false === $e['command']->hasKey('tid')) {
                 $e['command']->set('tid', $config['tid']);
             }
         });
     }
     return $client;
 }
开发者ID:jordi12100,项目名称:php-ga-measurement-protocol,代码行数:18,代码来源:MeasurementProtocolClient.php

示例14: factory

 public static function factory($opts = array())
 {
     $default = array('sandbox' => true, 'xsd' => true);
     $required = array('sandbox', 'user', 'pass');
     $config = Collection::fromConfig($opts, $default, $required);
     if ($config->get('xsd') === true) {
         $config->set('xsd', file_get_contents(__DIR__ . '/Resources/schema.xsd'));
     }
     if ($config->get('sandbox') === true) {
         $baseUrl = 'https://exttest.cybertip.org/ispws/';
     } else {
         $baseUrl = 'https://report.cybertip.org/ispws/.';
     }
     $client = new self($baseUrl, $config);
     $client->setDefaultOption('auth', array($config['user'], $config['pass'], 'Any'));
     $client->getConfig()->set('curl.options', array('body_as_string' => true));
     $description = ServiceDescription::factory(__DIR__ . '/Resources/service.php');
     $client->setDescription($description);
     $client->getEventDispatcher()->addListener('command.after_prepare', array($client, 'onCommandAfterPrepare'));
     return $client;
 }
开发者ID:jbboehr,项目名称:cybertip,代码行数:21,代码来源:CybertipClient.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::getEventDispatcher方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。