Пример #1
0
 /**
  * @dataProvider getReadUntilLineBreakData
  */
 public function testReadUntilLineBreak($content, array $lines, $remain)
 {
     $buffer = new Buffer();
     $buffer->append($content);
     foreach ($lines as $line) {
         $this->assertEquals($line, $buffer->readUntilLineBreak());
     }
     $this->assertEquals($remain, $buffer->getContent());
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function readLine($removeLineBreak = false)
 {
     if (null === $this->getResource() && $this->buffer->isEmpty()) {
         throw new ReadingFinishedException();
     }
     while (true) {
         if (null !== $this->getResource()) {
             $this->buffer->append(fread($this->getResource(), $this->chunkSize));
             if (feof($this->getResource())) {
                 $this->close();
             }
         }
         if ($this->buffer->hasLineBreak()) {
             $line = $this->buffer->readUntilLineBreak();
             return $removeLineBreak ? $line : $line . $this->buffer->getLastLineBreak();
         }
         if (null === $this->getResource()) {
             $remain = $this->buffer->getContent();
             $this->buffer->clear();
             return $remain;
         }
     }
 }