コード例 #1
0
 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());
     }
 }
コード例 #2
0
 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);
 }
コード例 #3
0
 /**
  * {@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;
 }
コード例 #4
0
ファイル: Utils.php プロジェクト: bobozhangshao/HeartCare
 /**
  * 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;
 }
コード例 #5
0
 /**
  * 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;
 }
コード例 #6
0
 public function eof()
 {
     return $this->stream->eof();
 }
コード例 #7
0
ファイル: GuzzleHttpStream.php プロジェクト: lamenath/fbp
 /**
  * {@inheritdoc}
  */
 protected function doEof()
 {
     return $this->stream->eof();
 }