React\HttpClient\Request::write PHP Méthode

write() public méthode

public write ( $data )
    public function write($data)
    {
        if (!$this->isWritable()) {
            return;
        }
        if (self::STATE_HEAD_WRITTEN <= $this->state) {
            return $this->stream->write($data);
        }
        if (!count($this->pendingWrites)) {
            $this->on('headers-written', function ($that) {
                foreach ($that->pendingWrites as $pw) {
                    $that->write($pw);
                }
                $that->pendingWrites = array();
                $that->emit('drain', array($that));
            });
        }
        $this->pendingWrites[] = $data;
        if (self::STATE_WRITING_HEAD > $this->state) {
            $this->writeHead();
        }
        return false;
    }

Usage Example

 /** @test */
 public function writeWithAPostRequestShouldSendToTheStream()
 {
     $requestData = new RequestData('POST', 'http://www.example.com');
     $request = new Request($this->loop, $this->connector, $requestData);
     $this->successfulConnectionMock();
     $this->stream->expects($this->at(4))->method('write')->with($this->matchesRegularExpression("#^POST / HTTP/1\\.0\r\nHost: www.example.com\r\nUser-Agent:.*\r\n\r\n\$#"));
     $this->stream->expects($this->at(5))->method('write')->with($this->identicalTo("some"));
     $this->stream->expects($this->at(6))->method('write')->with($this->identicalTo("post"));
     $this->stream->expects($this->at(7))->method('write')->with($this->identicalTo("data"));
     $factory = $this->createCallableMock();
     $factory->expects($this->once())->method('__invoke')->will($this->returnValue($this->response));
     $request->setResponseFactory($factory);
     $request->write("some");
     $request->write("post");
     $request->end("data");
     $request->handleData("HTTP/1.0 200 OK\r\n");
     $request->handleData("Content-Type: text/plain\r\n");
     $request->handleData("\r\nbody");
 }