/** * @param LineBuffer $buffer * @param int $indent * @param string $firstPrefix */ public function addBuffer(LineBuffer $buffer, $indent = 0, $firstPrefix = '') { $first = true; foreach ($buffer->getLines() as $line) { $newline = null; if ($first) { $first = false; $newline = new Line($line->hasMatched(), $firstPrefix . $line->getText(), $line->getMarker()); $newline->setExtraIndent(max(0, $indent - strlen($firstPrefix))); } else { $newline = $line; $newline->setExtraIndent($indent); } $this->lines[] = $newline; } }
/** * Calls the callback for each line in the text * * @param string $text Text * @param callable $callback Callback */ public static function lines($text, callable $callback) { $buffer = new LineBuffer($callback); $buffer->input($text); $buffer->flush(); }