/** * 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; }
/** * 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; }
/** * Method to test read(). * * @return void * * @covers \Windwalker\Http\Stream::read */ public function testRead() { $this->createTempFile(); file_put_contents($this->tmpnam, 'FOO BAR'); $resource = fopen($this->tmpnam, Stream::MODE_READ_ONLY_FROM_BEGIN); $stream = new Stream($resource); $this->assertEquals('FO', $stream->read(2)); $this->assertEquals('O B', $stream->read(3)); $stream->rewind(); $this->assertEquals('FOO', $stream->read(3)); }