@@ -1173,6 +1173,7 @@ public function __construct( $options=null ) {
11731173
11741174 $ this ->backgroundText = ErrorHandler::optionsPop ( $ options , 'background_text ' , '' );
11751175 $ this ->numLines = ErrorHandler::optionsPop ( $ options , 'snippet_num_lines ' , ErrorHandler::NUM_FILE_LINES );
1176+ $ this ->displayLineNumber = ErrorHandler::optionsPop ( $ options , 'display_line_numbers ' , false );
11761177
11771178 $ this ->classNotFoundException = null ;
11781179
@@ -2925,6 +2926,11 @@ function() use (
29252926 $ fileLines = $ fileLinesSet ->getLines ();
29262927 $ show = $ fileLinesSet ->isShown ();
29272928 $ highlightLine = $ fileLinesSet ->getLine ();
2929+
2930+ // calculate last line number length
2931+ end ($ fileLines );
2932+ $ maxLineNumber = key ($ fileLines );
2933+ $ lineDecimals = strlen ($ maxLineNumber );
29282934 ?>
29292935 <div id="<?php echo $ id ?> " class="error-file-lines <?php echo $ show ? 'show ' : '' ?> ">
29302936 <?php
@@ -2939,7 +2945,17 @@ function() use (
29392945 $ line = " $ line " ;
29402946 }
29412947
2942- ?> <div <?php echo $ style ?> class="error-file-line <?php echo ($ lineNum === $ highlightLine ) ? 'highlight ' : '' ?> "><?php echo $ line ?> </div><?php
2948+ if ($ this ->displayLineNumber ) {
2949+ $ lineNumLabel = str_replace (' ' , ' ' , sprintf ("% {$ lineDecimals }d " , $ lineNum ));
2950+ } else {
2951+ $ lineNumLabel = '' ;
2952+ }
2953+
2954+ ?> <div <?php echo $ style ?> class="error-file-line <?php echo ($ lineNum === $ highlightLine ) ? 'highlight ' : '' ?> ">
2955+ <span class="error-file-line-number"><?php echo $ lineNumLabel ?> </span>
2956+ <span class="error-file-line-content"><?php echo $ line ?> </span>
2957+ </div>
2958+ <?php
29432959 }
29442960 ?>
29452961 </div>
0 commit comments