private function checkTransFile($mothed, $args) { if (ucfirst($mothed) === 'PutObject' || ucfirst($mothed) === 'UploadPart') { if (array_key_exists('SourceFile', $args[0]) && array_key_exists('Body', $args[0])) { throw new OnlyBodyOrFileException(); } if (!array_key_exists('SourceFile', $args[0]) || array_key_exists('Body', $args[0])) { return false; } if (!array_key_exists('Bucket', $args[0]) || !array_key_exists('Key', $args[0])) { return false; } if (ucfirst($mothed) === 'UploadPart' && (!array_key_exists('PartNumber', $args[0]) || !array_key_exists('UploadId', $args[0]))) { return false; } if (array_key_exists('ContentLength', $args[0]) && (int) $args[0]['ContentLength'] <= 0) { return false; } if (!file_exists($args[0]['SourceFile'])) { return false; } if (ucfirst($mothed) === 'PutObject') { include_once 'Obs/S3/Model/MultipartUpload/SetObjectHead.php'; $head = new \SetObjectHead(); if ($head->getFileSize($args[0]['SourceFile']) > 524288000) { return true; } } if (!array_key_exists('ContentLength', $args[0])) { include_once 'Obs/S3/Model/MultipartUpload/SetObjectHead.php'; $head = new \SetObjectHead(); $body = new Stream(fopen($args[0]['SourceFile'], 'rb')); if ($head->getFileSize($args[0]['SourceFile']) === $body->getSize()) { return false; } } return true; } return false; }
/** * @covers Guzzle\Stream\Stream::getSize * @covers Guzzle\Stream\Stream::__construct */ public function testGetSize() { $size = filesize(__DIR__ . '/../../../bootstrap.php'); $handle = fopen(__DIR__ . '/../../../bootstrap.php', 'r'); $stream = new Stream($handle); $this->assertEquals($handle, $stream->getStream()); $this->assertEquals($size, $stream->getSize()); $this->assertEquals($size, $stream->getSize()); unset($stream); // Make sure that false is returned when the size cannot be determined $this->getServer()->enqueue("HTTP/1.1 200 OK\r\nContent-Length: 0\r\n\r\n"); $handle = fopen('http://localhost:' . $this->getServer()->getPort(), 'r'); $stream = new Stream($handle); $this->assertEquals(false, $stream->getSize()); unset($stream); }
public function testEnsuresSizeIsConsistent() { $h = fopen('php://temp', 'r+'); fwrite($h, 'foo'); $stream = new Stream($h); $this->assertEquals(3, $stream->getSize()); $stream->write('test'); $this->assertEquals(7, $stream->getSize()); fclose($h); }