コード例 #1
0
 /**
  * Handle body to stream object.
  *
  * @param   string  $body  The body data.
  *
  * @return  StreamInterface  Converted to stream object.
  */
 protected function handleBody($body)
 {
     $stream = new Stream('php://memory', 'rw+');
     $stream->write($body);
     $stream->rewind();
     return $stream;
 }
コード例 #2
0
 /**
  * Handle body to stream object.
  *
  * @param   string  $body  The body data.
  *
  * @return  StreamInterface  Converted to stream object.
  */
 protected function handleBody($body)
 {
     if (is_string($body)) {
         $stream = new Stream('php://temp', 'wb+');
         $stream->write($body);
         $stream->rewind();
         $body = $stream;
     }
     if (!$body instanceof StreamInterface) {
         throw new \InvalidArgumentException(sprintf('Invalid body content type %s, please provide string or StreamInterface', gettype($body)));
     }
     return $body;
 }
コード例 #3
0
 /**
  * testMoveInNotCli
  *
  * @return  void
  */
 public function testMoveInNotCli()
 {
     // Send stream
     $stream = new Stream('php://temp', 'wb+');
     $stream->write('Foo bar!');
     $upload = new UploadedFile($stream, 0, UPLOAD_ERR_OK);
     $upload->setSapi('cgi');
     $this->tmpFile = $to = sys_get_temp_dir() . '/windwalker-' . uniqid();
     $this->assertFalse(is_file($to));
     $upload->moveTo($to);
     $this->assertTrue(is_file($to));
     $contents = file_get_contents($to);
     $this->assertEquals($stream->__toString(), $contents);
     // Send string
     $uploadFile = sys_get_temp_dir() . '/upload-' . uniqid();
     file_put_contents($uploadFile, 'Foo bar!');
     $upload = new UploadedFile($uploadFile, 0, UPLOAD_ERR_OK);
     $upload->setSapi('cgi');
     $this->tmpFile = $to = sys_get_temp_dir() . '/windwalker-' . uniqid();
     $this->assertFalse(is_file($to));
     $this->assertExpectedException(function () use($upload, $to) {
         $upload->moveTo($to);
     }, 'RuntimeException', 'Error moving uploaded file');
 }
コード例 #4
0
 /**
  * Method to test write().
  *
  * @return void
  *
  * @covers \Windwalker\Http\Stream::write
  */
 public function testWrite()
 {
     $this->createTempFile();
     $resource = fopen($this->tmpnam, Stream::MODE_READ_WRITE_RESET);
     $stream = new Stream($resource);
     $stream->write('flower');
     $this->assertEquals('flower', file_get_contents($this->tmpnam));
     $stream->write(' bloom');
     $this->assertEquals('flower bloom', file_get_contents($this->tmpnam));
     $stream->seek(4);
     $stream->write('test');
     $this->assertEquals('flowtestloom', file_get_contents($this->tmpnam));
 }