本文整理汇总了PHP中Buzz\Message\Request::fromUrl方法的典型用法代码示例。如果您正苦于以下问题:PHP Request::fromUrl方法的具体用法?PHP Request::fromUrl怎么用?PHP Request::fromUrl使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Buzz\Message\Request
的用法示例。
在下文中一共展示了Request::fromUrl方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: testFromUrlRejectsInvalidUrl
public function testFromUrlRejectsInvalidUrl()
{
$this->setExpectedException('InvalidArgumentException');
// port number is too high
$request = new Request();
$request->fromUrl('http://localhost:123456');
}
示例3: 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);
}
示例4: createRequest
/**
* Converts a PSR request into a BuzzRequest request.
*
* @param RequestInterface $request
*
* @return BuzzRequest
*/
private function createRequest(RequestInterface $request)
{
$buzzRequest = new BuzzRequest();
$buzzRequest->setMethod($request->getMethod());
$buzzRequest->fromUrl($request->getUri()->__toString());
$buzzRequest->setProtocolVersion($request->getProtocolVersion());
$buzzRequest->setContent((string) $request->getBody());
$this->addPsrHeadersToBuzzRequest($request, $buzzRequest);
return $buzzRequest;
}
示例5: 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);
}
示例6: testAuthenticate
public function testAuthenticate()
{
$basic = new OAuth('KFGDSYGSDHKKGFSFN');
// Create request, authenticate it
$request = new Request();
$request->fromUrl('http://test.com?name=dsyph3r');
$request = $basic->authenticate($request);
// Check access_token param is set correctly
$url = parse_url($request->getUrl());
$params = explode('&', $url['query']);
$this->assertContains('access_token=KFGDSYGSDHKKGFSFN', $params);
}
示例7: testLogger
public function testLogger()
{
$test = $this;
$logger = function ($line) use($test) {
$test->assertRegExp('~^Sent "GET http://google.com/" in \\d+ms$~', $line);
};
$request = new Message\Request();
$request->fromUrl('http://google.com/');
$response = new Message\Response();
$listener = new LoggerListener($logger);
$listener->preSend($request);
$listener->postSend($request, $response);
}
示例8: doHttpRequest
/**
* @param $method
* @param $relativeUrl
* @param array|\stdClass $content
* @return mixed
*/
protected function doHttpRequest($method, $relativeUrl, $content = null)
{
$relativeUrl = ltrim($relativeUrl, '/');
$response = new Response();
$request = new Request($method);
$request->fromUrl($this->baseUrl . '/' . $relativeUrl);
$request->addHeader("Content-Type: application/json");
$request->addHeader('Accept: application/json');
if ($content) {
$request->setContent(json_encode(array_filter((array) $content)));
}
$timezone = new \DateTimeZone("UTC");
$datetime = new \DateTime(null, $timezone);
$timestamp = str_replace('-', '', $datetime->format('c'));
$nonce = uniqid();
$authToken = $this->makeAuthHeader($request, $timestamp, $nonce);
$request->addHeader("Authorization: " . $authToken);
// $listener = new BasicAuthListener($this->username, $this->password);
// $listener->preSend($request);
$this->httpClient->send($request, $response);
return $this->getResult($response);
}
示例9: testMultiCurlExecutesRequestsConcurently
public function testMultiCurlExecutesRequestsConcurently()
{
$client = new MultiCurl();
$client->setTimeout(10);
$calls = array();
$callback = function ($client, $request, $response, $options, $error) use(&$calls) {
$calls[] = func_get_args();
};
for ($i = 3; $i > 0; $i--) {
$request = new Request();
$request->fromUrl($_SERVER['TEST_SERVER'] . '?delay=' . $i);
$client->send($request, new Response(), array('callback' => $callback));
}
$client->flush();
$this->assertCount(3, $calls);
}
示例10: buildValidationRequest
/**
* @param string $credentials
*
* @return \Buzz\Message\Request
*/
public function buildValidationRequest($credentials)
{
$request = new Request();
$request->fromUrl(sprintf('%s&ticket=%s', $this->getValidationUrl(), $credentials));
return $request;
}
示例11: doRequest
/**
* @parem string $controller
* @param Request $request
* @param array $qs
*
* @throws RequestException
*
* @return JsonResponse
*/
protected function doRequest($controller, Request $request, array $qs = array())
{
$request->fromUrl($this->getApiEndpoint($controller) . '?' . http_build_query($qs));
$request->addHeader('Authorization: Basic ' . $this->options['key']);
$request->addHeader('Accept: text/json');
$this->client->send($request, $response = new JsonResponse());
$content = $response->getContentJson(true);
if (!in_array($content['ReturnCode'], array(self::EXECCODE_SUCCESS, self::EXECCODE_OPERATION_REFUSED))) {
$e = new RequestException(print_r(array_merge($content, array('url' => $request->getUrl(), 'content' => $request->getContent())), true));
$e->setRequest($request);
throw $e;
}
return $response;
}
示例12: testRedirectedToForbiddenProtocol
/**
* @expectedException RuntimeException
* @expectedExceptionMessage Protocol pop3 not supported or disabled in libcurl
*/
public function testRedirectedToForbiddenProtocol()
{
$client = new Curl();
$request = new Request();
$request->fromUrl($_SERVER['TEST_SERVER'] . '?redirect_to=pop3://localhost/');
$response = $this->send($client, $request);
}
示例13: testConsecutiveRequests
/**
* @dataProvider provideClient
*/
public function testConsecutiveRequests($client)
{
// request 1
$request = new Request(Request::METHOD_PUT);
$request->fromUrl($_SERVER['TEST_SERVER']);
$request->addHeader('Content-Type: application/json');
$request->setContent(json_encode(array('foo' => 'bar')));
$response = new Response();
$client->send($request, $response);
$data = json_decode($response->getContent(), true);
$this->assertEquals('PUT', $data['SERVER']['REQUEST_METHOD']);
$this->assertEquals('application/json', $data['SERVER']['CONTENT_TYPE']);
$this->assertEquals('{"foo":"bar"}', $data['INPUT']);
// request 2
$request = new Request(Request::METHOD_GET);
$request->fromUrl($_SERVER['TEST_SERVER']);
$response = new Response();
$client->send($request, $response);
$data = json_decode($response->getContent(), true);
$this->assertEquals('GET', $data['SERVER']['REQUEST_METHOD']);
$this->assertEmpty($data['INPUT']);
}
示例14: queryByUrl
/**
* Return an array of Image most similar to the supplied image
*
* @param string $url
* @param int $returns (optional) defaults to 12
* @param int $sketch (optional) 0 for photograph 1 for sketch, defaults to 0
* @param $fast (optional)
*
* @return array of ImgSeek\Entity\ImageInterface
*/
public function queryByUrl($url, $returns = 12, $sketch = 0, $fast = false)
{
$request = new Request();
$request->fromUrl($url);
$response = new Response();
$this->httpClient->send($request, $response);
$imgResponses = $this->imgSeekGateway->request('queryImgBlob', array($this->defaultDbId, $response->getContent(), $returns, $sketch, $fast));
$imageIds = array();
foreach ($imgResponses as $imgResponse) {
$imageIds[] = $imgResponse[0];
}
$images = array();
foreach ($this->persistence->findImages($imageIds) as $image) {
$imageId = $image->getImageId();
foreach ($imgResponses as $imgResponse) {
if ($imgResponse[0] == $imageId) {
$imageSet['image'] = $image;
$imageSet['score'] = $imgResponse[1];
$images[] = $imageSet;
continue;
}
}
}
return $images;
}
示例15: testRedirectedResponse
/**
* @dataProvider provideClient
*/
public function testRedirectedResponse($client)
{
$request = new Request();
$request->fromUrl($_SERVER['TEST_SERVER'] . '?redirect_to=' . $_SERVER['TEST_SERVER']);
$response = $this->send($client, $request);
$headers = $response->getHeaders();
$this->assertContains('200', $headers[0]);
}