/** * {@inheritdoc} */ protected function read($length = null) { if (is_null($length)) { return trim(Utils::readLine($this->inputStream)); } return $this->inputStream->read($length); }
private function matchesHash(CompleteEvent $event, $hash, StreamInterface $body) { $body->seek(0); while (!$body->eof()) { $this->hash->update($body->read(16384)); } $result = $this->hash->complete(); if ($hash !== $result) { throw new MessageIntegrityException(sprintf('Message integrity check failure. Expected "%s" but' . ' got "%s"', $hash, $result), $event->getRequest(), $event->getResponse()); } }
function it_listens_to_events(StreamInterface $inputStream, StreamInterface $outputStream) { $handler = new Handler(); $header = ''; $inputStream->eof()->willReturn(false); $inputStream->read(1)->will(function ($args) use(&$header) { if (empty($header)) { $header = str_split("ver:3.0 server:supervisor serial:21 pool:listener poolserial:10 eventname:PROCESS_COMMUNICATION_STDOUT len:86\n"); return "\n"; } return array_shift($header); }); $inputStream->read(86)->will(function ($args) use(&$header) { $header = str_split("ver:3.0 server:supervisor serial:21 pool:listener poolserial:10 eventname:PROCESS_COMMUNICATION_STDOUT len:86\n"); return "processname:foo groupname:bar pid:123\nThis is the data that was sent between the tags"; }); $outputStream->write("READY\n")->shouldBeCalledTimes(4); $outputStream->write("RESULT 2\nOK")->shouldBeCalled(); $outputStream->write("RESULT 4\nFAIL")->shouldBeCalled(); $this->listen($handler); }
/** * {@inheritdoc} */ protected function readNext() { $line = null; $stream = Stream::factory(); while (!$this->stream->eof()) { $line = $this->readLine(); if ($this->isBoundary($line)) { break; } if ($this->isLastBoundary($line)) { // read last bytes $this->stream->read(2); break; } $stream->write("\r\n" . $line); } if ($line === null) { return; } $stream->seek(0); return $stream; }
/** * Read a line from the stream up to the maximum allowed buffer length * * @param StreamInterface $stream Stream to read from * @param int $maxLength Maximum buffer length * * @return string|bool */ public static function readline(StreamInterface $stream, $maxLength = null) { $buffer = ''; $size = 0; while (!$stream->eof()) { if (false === ($byte = $stream->read(1))) { return $buffer; } $buffer .= $byte; // Break when a new line is found or the max length - 1 is reached if ($byte == PHP_EOL || ++$size == $maxLength - 1) { break; } } return $buffer; }
/** * Read a line from the stream up to the maximum allowed buffer length * * @param StreamInterface $stream Stream to read from * @param int $maxLength Maximum buffer length * @param string $eol Line ending * * @return string|bool */ public static function readline(StreamInterface $stream, $maxLength = null, $eol = PHP_EOL) { $buffer = ''; $size = 0; $negEolLen = -strlen($eol); while (!$stream->eof()) { if (false === ($byte = $stream->read(1))) { return $buffer; } $buffer .= $byte; // Break when a new line is found or the max length - 1 is reached if (++$size == $maxLength || substr($buffer, $negEolLen) === $eol) { break; } } return $buffer; }
public function read($length) { return $this->stream->read($length); }
/** * {@inheritdoc} */ protected function doRead($length) { return $this->stream->read($length); }