本文整理汇总了PHP中Buzz\Message\Request类的典型用法代码示例。如果您正苦于以下问题:PHP Request类的具体用法?PHP Request怎么用?PHP Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: bind
/**
* @param \Buzz\Message\Request $request
* @param object $tracking
*/
public function bind(Request $request, $tracking)
{
$number = $tracking->getNumber();
$trackingData = [];
$trackingData = ['tracking_number' => $number];
if ($courier = $tracking->getCourier()) {
$trackingData['slug'] = $courier;
}
if ($orderId = $tracking->getOrderId()) {
$trackingData['order_id'] = $orderId;
}
if ($orderUrl = $tracking->getOrderUrl()) {
$trackingData['order_id_path'] = $orderUrl;
}
if ($meta = $tracking->getMeta()) {
$customFields = [];
foreach ($meta as $key => $value) {
$customFields[$key] = $value;
}
$trackingData['custom_fields'] = $customFields;
}
$content = ['tracking' => $trackingData];
$content = $this->encodeContent($content);
$request->setContent($content);
}
示例2: bindCollection
/**
* @param Buzz\Message\Request $request
* @param Doctrine\Common\Collections\Collection $collection
* @throws AntiMattr\Sears\Exception\IntegrationException
*/
public function bindCollection(Request $request, Collection $collection)
{
$createdAt = $this->getCreatedAt();
if (null === $createdAt) {
throw new IntegrationException('CreatedAt is required');
}
$element = $this->xmlBuilder->setRoot('dss-order-adjustment-feed')->setNamespace('http://seller.marketplace.sears.com/oms/v1')->setSchemaLocation('http://seller.marketplace.sears.com/oms/v1 dss-order-return-v1.xsd ')->create();
$element->addChild('date-time-stamp', $this->getCreatedAt()->format('Y-m-d\\TH:i:s'));
// Hold all IntegrationExceptions until the end
$exceptions = array();
foreach ($collection as $orderReturn) {
try {
$this->xmlBuilder->addChild($element, 'dss-order-adjustment', $orderReturn->toArray());
} catch (IntegrationException $e) {
$orderId = $orderReturn->getPurchaseOrderId();
$message = $e->getMessage();
$exceptions[] = $this->exceptionMessageForOrder($orderId, $message);
}
}
$xml = $element->asXML();
$request->setContent($xml);
if (count($exceptions) > 0) {
throw new IntegrationException(json_encode($exceptions));
}
}
示例3: authenticate
/**
* Authenticate the request object. Apply the access_token to the URL
*
* TODO: implement
*
* @param Request $request Request object to authenticate
*/
public function authenticate(\Buzz\Message\Request $request)
{
$url = $request->getUrl();
$prefix = strpos($url, '?') > 0 ? '&' : '?';
$request->fromUrl($url . $prefix . 'access_token=' . $this->accessToken);
return $request;
}
示例4: setCurlOptsFromRequest
protected static function setCurlOptsFromRequest($curl, Message\Request $request)
{
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $request->getMethod());
curl_setopt($curl, CURLOPT_URL, $request->getUrl());
curl_setopt($curl, CURLOPT_HTTPHEADER, $request->getHeaders());
curl_setopt($curl, CURLOPT_POSTFIELDS, $request->getContent());
}
示例5: createRequest
/**
* Create request instance
*
* @param string $method Request method
* @param string $path Request path
* @param array $body Request body array
*/
protected function createRequest($method, $path, array $body)
{
$request = new Request($method, $path, $this->createHost());
$request->setHeaders(['Accept' => 'application/json; charset=UTF-8', 'Content-Type' => 'application/json', 'X-Stream' => 'true']);
$request->addHeader('Authorization: Basic ' . base64_encode($this->options['username'] . ':' . $this->options['password']));
$request->setContent(json_encode($body));
return $request;
}
示例6: createOffsitePurchase
/**
* @param array $paymentDetails
*
* @return \LedjIn\Bridge\Buzz\Response
*/
public function createOffsitePurchase(array $paymentDetails)
{
$paymentDetails['TxType'] = static::OPERATION_PAYMENT;
$query = http_build_query($paymentDetails);
$request = new Request('post', $this->getOffsiteResource(), $this->getGatewayHost());
$request->setContent($query);
return $this->doRequest($request);
}
示例7: testBearerAuthListener
public function testBearerAuthListener()
{
$request = new Message\Request();
$this->assertEmpty($request->getHeader('Authorization'));
$listener = new BearerAuthListener('superSecretAccessTokenGeneratedByTheNsaItself');
$listener->preSend($request);
$this->assertEquals('Bearer superSecretAccessTokenGeneratedByTheNsaItself', $request->getHeader('Authorization'));
}
示例8: testBasicAuthHeader
public function testBasicAuthHeader()
{
$request = new Message\Request();
$this->assertEmpty($request->getHeader('Authorization'));
$listener = new BasicAuthListener('foo', 'bar');
$listener->preSend($request);
$this->assertEquals('Basic ' . base64_encode('foo:bar'), $request->getHeader('Authorization'));
}
示例9: createHttpRequest
/**
* @return HttpRequest
*/
public function createHttpRequest($method, $uri, $contentType = '', $acceptType = '')
{
$request = new HttpRequest($method, $uri, $this->httpHost);
$request->addHeader('Authorization: Basic ' . base64_encode($this->httpAuth));
$request->addHeader('Content-Type: ' . $this->generateMediaTypeString($contentType));
$request->addHeader('Accept: ' . $this->generateMediaTypeString($acceptType));
return $request;
}
示例10: processSetCookieHeaders
/**
* Processes Set-Cookie headers from a request/response pair.
*
* @param Message\Request $request A request object
* @param Message\Response $response A response object
*/
public function processSetCookieHeaders(Message\Request $request, Message\Response $response)
{
foreach ($response->getHeader('Set-Cookie', false) as $header) {
$cookie = new Cookie();
$cookie->fromSetCookieHeader($header, parse_url($request->getHost(), PHP_URL_HOST));
$this->addCookie($cookie);
}
}
示例11: prepareRequest
/**
* @param Request $request
* @return BuzzRequest
*/
protected function prepareRequest(Request $request)
{
$buzzRequest = new BuzzRequest($request->getMethod(), $request->getUrl()->getResource(), $request->getUrl()->getHost());
$buzzRequest->setProtocolVersion($request->getProtocolVersion());
$buzzRequest->setHeaders(HeaderConverter::convertAssociativeToRaw($this->prepareHeaders($request)));
$buzzRequest->setContent($request->getContent());
return $buzzRequest;
}
示例12: testSendToInvalidUrl
/**
* @dataProvider provideInvalidHosts
*/
public function testSendToInvalidUrl($host, $client)
{
$this->setExpectedException('Buzz\\Exception\\ClientException');
$request = new Message\Request();
$request->fromUrl('http://' . $host . ':12345');
$response = new Message\Response();
$client = new $client();
$client->setTimeout(0.05);
$client->send($request, $response);
}
示例13: __construct
public function __construct(Response $response, Request $request, Curl $client)
{
$this->response = $response;
$request->setProtocolVersion(1.1);
$request->addHeader('Content-Type: application/json');
$this->request = $request;
$client->setTimeout(5);
$client->setIgnoreErrors(true);
$this->client = $client;
}
示例14: testSendToInvalidUrl
/**
* @dataProvider provideInvalidHosts
*/
public function testSendToInvalidUrl($host)
{
$this->setExpectedException('RuntimeException');
$request = new Message\Request();
$request->fromUrl('http://' . $host . ':12345');
$response = new Message\Response();
$client = new FileGetContents();
$client->setTimeout(0.05);
$client->send($request, $response);
}
示例15: isRequestCacheable
/**
*
* @param \Buzz\Message\Request $request
* @return boolean
*/
public function isRequestCacheable(Request $request)
{
if (!$this->isHTTPMethodCacheable($request->getMethod())) {
return false;
}
//[rfc2616-14.8]
if ($request->getHeader("authorization")) {
return false;
}
return true;
}