本文整理汇总了PHP中Guzzle\Http\Client::addSubscriber方法的典型用法代码示例。如果您正苦于以下问题:PHP Client::addSubscriber方法的具体用法?PHP Client::addSubscriber怎么用?PHP Client::addSubscriber使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Guzzle\Http\Client
的用法示例。
在下文中一共展示了Client::addSubscriber方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: __construct
/**
* Build a new FactoryDriver
*
* @param Container $app
*/
public function __construct(Container $app)
{
$this->app = $app;
$this->client = new \Guzzle\Http\Client();
$cookiePlugin = new CookiePlugin(new ArrayCookieJar());
$this->client->addSubscriber($cookiePlugin);
}
示例2: setUp
protected function setUp()
{
$this->httpClient = new HttpClient('http://localhost');
$this->clientMocker = new MockPlugin();
$this->httpClient->addSubscriber($this->clientMocker);
$this->engineClient = new EngineClient($this->httpClient, array('collection_name' => 'widgets'));
}
示例3: setGuzzle
/**
* @param \Guzzle\Http\Client $guzzle
* @return void
*/
public function setGuzzle(Client $guzzle)
{
$this->guzzle = $guzzle;
$this->guzzle->setSslVerification(false, false);
$this->guzzle->setUserAgent('User-Agent: Mozilla/5.0 (Linux; U; Android 4.3; EN; C6502 Build/10.4.1.B.0.101) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30 PlayStation App/1.60.5/EN/EN');
$this->guzzle->addSubscriber(new CookiePlugin(new ArrayCookieJar()));
}
示例4: __construct
/**
* GuzzleHandler constructor.
*
* @param ConfigFacade|ConfigInterface $pConfig
* @param InternalFactory $pFactory
*/
public function __construct(ConfigInterface $pConfig, InternalFactory $pFactory)
{
$this->_config = $pConfig;
$this->_factory = $pFactory;
$this->_client = $this->_factory->getGuzzleFactory()->getHttpClientObject($this->_configurationOptions());
$this->_client->addSubscriber($this->_factory->getGuzzleFactory()->getCookiePlugin());
}
示例5: setUp
public function setUp()
{
// create client
$this->_client = new \Guzzle\Http\Client('http://www.bing.com/');
// add request sign plugin
$this->_client->addSubscriber(new \Sokil\Guzzle\Plugin\RequestSign(array('key' => 'Shared secret key used for generating the HMAC variant of the message digest', 'additionalParams' => array('akey' => 'avalue'))));
}
示例6: getHttpClient
/**
*
* @return \Guzzle\Http\Client
*/
protected function getHttpClient()
{
if (is_null($this->httpClient)) {
$this->httpClient = new HttpClient();
$this->httpClient->addSubscriber(new \Guzzle\Plugin\History\HistoryPlugin());
}
return $this->httpClient;
}
示例7: __construct
public function __construct()
{
$this->guzzleClient = new Client();
$this->logger = LogFactory::getLogger(get_class($this));
if (!$this->logger instanceof NullLogger) {
$logPlugin = new LogPlugin(new GuzzleLogAdapter(), MessageFormatter::DEFAULT_FORMAT);
$this->guzzleClient->addSubscriber($logPlugin);
}
}
示例8: getClient
/**
* @return \Guzzle\Http\Client
*/
protected function getClient()
{
if (is_null($this->client)) {
$cookiePlugin = new CookiePlugin(new ArrayCookieJar());
$this->client = new Client($this->parameters['base_url']);
$this->client->addSubscriber($cookiePlugin);
}
return $this->client;
}
示例9: testRegisterPlugin
public function testRegisterPlugin()
{
$client = new Client('http://example.com');
$client->addSubscriber($this->getPlugin());
$mock = new MockPlugin();
$mock->addResponse(new Response(200));
$client->addSubscriber($mock);
$request = $client->get('/resource/1');
$request->send();
$authorization = (string) $request->getHeader('Authorization');
$this->assertRegExp('@Acquia 1:([a-zA-Z0-9+/]+={0,2})$@', $authorization);
}
示例10: setCredentials
/**
* Set the consumer_key and consumer_secret for this instance.
*
* @param string $consumer_key The consumer_key of the twitter account.
* @param string $consumer_secret The consumer_secret for the twitter account.
* @param string $access_token_key The OAuth access token key value
* @param string $access_token_secret The OAuth access token's secret
*/
public function setCredentials($consumer_key, $consumer_secret, $access_token_key = null, $access_token_secret = null)
{
$this->setConsumerKey($consumer_key);
$this->setConsumerSecret($consumer_secret);
$this->setAccessTokenKey($access_token_key);
$this->setAccessTokenSecret($access_token_secret);
$this->oauth_consumer = null;
if (!is_null($consumer_key) && !is_null($consumer_secret) && !is_null($access_token_key) && !is_null($access_token_secret)) {
$oauth = new OauthPlugin(array('consumer_key' => $consumer_key, 'consumer_secret' => $consumer_secret, 'token' => $access_token_key, 'token_secret' => $access_token_secret));
$this->http_client->addSubscriber($oauth);
}
}
示例11: getOAuthConnection
/**
* @param string $token
* @param string $secret
* @return Client
*/
public function getOAuthConnection($token = null, $secret = null)
{
$client = new Client('https://api.twitter.com');
$params = array('consumer_key' => $this->key, 'consumer_secret' => $this->secret);
if ($token !== null && $secret !== null) {
$params['token'] = $token;
$params['token_secret'] = $secret;
}
$oauth = new OauthPlugin($params);
$client->addSubscriber($oauth);
if (null !== $this->logger) {
$client->addSubscriber(new LogPlugin(new PsrLogAdapter($this->logger)));
}
return $client;
}
示例12: create
public static function create($host, $ssl, $clientID, $apiKey)
{
$guzzle = new GuzzleHttpClient(($ssl ? 'https' : 'http') . '://' . $host . '/');
$signer = new RequestSigner($clientID, $apiKey);
$guzzle->addSubscriber($signer);
return new static($guzzle);
}
示例13: connect
public function connect($errors = 0)
{
$client = new Client(null);
if (!file_exists($this->_cookieFile)) {
file_put_contents($this->_cookieFile, "");
}
$cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
$client->addSubscriber($cookiePlugin);
$client->setUserAgent('User-Agent', 'Mozilla/5.0 (Linux; U; Android 4.2.2; de-de; GT-I9195 Build/JDQ39) AppleWebKit/534.30 (KHTML, like Gecko) Version/4.0 Mobile Safari/534.30');
$this->_client = $client;
try {
$url = $this->getLoginUrl();
$this->loginAndGetCode($url);
$this->enterAnswer();
$this->gatewayMe();
$this->auth();
$this->getSid();
$this->utasRefreshNucId();
$this->auth();
$this->utasAuth();
$this->utasQuestion();
} catch (\Exception $e) {
throw $e;
// server down, gotta retry
if ($errors < static::RETRY_ON_SERVER_DOWN && preg_match("/service unavailable/mi", $e->getMessage())) {
$this->connect(++$errors);
} else {
throw new \Exception('Could not connect to the mobile endpoint.');
}
}
return array("nucleusId" => $this->nucId, "userAccounts" => $this->accounts, "sessionId" => $this->sid, "phishingToken" => $this->phishingToken, "platform" => $this->_loginDetails['platform']);
}
示例14: connect
public function connect($appKey, $appSecret, $accessToken, $tokenSecret)
{
try {
$client = new Client(self::BASE_URL . '/{version}', ['version' => '1.1']);
$oauth = new OauthPlugin(['consumer_key' => $appKey, 'consumer_secret' => $appSecret, 'token' => $accessToken, 'token_secret' => $tokenSecret]);
return $client->addSubscriber($oauth);
} catch (ClientErrorResponseException $e) {
$req = $e->getRequest();
$resp = $e->getResponse();
print_r($resp);
die('1');
} catch (ServerErrorResponseException $e) {
$req = $e->getRequest();
$resp = $e->getResponse();
die('2');
} catch (BadResponseException $e) {
$req = $e->getRequest();
$resp = $e->getResponse();
print_r($resp);
die('3');
} catch (Exception $e) {
echo 'AGH!';
die('4');
}
}
示例15: Connect
public function Connect()
{
$client = new Client(null);
if (!file_exists($this->_cookieFile)) {
file_put_contents($this->_cookieFile, "");
}
$cookiePlugin = new CookiePlugin(new FileCookieJar($this->_cookieFile));
$client->addSubscriber($cookiePlugin);
$client->setUserAgent("Mozilla/5.0 (Windows NT 6.2; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/29.0.1547.62 Safari/537.36");
$this->_client = $client;
$login_url = $this->GetMainPage($this->urls['main']);
$this->Login($login_url);
$nucleusId = $this->GetNucleusId($this->urls['nucleus']);
$this->GetShards($nucleusId, $this->urls['shards']);
$userAccounts = $this->GetUserAccounts($nucleusId, $this->urls['userinfo']);
$sessionId = $this->GetSessionId($nucleusId, $userAccounts, $this->urls['session']);
$phishing = $this->Phishing($nucleusId, $sessionId, $this->urls['phishing']);
if (isset($phishing['debug']) && $phishing['debug'] == "Already answered question.") {
$phishingToken = $phishing['token'];
} else {
$phishingToken = $this->Validate($nucleusId, $sessionId, $this->urls['validate']);
}
$this->_loginResponse = array("nucleusId" => $nucleusId, "userAccounts" => $userAccounts, "sessionId" => $sessionId, "phishingToken" => $phishingToken, "platform" => $this->_loginDetails['platform']);
return $this->_loginResponse;
}