本文整理匯總了PHP中Buzz\Browser::addListener方法的典型用法代碼示例。如果您正苦於以下問題:PHP Browser::addListener方法的具體用法?PHP Browser::addListener怎麽用?PHP Browser::addListener使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Buzz\Browser
的用法示例。
在下文中一共展示了Browser::addListener方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: BasicAuthListener
/**
* @param Logger $logger
* @param $client
* @param $method
* @param $host
* @param $resource
* @param string|null $login
* @param string|null $password
* @param bool|false $useCookie
*/
function __construct(Logger $logger, $client, $method, $host, $resource, $login = null, $password = null, $useCookie = false)
{
$this->logger = $logger;
$this->client = $client;
$this->method = $method;
$this->host = $host;
$this->resource = $resource;
$this->login = $login;
$this->password = $password;
$this->useCookie = $useCookie;
$this->client->getClient()->setOption(CURLINFO_HEADER_OUT, true);
if ($this->login) {
$listener = new BasicAuthListener($this->login, $this->password);
if (!$this->hasListener($this->client, $listener)) {
$this->logger->addDebug('BasicAuthListener: ' . $this->login . ' ' . substr($this->password, 3, 7));
$this->client->addListener($listener);
}
}
if ($this->useCookie) {
$listener = new \Avtonom\WebGateBundle\Listener\CookieListener();
if (!$this->hasListener($this->client, $listener)) {
$this->logger->addDebug('CookieListener');
$this->client->addListener($listener);
}
}
}
示例2: __construct
/**
* @param string $accessToken
* @param Browser $browser (optional)
* @param ListenerInterface $listener (optional)
* @param ExceptionInterface $exception (optional)
*/
public function __construct($accessToken, Browser $browser = null, ListenerInterface $listener = null, ExceptionInterface $exception = null)
{
$curl = new Curl();
$curl->setTimeout(10);
// 10 seconds
$this->browser = $browser ?: new Browser($curl);
$this->browser->addListener($listener ?: new BuzzOAuthListener($accessToken));
$this->exception = $exception;
}
示例3: __construct
public function __construct(Browser $browser, $clientId, $clientSecret, $accessToken = null)
{
$this->browser = $browser;
$this->clientId = $clientId;
$this->clientSecret = $clientSecret;
// todo retrieve accessToken from cache
if ($accessToken === null) {
$accessToken = $this->getAccessToken();
}
$this->browser->addListener(new BearerAuthListener($accessToken));
}
示例4: __construct
/**
* Instantiated a new http client
*
* @param array $options Http client options
* @param null|Browser $browser Buzz client
*/
public function __construct(array $options = array(), Browser $browser = null)
{
$this->options = array_merge($this->options, $options);
$this->browser = $browser ?: new Browser(new Curl());
$this->browser->getClient()->setTimeout($this->options['timeout']);
$this->browser->getClient()->setVerifyPeer(false);
if (null !== $this->options['login'] || null !== $this->options['token']) {
if (null !== $this->options['token']) {
$options = array($this->options['token']);
} else {
$options = array($this->options['login'], $this->options['password']);
}
$this->browser->addListener(new AuthListener($this->options['auth_method'], $options));
}
}
示例5: __construct
/**
* Tapfiliate constructor.
*
* @param string $key
*/
public function __construct($key)
{
Assertion::string($key);
// @see https://github.com/kriswallsmith/Buzz/pull/186
$listener = new Buzz\Listener\CallbackListener(function (Buzz\Message\RequestInterface $request, $response = null) use($key) {
if ($response) {
// postSend
} else {
// preSend
$request->addHeader(sprintf('Api-Key: %s', $key));
}
});
$this->browser = new Buzz\Browser(new Buzz\Client\Curl());
$this->browser->addListener($listener);
}
示例6: createBrowser
protected function createBrowser($user = null, $password = null)
{
$browser = new Buzz\Browser();
if ($user) {
$browser->addListener(new Buzz\Listener\BasicAuthListener($user, $password));
}
return $browser;
}
示例7: fetch
/**
* Fetch from the API
* @param string $endpoint Fetch from the endpoint
* @param array $params Any parameters
* @return \stdClass|\stdClass[]
*/
public static function fetch($endpoint, array $params = [])
{
$client = self::getClient();
$browser = new Browser($client);
$method = Request::METHOD_GET;
foreach (self::$postEndpoints as $check) {
if (preg_match("/^{$check}\$/", $endpoint)) {
$method = Request::METHOD_POST;
}
}
$request = new FormRequest($method, $endpoint, self::BASE_URL);
$request->setFields($params);
$response = new Response();
$listener = new JsonListener();
$browser->addListener($listener);
$response = $browser->send($request, $response);
return $response->getContent();
}
示例8: doSend
/**
* Does the actual sending
*
* @param \RMS\PushNotificationsBundle\Message\BlackberryMessage $message
* @return bool
*/
protected function doSend(BlackberryMessage $message)
{
$separator = "mPsbVQo0a68eIL3OAxnm";
$body = $this->constructMessageBody($message, $separator);
$browser = new Browser(new Curl());
$listener = new BasicAuthListener($this->appID, $this->password);
$browser->addListener($listener);
$url = "https://pushapi.na.blackberry.com/mss/PD_pushRequest";
if ($this->evaluation) {
$url = "https://pushapi.eval.blackberry.com/mss/PD_pushRequest";
}
$headers = array();
$headers[] = "Content-Type: multipart/related; boundary={$separator}; type=application/xml";
$headers[] = "Accept: text/html, *";
$headers[] = "Connection: Keep-Alive";
$response = $browser->post($url, $headers, $body);
return $this->parseResponse($response);
}
示例9: Curl
<?php
require '../vendor/autoload.php';
use Buzz\Browser;
use Buzz\Client\Curl;
use Buzz\Listener\DigestAuthListener;
$username = 'user1';
$password = 'user1';
//
// This URL will Authenticate usernames user1 through user9, password is the same as the username.
//
$url = 'http://test.webdav.org/auth-digest/';
// Create Curl Client
$curl = new Curl();
$browser = new Browser();
$browser->setClient($curl);
// Create DigestAuthListener
$browser->addListener(new DigestAuthListener($username, $password));
//
// This URL will Authenticate any username and password that matches those in the URL.
// It requires the Browser/Client to respond with the same Cookie in order to Authenticate.
//
// $url = 'http://httpbin.org/digest-auth/auth-int/' . $username . '/' . $password;
$response = $browser->get($url);
echo $response;
$statusCode = $response->getStatusCode();
if ($statusCode == 401) {
$response = $browser->get($url);
}
echo $response;
示例10: initContaoRequest
/**
*
* This code is copied from Ctsmedia\Phpbb\BridgeBundle\PhpBB\Connector
* @return Browser
*/
protected function initContaoRequest()
{
// Init Request
$client = new Curl();
$client->setMaxRedirects(0);
$browser = new Browser();
$browser->setClient($client);
$cookieListener = new CookieListener();
$browser->addListener($cookieListener);
return $browser;
}
示例11: initForumRequest
/**
* @return Browser
*/
protected function initForumRequest($force = false)
{
// Init Request
$client = new Curl();
$client->setMaxRedirects(0);
$browser = new Browser();
$browser->setClient($client);
$cookieListener = new CookieListener();
$browser->addListener($cookieListener);
// We need to make sure that the if the original Request is already coming from the forum, we then are not
// allowed to send a request to the forum so we create a login loop for example.
if ($force === false && System::getContainer()->get('request_stack')->getCurrentRequest() && System::getContainer()->get('request_stack')->getCurrentRequest()->headers->get('x-requested-with') == 'ContaoPhpbbBridge') {
System::log('Bridge Request Recursion detected', __METHOD__, TL_ERROR);
throw new TooManyRequestsHttpException(null, 'Internal recursion Bridge requests detected');
}
return $browser;
}
示例12: __construct
/**
* Constructor
*
* @param string $token Access Token
* @param Browser|null $browser (optional) Browser Instance
*/
public function __construct($token, Browser $browser = null)
{
$this->browser = $browser ?: new Browser(function_exists('curl_exec') ? new Curl() : new FileGetContents());
$this->browser->addListener(new BuzzAsaasAuthListener($token));
}
示例13: __construct
/**
* @param string $accessToken
* @param Browser $browser (optional)
* @param ListenerInterface $listener (optional)
* @param ExceptionInterface $exception (optional)
*/
public function __construct($accessToken, Browser $browser = null, ListenerInterface $listener = null, ExceptionInterface $exception = null)
{
$this->browser = $browser ?: new Browser(new Curl());
$this->browser->addListener($listener ?: new BuzzOAuthListener($accessToken));
$this->exception = $exception;
}
示例14: Browser
<?php
require '../vendor/autoload.php';
use Buzz\Browser;
use Buzz\Client\Curl;
use Buzz\Listener\CookieListener;
$browser = new Browser();
$client = new Curl();
$client->setMaxRedirects(0);
$browser->setClient($client);
// Create CookieListener
$listener = new CookieListener();
$browser->addListener($listener);
// This URL set two Cookies, k1=v1 and k2=v2
$response = $browser->get('http://httpbin.org/cookies/set?k1=v1&k2=v2');
// This URL will return the two set Cookies
$response = $browser->get('http://httpbin.org/cookies');
echo $response;
// Should output
/*
{
"cookies": {
"k1": "v1",
"k2": "v2"
}
}
*/
// The Cookies are able to be retrieved and set using getCookies and setCookies on the Listener.
print_r($listener->getCookies());
示例15: getHTTPClientInstance
/**
* Creates the HTTP abstraction object hierarchy.
* For this purpose we use an external library called "Buzz".
*
* For $instanceConfig documentation see self::getDataService.
*
* @param array $instanceConfig
* @return Browser
*/
protected static function getHTTPClientInstance(array $instanceConfig)
{
$username = isset($instanceConfig['Instance']['user']) === true ? $instanceConfig['Instance']['user'] : '';
$password = isset($instanceConfig['Instance']['pass']) === true ? $instanceConfig['Instance']['pass'] : '';
// Bootstrap the REST client
$curlClient = new Curl();
$curlClient->setVerifyPeer(false);
$restClient = new Browser($curlClient);
if ($username && $password) {
$authListener = new BasicAuthListener($username, $password);
$restClient->addListener($authListener);
}
return $restClient;
}