Phly\Http\Stream::write PHP Method

write() public method

public write ( $string )
    public function write($string)
    {
        if (!$this->resource) {
            throw new RuntimeException('No resource available; cannot write');
        }
        $result = fwrite($this->resource, $string);
        if (false === $result) {
            throw new RuntimeException('Error writing to stream');
        }
        return $result;
    }

Usage Example

Beispiel #1
0
 public function testSerializesRequestWithBody()
 {
     $body = json_encode(['test' => 'value']);
     $stream = new Stream('php://memory', 'wb+');
     $stream->write($body);
     $request = (new Request())->withMethod('POST')->withUri(new Uri('http://example.com/foo/bar'))->withAddedHeader('Accept', 'application/json')->withAddedHeader('Content-Type', 'application/json')->withBody($stream);
     $message = Serializer::toString($request);
     $this->assertContains("POST /foo/bar HTTP/1.1\r\n", $message);
     $this->assertContains("\r\n\r\n" . $body, $message);
 }
All Usage Examples Of Phly\Http\Stream::write