本文整理汇总了PHP中Guzzle\Http\Message\RequestFactory类的典型用法代码示例。如果您正苦于以下问题:PHP RequestFactory类的具体用法?PHP RequestFactory怎么用?PHP RequestFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了RequestFactory类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: parseRequest
public function parseRequest($data)
{
list($headers, $bodyBuffer) = explode("\r\n\r\n", $data, 2);
$factory = new RequestFactory();
$parsed = $factory->parseMessage($headers . "\r\n\r\n");
$parsedQuery = array();
if (0 === strpos($parsed['parts']['query'], '?')) {
$query = substr($parsed['parts']['query'], 1);
parse_str($query, $parsedQuery);
}
$request = new Request($parsed['method'], $parsed['parts']['path'], $parsedQuery, $parsed['protocol_version'], $parsed['headers']);
return array($request, $bodyBuffer);
}
开发者ID:ramiyer,项目名称:react,代码行数:13,代码来源:RequestHeaderParser.php
示例2: testIgnoresUnsentRequests
/**
* @covers Guzzle\Http\Plugin\HistoryPlugin::add
*/
public function testIgnoresUnsentRequests()
{
$h = new HistoryPlugin();
$request = RequestFactory::getInstance()->create('GET', 'http://localhost/');
$h->add($request);
$this->assertEquals(0, count($h));
}
开发者ID:MicroSDHC,项目名称:justinribeiro.com-examples,代码行数:10,代码来源:HistoryPluginTest.php
示例3: testRevalidatesResponsesAgainstOriginServer
/**
* @dataProvider cacheRevalidationDataProvider
*/
public function testRevalidatesResponsesAgainstOriginServer($can, $request, $response, $validate = null, $result = null)
{
// Send some responses to the test server for cache validation
$server = $this->getServer();
$server->flush();
if ($validate) {
$server->enqueue($validate);
}
$request = RequestFactory::getInstance()->fromMessage("GET / HTTP/1.1\r\nHost: 127.0.0.1:" . $server->getPort() . "\r\n" . $request);
$response = Response::fromMessage($response);
$request->setClient(new Client());
$plugin = new CachePlugin(new DoctrineCacheAdapter(new ArrayCache()));
$this->assertEquals($can, $plugin->canResponseSatisfyRequest($request, $response), '-> ' . $request . "\n" . $response);
if ($result) {
$result = Response::fromMessage($result);
$result->removeHeader('Date');
$request->getResponse()->removeHeader('Date');
$request->getResponse()->removeHeader('Connection');
// Get rid of dates
$this->assertEquals((string) $result, (string) $request->getResponse());
}
if ($validate) {
$this->assertEquals(1, count($server->getReceivedRequests()));
}
}
开发者ID:alvarobfdev,项目名称:applog,代码行数:28,代码来源:DefaultRevalidationTest.php
示例4: uploadMedia
private function uploadMedia($path, $type)
{
//build Mac
$timeStamp = time();
$lstParams = array($this->pageId, $timeStamp, $this->secretKey);
$mac = ZaloSdkHelper::buildMacForAuthentication($lstParams);
$request = RequestFactory::getInstance()->create('POST', CommonInfo::$DOMAIN . CommonInfo::$SER_UPLOAD)->setClient(new Client())->addPostFiles(array(CommonInfo::$URL_UPLOAD => $path))->addPostFields(array(CommonInfo::$URL_ACT => $type, CommonInfo::$URL_PAGEID => $this->pageId, CommonInfo::$URL_TIMESTAMP => $timeStamp, CommonInfo::$URL_MAC => $mac));
$response = $request->send()->json();
$error = $response["error"];
if ($error < 0) {
$zaloSdkExcep = new ZaloSdkException();
$zaloSdkExcep->setZaloSdkExceptionErrorCode($error);
if (!empty($response["message"])) {
$zaloSdkExcep->setZaloSdkExceptionMessage($response["message"]);
}
throw $zaloSdkExcep;
} else {
if (!empty($response["result"])) {
return $response["result"];
} else {
$zaloSdkExcep = new ZaloSdkException();
$zaloSdkExcep->setZaloSdkExceptionErrorCode(-1);
throw zaloSdkExcep;
}
}
}
开发者ID:zalopage,项目名称:Zalo-Sdk-Php,代码行数:26,代码来源:ZaloUploadServiceImpl.php
示例5: createRedirectRequest
protected function createRedirectRequest(RequestInterface $request, $statusCode, $location, RequestInterface $original)
{
$redirectRequest = null;
$strict = $original->getParams()->get(self::STRICT_REDIRECTS);
if ($request instanceof EntityEnclosingRequestInterface && ($statusCode == 303 || !$strict && $statusCode <= 302)) {
$redirectRequest = RequestFactory::getInstance()->cloneRequestWithMethod($request, 'GET');
} else {
$redirectRequest = clone $request;
}
$redirectRequest->setIsRedirect(true);
$redirectRequest->setResponseBody($request->getResponseBody());
$location = Url::factory($location);
if (!$location->isAbsolute()) {
$originalUrl = $redirectRequest->getUrl(true);
$originalUrl->getQuery()->clear();
$location = $originalUrl->combine((string) $location, true);
}
$redirectRequest->setUrl($location);
$redirectRequest->getEventDispatcher()->addListener('request.before_send', $func = function ($e) use(&$func, $request, $redirectRequest) {
$redirectRequest->getEventDispatcher()->removeListener('request.before_send', $func);
$e['request']->getParams()->set(RedirectPlugin::PARENT_REQUEST, $request);
});
if ($redirectRequest instanceof EntityEnclosingRequestInterface && $redirectRequest->getBody()) {
$body = $redirectRequest->getBody();
if ($body->ftell() && !$body->rewind()) {
throw new CouldNotRewindStreamException('Unable to rewind the non-seekable entity body of the request after redirecting. cURL probably ' . 'sent part of body before the redirect occurred. Try adding acustom rewind function using on the ' . 'entity body of the request using setRewindFunction().');
}
}
return $redirectRequest;
}
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:30,代码来源:RedirectPlugin.php
示例6: __construct
/**
* Client constructor
*
* @param string $baseUrl Base URL of the web service
* @param array|Collection $config Configuration settings
*/
public function __construct($baseUrl = '', $config = null)
{
$this->setConfig($config ?: new Collection());
$this->setBaseUrl($baseUrl);
$this->defaultHeaders = new Collection();
$this->setRequestFactory(RequestFactory::getInstance());
}
开发者ID:norv,项目名称:guzzle,代码行数:13,代码来源:Client.php
示例7: __construct
/**
* Constructor override
*/
public function __construct(Collection $config)
{
$this->setConfig($config);
$this->setBaseUrl($config->get(Options::BASE_URL));
$this->defaultHeaders = new Collection();
$this->setRequestFactory(RequestFactory::getInstance());
}
开发者ID:loulancn,项目名称:core,代码行数:10,代码来源:InstanceMetadataClient.php
示例8: testProperlyValidatesWhenUsingContentEncoding
public function testProperlyValidatesWhenUsingContentEncoding()
{
$plugin = new Md5ValidatorPlugin(true);
$request = RequestFactory::getInstance()->create('GET', 'http://www.test.com/');
$request->getEventDispatcher()->addSubscriber($plugin);
// Content-MD5 is the MD5 hash of the canonical content after all
// content-encoding has been applied. Because cURL will automatically
// decompress entity bodies, we need to re-compress it to calculate.
$body = EntityBody::factory('abc');
$body->compress();
$hash = $body->getContentMd5();
$body->uncompress();
$response = new Response(200, array('Content-MD5' => $hash, 'Content-Encoding' => 'gzip'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
$this->assertEquals('abc', $response->getBody(true));
// Try again with an unknown encoding
$response = new Response(200, array('Content-MD5' => $hash, 'Content-Encoding' => 'foobar'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
// Try again with compress
$body->compress('bzip2.compress');
$response = new Response(200, array('Content-MD5' => $body->getContentMd5(), 'Content-Encoding' => 'compress'), 'abc');
$request->dispatch('request.complete', array('response' => $response));
// Try again with encoding and disabled content-encoding checks
$request->getEventDispatcher()->removeSubscriber($plugin);
$plugin = new Md5ValidatorPlugin(false);
$request->getEventDispatcher()->addSubscriber($plugin);
$request->dispatch('request.complete', array('response' => $response));
}
开发者ID:jsnshrmn,项目名称:Suma,代码行数:28,代码来源:Md5ValidatorPluginTest.php
示例9: testCreatesCanonicalizedString
/**
* @dataProvider signatureDataProvider
*/
public function testCreatesCanonicalizedString($input, $result, $expires = null)
{
$signature = new S3Signature();
$request = \Guzzle\Http\Message\RequestFactory::getInstance()->create($input['verb'], 'http://' . $input['headers']['Host'] . $input['path'], $input['headers']);
$request->setClient($this->getServiceBuilder()->get('s3'));
$this->assertEquals($result, $signature->createCanonicalizedString($request), $expires);
}
开发者ID:myrichhub,项目名称:mssapi_php,代码行数:10,代码来源:S3SignatureTest.php
示例10: testSettingBody
public function testSettingBody()
{
$request = \Guzzle\Http\Message\RequestFactory::getInstance()->create('PUT', 'http://www.test.com/');
$request->setBody(EntityBody::factory('test'));
$this->assertEquals(4, (string) $request->getHeader('Content-Length'));
$this->assertFalse($request->hasHeader('Transfer-Encoding'));
}
开发者ID:summer11123,项目名称:trucker,代码行数:7,代码来源:RestRequestTest.php
示例11: testErrorDescriptions
/**
* @dataProvider getErrorMapping
* @param string $httpMethod
* @param int $statusCode
* @param string $description
*/
public function testErrorDescriptions($httpMethod, $statusCode, $description)
{
$request = RequestFactory::getInstance()->fromMessage("{$httpMethod} /container/ HTTP/1.1\r\n" . "Host: www.foo.bar\r\n");
$response = new Response($statusCode);
$prevException = BadResponseException::factory($request, $response);
$httpException = HttpException::factory($prevException);
$this->assertEquals($description, $httpException->getDescription());
}
开发者ID:samizdam,项目名称:WebDAV,代码行数:14,代码来源:HttpExceptionTest.php
示例12: testAddsDebugLoggerWhenSetToDebug
/**
* @expectedException PHPUnit_Framework_Error
* @expectedExceptionMessage GET http://www.example.com/ - 503 Service Unavailable
*/
public function testAddsDebugLoggerWhenSetToDebug()
{
list($config, $plugin, $resolver) = $this->getMocks();
$config->set(Options::BACKOFF_LOGGER, 'debug');
$client = $this->getMock('Aws\\Common\\Client\\DefaultClient', array(), array(), '', false);
$resolver->resolve($config, $client);
$listeners = $plugin->getEventDispatcher()->getListeners();
$this->assertArrayHasKey('plugins.backoff.retry', $listeners);
$plugin->dispatch('plugins.backoff.retry', array('request' => RequestFactory::getInstance()->create('GET', 'http://www.example.com'), 'response' => new Response(503), 'retries' => 3, 'delay' => 2));
}
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:14,代码来源:BackoffOptionResolverTest.php
示例13: testMasksCurlExceptions
/**
* @covers Guzzle\Http\Plugin\AsyncPlugin::onRequestTimeout
*/
public function testMasksCurlExceptions()
{
$p = new AsyncPlugin();
$request = RequestFactory::getInstance()->create('PUT', 'http://www.example.com');
$e = new CurlException('Error');
$event = new Event(array('request' => $request, 'exception' => $e));
$p->onRequestTimeout($event);
$this->assertEquals(RequestInterface::STATE_COMPLETE, $request->getState());
$this->assertEquals(200, $request->getResponse()->getStatusCode());
$this->assertTrue($request->getResponse()->hasHeader('X-Guzzle-Async'));
}
开发者ID:nickpeirson,项目名称:guzzle,代码行数:14,代码来源:AsyncPluginTest.php
示例14: getMocks
/**
* @return array
*/
protected function getMocks()
{
$that = $this;
$logger = new ClosureLogAdapter(function ($message) use($that) {
$that->message .= $message . "\n";
});
$logPlugin = new BackoffLogger($logger);
$response = new Response(503);
$request = RequestFactory::getInstance()->create('PUT', 'http://www.example.com', array('Content-Length' => 3, 'Foo' => 'Bar'));
return array($logPlugin, $request, $response);
}
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:14,代码来源:BackoffLoggerTest.php
示例15: parseRequestFromResponse
/**
* @param Response $response
* @param string $path
* @throws UnexpectedValueException
* @return UnifiedRequest
*/
private function parseRequestFromResponse(Response $response, $path)
{
try {
$requestInfo = Util::deserialize($response->getBody());
} catch (UnexpectedValueException $e) {
throw new UnexpectedValueException(sprintf('Cannot deserialize response from "%s": "%s"', $path, $response->getBody()), null, $e);
}
$request = RequestFactory::getInstance()->fromMessage($requestInfo['request']);
$params = $this->configureRequest($request, $requestInfo['server'], isset($requestInfo['enclosure']) ? $requestInfo['enclosure'] : []);
return new UnifiedRequest($request, $params);
}
开发者ID:internations,项目名称:http-mock,代码行数:17,代码来源:RequestCollectionFacade.php
示例16: testUrl
public function testUrl()
{
$app = $this->getApp();
if ($app['deprecated.php']) {
$factory = new RequestFactory();
$request = $factory->create('GET', '/');
$response = new V3Response('200');
$guzzle = $this->getMock('Guzzle\\Service\\Client', array('get', 'send'));
$request->setClient($guzzle);
$guzzle->expects($this->once())->method('send')->will($this->returnValue($response));
} else {
$factory = new MessageFactory();
$request = $factory->createRequest('GET', '/');
$response = new Response('200');
$guzzle = $this->getMock('GuzzleHttp\\Client', array('get'));
}
$guzzle->expects($this->once())->method('get')->with('http://loripsum.net/api/1/veryshort')->will($this->returnValue($request));
$app['guzzle.client'] = $guzzle;
$app['prefill']->get('/1/veryshort');
}
开发者ID:aaleksu,项目名称:bolt_cm,代码行数:20,代码来源:PrefillTest.php
示例17: testAddsHeader
public function testAddsHeader()
{
$plugin = new AuthenticationPlugin('foo');
$dispatcher = new EventDispatcher();
$dispatcher->addSubscriber($plugin);
$request = RequestFactory::getInstance()->create('POST', 'http://www.example.com');
$event = new Event(array('request' => $request));
$dispatcher->dispatch('request.before_send', $event);
$headers = $event['request']->getHeaders();
$this->assertArrayHasKey('helthe-api-key', $headers);
$this->assertEquals('foo', $headers['helthe-api-key']);
}
开发者ID:helthe,项目名称:monitor,代码行数:12,代码来源:AuthenticationPluginTest.php
示例18: parseRequestFromResponse
/**
* @param Response $response
* @param string $path
* @throws UnexpectedValueException
* @return UnifiedRequest
*/
private function parseRequestFromResponse(Response $response, $path)
{
// @codingStandardsIgnoreStart
$requestInfo = @unserialize($response->getBody());
// @codingStandardsIgnoreEnd
if ($requestInfo === false) {
throw new UnexpectedValueException(sprintf('Cannot deserialize response from "%s": "%s"', $path, $response->getBody()));
}
$request = RequestFactory::getInstance()->fromMessage($requestInfo['request']);
$params = $this->configureRequest($request, $requestInfo['server']);
return new UnifiedRequest($request, $params);
}
开发者ID:colindecarlo,项目名称:http-mock,代码行数:18,代码来源:RequestCollectionFacade.php
示例19: testExecutesClosure
/**
* @covers Guzzle\Service\Command\ClosureCommand::prepare
* @covers Guzzle\Service\Command\ClosureCommand::build
*/
public function testExecutesClosure()
{
$c = new ClosureCommand(array('closure' => function ($command, $api) {
$command->set('testing', '123');
$request = RequestFactory::getInstance()->create('GET', 'http://www.test.com/');
return $request;
}));
$client = $this->getServiceBuilder()->get('mock');
$c->setClient($client)->prepare();
$this->assertEquals('123', $c->get('testing'));
$this->assertEquals('http://www.test.com/', $c->getRequest()->getUrl());
}
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:16,代码来源:ClosureCommandTest.php
示例20: testAppendsStringsToUserAgentHeader
public function testAppendsStringsToUserAgentHeader()
{
$this->assertInternalType('array', UserAgentListener::getSubscribedEvents());
$listener = new UserAgentListener();
$request = RequestFactory::getInstance()->create('GET', 'http://www.foo.com', array('User-Agent' => 'Aws/Foo Baz/Bar'));
$command = $this->getMockBuilder('Aws\\Common\\Command\\JsonCommand')->setMethods(array('getRequest'))->getMock();
$command->expects($this->any())->method('getRequest')->will($this->returnValue($request));
$command->add(UserAgentListener::OPTION, 'Test/123')->add(UserAgentListener::OPTION, 'Other/456');
$event = new Event(array('command' => $command));
$listener->onBeforeSend($event);
$this->assertEquals('Aws/Foo Baz/Bar Test/123 Other/456', (string) $request->getHeader('User-Agent'));
}
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:12,代码来源:UserAgentListenerTest.php
注:本文中的Guzzle\Http\Message\RequestFactory类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论