本文整理汇总了PHP中Guzzle\Http\EntityBody类的典型用法代码示例。如果您正苦于以下问题:PHP EntityBody类的具体用法?PHP EntityBody怎么用?PHP EntityBody使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了EntityBody类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: transfer
/**
* {@inheritdoc}
*/
protected function transfer()
{
while (!$this->stopped && !$this->source->isConsumed()) {
if ($this->source->getContentLength() && $this->source->isSeekable()) {
// If the stream is seekable and the Content-Length known, then stream from the data source
$body = new ReadLimitEntityBody($this->source, $this->partSize, $this->source->ftell());
} else {
// We need to read the data source into a temporary buffer before streaming
$body = EntityBody::factory();
while ($body->getContentLength() < $this->partSize && $body->write($this->source->read(max(1, min(10 * Size::KB, $this->partSize - $body->getContentLength()))))) {
}
}
// @codeCoverageIgnoreStart
if ($body->getContentLength() == 0) {
break;
}
// @codeCoverageIgnoreEnd
$params = $this->state->getUploadId()->toParams();
$command = $this->client->getCommand('UploadPart', array_replace($params, array('PartNumber' => count($this->state) + 1, 'Body' => $body, 'ContentMD5' => (bool) $this->options['part_md5'], Ua::OPTION => Ua::MULTIPART_UPLOAD)));
// Notify observers that the part is about to be uploaded
$eventData = $this->getEventData();
$eventData['command'] = $command;
$this->dispatch(self::BEFORE_PART_UPLOAD, $eventData);
// Allow listeners to stop the transfer if needed
if ($this->stopped) {
break;
}
$response = $command->getResponse();
$this->state->addPart(UploadPart::fromArray(array('PartNumber' => count($this->state) + 1, 'ETag' => $response->getHeader('ETag', true), 'Size' => $body->getContentLength(), 'LastModified' => gmdate(DateFormat::RFC2822))));
// Notify observers that the part was uploaded
$this->dispatch(self::AFTER_PART_UPLOAD, $eventData);
}
}
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:36,代码来源:SerialTransfer.php
示例2: setBody
/**
* Set the body of the request
*
* @param string|resource|EntityBody $body Body to use in the entity body
* of the request
* @param string $contentType (optional) Content-Type to set. Leave null
* to use an existing Content-Type or to guess the Content-Type
* @param bool $tryChunkedTransfer (optional) Set to TRUE to try to use
* Tranfer-Encoding chunked
*
* @return EntityEnclosingRequest
* @throws RequestException if the protocol is < 1.1 and Content-Length can
* not be determined
*/
public function setBody($body, $contentType = null, $tryChunkedTransfer = false)
{
$this->body = EntityBody::factory($body);
$this->removeHeader('Content-Length');
$this->setHeader('Expect', '100-Continue');
if ($contentType) {
$this->setHeader('Content-Type', (string) $contentType);
}
if ($tryChunkedTransfer) {
$this->setHeader('Transfer-Encoding', 'chunked');
} else {
$this->removeHeader('Transfer-Encoding');
// Set the Content-Length header if it can be determined
$size = $this->body->getContentLength();
if ($size !== null && $size !== false) {
$this->setHeader('Content-Length', $size);
} else {
if ('1.1' == $this->protocolVersion) {
$this->setHeader('Transfer-Encoding', 'chunked');
} else {
throw new RequestException('Cannot determine entity body ' . 'size and cannot use chunked Transfer-Encoding when ' . 'using HTTP/' . $this->protocolVersion);
}
}
}
return $this;
}
开发者ID:MicroSDHC,项目名称:justinribeiro.com-examples,代码行数:40,代码来源:EntityEnclosingRequest.php
示例3: create
/**
* {@inheritdoc}
*/
public function create($method, $url, $headers = null, $body = null)
{
if ($method != 'POST' && $method != 'PUT' && $method != 'PATCH') {
$c = $this->requestClass;
$request = new $c($method, $url, $headers);
if ($body) {
$request->setResponseBody(EntityBody::factory($body));
}
return $request;
}
$c = $this->entityEnclosingRequestClass;
$request = new $c($method, $url, $headers);
if ($body) {
$isChunked = (string) $request->getHeader('Transfer-Encoding') == 'chunked';
if ($method == 'POST' && (is_array($body) || $body instanceof Collection)) {
$request->addPostFields($body);
if ($isChunked) {
$request->setHeader('Transfer-Encoding', 'chunked');
}
} elseif (is_resource($body) || $body instanceof EntityBody) {
$request->setBody($body, (string) $request->getHeader('Content-Type'), $isChunked);
} else {
$request->setBody((string) $body, (string) $request->getHeader('Content-Type'), $isChunked);
}
}
return $request;
}
开发者ID:norv,项目名称:guzzle,代码行数:30,代码来源:RequestFactory.php
示例4: testCreatesPutRequests
/**
* @covers Guzzle\Http\Message\RequestFactory::create
*/
public function testCreatesPutRequests()
{
// Test using a string
$request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, 'Data');
$this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
$this->assertEquals('PUT', $request->getMethod());
$this->assertEquals('http', $request->getScheme());
$this->assertEquals('http://www.google.com/path?q=1&v=2', $request->getUrl());
$this->assertEquals('www.google.com', $request->getHost());
$this->assertEquals('/path', $request->getPath());
$this->assertEquals('/path?q=1&v=2', $request->getResource());
$this->assertInstanceOf('Guzzle\\Http\\EntityBody', $request->getBody());
$this->assertEquals('Data', (string) $request->getBody());
unset($request);
// Test using an EntityBody
$request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, EntityBody::factory('Data'));
$this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
$this->assertEquals('Data', (string) $request->getBody());
// Test using a resource
$resource = fopen('php://temp', 'w+');
fwrite($resource, 'Data');
$request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, $resource);
$this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
$this->assertEquals('Data', (string) $request->getBody());
// Test using an object that can be cast as a string
$request = RequestFactory::getInstance()->create('PUT', 'http://www.google.com/path?q=1&v=2', null, Url::factory('http://www.example.com/'));
$this->assertInstanceOf('Guzzle\\Http\\Message\\EntityEnclosingRequest', $request);
$this->assertEquals('http://www.example.com/', (string) $request->getBody());
}
开发者ID:biribogos,项目名称:wikihow-src,代码行数:32,代码来源:RequestFactoryTest.php
示例5: receiveResponseHeader
/**
* Receive a response header from curl
*
* @param resource $curl Curl handle
* @param string $header Received header
*
* @return int
*/
public function receiveResponseHeader($curl, $header)
{
static $normalize = array("\r", "\n");
$length = strlen($header);
$header = str_replace($normalize, '', $header);
if (strpos($header, 'HTTP/') === 0) {
$startLine = explode(' ', $header, 3);
$code = $startLine[1];
$status = isset($startLine[2]) ? $startLine[2] : '';
// Only download the body of the response to the specified response
// body when a successful response is received.
if ($code >= 200 && $code < 300) {
$body = $this->request->getResponseBody();
} else {
$body = EntityBody::factory();
}
$response = new Response($code, null, $body);
$response->setStatus($code, $status);
$this->request->startResponse($response);
$this->request->dispatch('request.receive.status_line', array('request' => $this, 'line' => $header, 'status_code' => $code, 'reason_phrase' => $status));
} elseif ($pos = strpos($header, ':')) {
$this->request->getResponse()->addHeader(trim(substr($header, 0, $pos)), trim(substr($header, $pos + 1)));
}
return $length;
}
开发者ID:adrianoaguiar,项目名称:magento-elasticsearch-module,代码行数:33,代码来源:RequestMediator.php
示例6: create
/**
* {@inheritdoc}
*/
public function create($method, $url, $headers = null, $body = '', array $options = array())
{
$c = $this->entityEnclosingRequestClass;
$request = new $c($method, $url, $headers);
$request->setBody(EntityBody::factory($body));
return $request;
}
开发者ID:DannyHuisman,项目名称:Ratchet,代码行数:10,代码来源:RequestFactory.php
示例7: setBody
public function setBody($body, $contentType = null)
{
$this->body = EntityBody::factory($body);
if ($contentType === null && !$this->hasHeader('Content-Type')) {
$contentType = $this->body->getContentType();
}
if ($contentType) {
$this->setHeader('Content-Type', $contentType);
}
if (!$this->body->isSeekable() && $this->expectCutoff !== false) {
$this->setHeader('Expect', '100-Continue');
}
$size = $this->body->getContentLength();
if ($size !== null && $size !== false) {
$this->setHeader('Content-Length', $size);
if ($size > $this->expectCutoff) {
$this->setHeader('Expect', '100-Continue');
}
} elseif (!$this->hasHeader('Content-Length')) {
if ('1.1' == $this->protocolVersion) {
$this->setHeader('Transfer-Encoding', 'chunked');
} else {
throw new RequestException('Cannot determine Content-Length and cannot use chunked Transfer-Encoding when using HTTP/1.0');
}
}
return $this;
}
开发者ID:Ryu0621,项目名称:SaNaVi,代码行数:27,代码来源:EntityEnclosingRequest.php
示例8: buildCoreRequest
protected function buildCoreRequest(HttpRequest $request)
{
$headers = $request->getHeaders();
$contentLength = 0;
if (!$request->isParameterInUrl()) {
$body = $request->getParameterString();
$contentLength = strlen($body);
} else {
$body = $request->getContent();
if ($body !== null) {
AssertUtils::assertSet(HttpHeaders::CONTENT_LENGTH, $headers);
$contentLength = (int) $headers[HttpHeaders::CONTENT_LENGTH];
}
}
$entity = null;
$headers[HttpHeaders::CONTENT_LENGTH] = (string) $contentLength;
if ($body !== null) {
$entity = new ReadLimitEntityBody(EntityBody::factory($body), $contentLength, $request->getOffset() !== false ? $request->getOffset() : 0);
}
$coreRequest = $this->client->createRequest($request->getMethod(), $request->getFullUrl(), $headers, $entity);
if ($request->getResponseBody() != null) {
$coreRequest->setResponseBody($request->getResponseBody());
}
return $coreRequest;
}
开发者ID:diandianxiyu,项目名称:Yii2Api,代码行数:25,代码来源:HttpServiceClient.php
示例9: 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
示例10: createTransferAction
protected function createTransferAction(\SplFileInfo $file)
{
// Open the file for reading
$filename = $file->getPathName();
if (!($resource = fopen($filename, 'r'))) {
// @codeCoverageIgnoreStart
throw new RuntimeException("Could not open {$filename} for reading");
// @codeCoverageIgnoreEnd
}
$key = $this->options['source_converter']->convert($filename);
$body = EntityBody::factory($resource);
// Determine how the ACL should be applied
if ($acl = $this->options['acl']) {
$aclType = is_string($this->options['acl']) ? 'ACL' : 'ACP';
} else {
$acl = 'private';
$aclType = 'ACL';
}
// Use a multi-part upload if the file is larger than the cutoff size and is a regular file
if ($body->getWrapper() == 'plainfile' && $file->getSize() >= $this->options['multipart_upload_size']) {
$builder = UploadBuilder::newInstance()->setBucket($this->options['bucket'])->setKey($key)->setMinPartSize($this->options['multipart_upload_size'])->setOption($aclType, $acl)->setClient($this->options['client'])->setSource($body)->setConcurrency($this->options['concurrency']);
$this->dispatch(self::BEFORE_MULTIPART_BUILD, array('builder' => $builder, 'file' => $file));
return $builder->build();
}
return $this->options['client']->getCommand('PutObject', array('Bucket' => $this->options['bucket'], 'Key' => $key, 'Body' => $body, $aclType => $acl));
}
开发者ID:mahassan,项目名称:shellneverknow,代码行数:26,代码来源:UploadSync.php
示例11: save
public function save($vaultName, $file, $description = null)
{
if (!$this->vaultExist($vaultName)) {
$this->createVault($vaultName);
}
if (!is_file($file)) {
throw new \Exception('File not exist');
}
$options = array('vaultName' => $vaultName, 'body' => EntityBody::factory(fopen($file, 'r')));
/*if (filesize($file) > 1024000) {
$multiupload = $this->glacier->initiateMultipartUpload(array(
'vaultName' => $vaultName,
'archiveDescription' => $description,
'partSize' => '4194304'
));
$options['uploadId'] = $multiupload->get('uploadId');
$options['range'] = filesize($file);
$this->glacier->uploadMultipartPart($options);
$result = $this->glacier->completeMultipartUpload(array(
'vaultName' => $vaultName,
'uploadId' => $multiupload->get('uploadId'),
));
} else {*/
if ($description) {
$options['archiveDescription'] = $description;
}
$result = $this->glacier->uploadArchive($options);
//}
$archiveId = $result->get('archiveId');
return $archiveId ? true : false;
}
开发者ID:sb15,项目名称:server-backup,代码行数:35,代码来源:Amazon.php
示例12: putObject
public function putObject($bucket, $key, $filePath, $options)
{
$options['Bucket'] = $bucket;
$options['Key'] = $key;
$options['Body'] = EntityBody::factory(fopen($filePath, 'r+'));
return $this->s3->putObject($options);
}
开发者ID:TheJester12,项目名称:s3upload_field,代码行数:7,代码来源:class.s3Facade.php
示例13: 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
示例14: setBody
/**
* {@inheritdoc}
*/
public function setBody($body, $contentType = null, $tryChunkedTransfer = false)
{
$this->body = EntityBody::factory($body);
$this->removeHeader('Content-Length');
if ($contentType) {
$this->setHeader('Content-Type', (string) $contentType);
}
// Always add the Expect 100-Continue header if the body cannot be rewound. This helps with redirects.
if (!$this->body->isSeekable() && $this->expectCutoff !== false) {
$this->setHeader('Expect', '100-Continue');
}
if ($tryChunkedTransfer) {
$this->setHeader('Transfer-Encoding', 'chunked');
} else {
$this->removeHeader('Transfer-Encoding');
// Set the Content-Length header if it can be determined
$size = $this->body->getContentLength();
if ($size !== null && $size !== false) {
$this->setHeader('Content-Length', $size);
if ($size > $this->expectCutoff) {
$this->setHeader('Expect', '100-Continue');
}
} elseif ('1.1' == $this->protocolVersion) {
$this->setHeader('Transfer-Encoding', 'chunked');
} else {
throw new RequestException('Cannot determine Content-Length and cannot use chunked Transfer-Encoding when using HTTP/1.0');
}
}
return $this;
}
开发者ID:unkerror,项目名称:Budabot,代码行数:33,代码来源:EntityEnclosingRequest.php
示例15: setBody
public function setBody($body, $contentType = null)
{
$this->body = EntityBody::factory($body);
// Auto detect the Content-Type from the path of the request if possible
if ($contentType === null && !$this->hasHeader('Content-Type')) {
$contentType = $this->body->getContentType() ?: Mimetypes::getInstance()->fromFilename($this->getPath());
}
if ($contentType) {
$this->setHeader('Content-Type', $contentType);
}
// Always add the Expect 100-Continue header if the body cannot be rewound. This helps with redirects.
if (!$this->body->isSeekable() && $this->expectCutoff !== false) {
$this->setHeader('Expect', '100-Continue');
}
// Set the Content-Length header if it can be determined
$size = $this->body->getContentLength();
if ($size !== null && $size !== false) {
$this->setHeader('Content-Length', $size);
if ($size > $this->expectCutoff) {
$this->setHeader('Expect', '100-Continue');
}
} elseif (!$this->hasHeader('Content-Length')) {
if ('1.1' == $this->protocolVersion) {
$this->setHeader('Transfer-Encoding', 'chunked');
} else {
throw new RequestException('Cannot determine Content-Length and cannot use chunked Transfer-Encoding when using HTTP/1.0');
}
}
return $this;
}
开发者ID:diandianxiyu,项目名称:Yii2Api,代码行数:30,代码来源:EntityEnclosingRequest.php
示例16: create
/**
* {@inheritdoc}
*/
public function create($method, $url, $headers = null, $body = null)
{
$method = strtoupper($method);
if ($method == 'GET' || $method == 'HEAD' || $method == 'TRACE' || $method == 'OPTIONS') {
$c = $this->requestClass;
$request = new $c($method, $url, $headers);
if ($body) {
// The body is where the response body will be stored
$request->setResponseBody(EntityBody::factory($body));
}
return $request;
}
$c = $this->entityEnclosingRequestClass;
$request = new $c($method, $url, $headers);
if ($body) {
$isChunked = (string) $request->getHeader('Transfer-Encoding') == 'chunked';
if ($method == 'POST' && (is_array($body) || $body instanceof Collection)) {
// Normalize PHP style cURL uploads with a leading '@' symbol
foreach ($body as $key => $value) {
if (is_string($value) && substr($value, 0, 1) == '@') {
$request->addPostFile($key, $value);
unset($body[$key]);
}
}
// Add the fields if they are still present and not all files
$request->addPostFields($body);
} elseif (is_resource($body) || $body instanceof EntityBody) {
$request->setBody($body, (string) $request->getHeader('Content-Type'), $isChunked);
} else {
$request->setBody((string) $body, (string) $request->getHeader('Content-Type'), $isChunked);
}
}
return $request;
}
开发者ID:Frinstio,项目名称:AlfredWorkflow.com,代码行数:37,代码来源:RequestFactory.php
示例17: getResponse
private function getResponse(array $headers = array(), $body = '', $status = 200)
{
$data = array('Body' => \Guzzle\Http\EntityBody::factory($body));
foreach ($headers as $header => $value) {
$data[str_replace('-', '', $header)] = $value;
}
return new \Guzzle\Service\Resource\Model($data);
}
开发者ID:dotsunited,项目名称:cabinet,代码行数:8,代码来源:AmazonS3AdapterTest.php
示例18: setUp
public function setUp()
{
$this->mockRequest = new \Guzzle\Plugin\Mock\MockPlugin();
$body = \Guzzle\Http\EntityBody::fromString($this->responseBodyString);
$this->mockRequest->addResponse(new Guzzle\Http\Message\Response(200, $this->responseHeaders, $body));
$this->client = $this->getClientInstance();
$this->client->addClientSubscriber($this->mockRequest);
}
开发者ID:digitaldevelopers,项目名称:merchant-esolutions-php,代码行数:8,代码来源:TestAbstract.php
示例19: save
public static function save($file_path, $file_name = null, $upload_type = 'img', $is_private_acl = false)
{
if (!file_exists($file_path)) {
throw new FuelException('File not exists.');
}
static::set_s3_instanse();
return self::$s3_instantse->putObject(array('Bucket' => FBD_AWS_S3_BUCKET, 'Key' => static::get_key($file_name ?: \Site_Upload::get_file_name_from_file_path($file_path), $upload_type), 'Body' => EntityBody::factory(fopen($file_path, 'r')), 'ACL' => $is_private_acl ? CannedAcl::PRIVATE_ACCESS : CannedAcl::PUBLIC_READ));
}
开发者ID:uzura8,项目名称:flockbird,代码行数:8,代码来源:s3.php
示例20: testHasChainableSetterMethods
public function testHasChainableSetterMethods()
{
$client = $this->getServiceBuilder()->get('s3');
$body = EntityBody::factory('foo');
$b = $this->mockBuilder->resumeFrom('foo')->setClient($client)->setSource($body)->setHeaders(array('Foo' => 'Bar'));
$this->assertEquals('foo', $this->readAttribute($b, 'state'));
$this->assertSame($client, $this->readAttribute($b, 'client'));
$this->assertSame($body, $this->readAttribute($b, 'source'));
}
开发者ID:romainneutron,项目名称:aws-sdk-php,代码行数:9,代码来源:AbstractUploadBuilderTest.php
注:本文中的Guzzle\Http\EntityBody类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论