@@ -40,6 +40,9 @@ class RendererModel
4040 /** @var int $duration print duration in milliseconds */
4141 public $ duration ;
4242
43+ /** @var int $pause pause duration between lines in milliseconds */
44+ public $ pause ;
45+
4346 /** @var string $fontCSS CSS required for displaying the selected font */
4447 public $ fontCSS ;
4548
@@ -60,7 +63,8 @@ class RendererModel
6063 "width " => "400 " ,
6164 "height " => "50 " ,
6265 "multiline " => "false " ,
63- "duration " => "5000 "
66+ "duration " => "5000 " ,
67+ "pause " => "0 " ,
6468 );
6569
6670 /**
@@ -78,13 +82,14 @@ public function __construct($template, $params, $database)
7882 $ this ->font = $ this ->checkFont ($ params ["font " ] ?? $ this ->DEFAULTS ["font " ]);
7983 $ this ->color = $ this ->checkColor ($ params ["color " ] ?? $ this ->DEFAULTS ["color " ], "color " );
8084 $ this ->background = $ this ->checkColor ($ params ["background " ] ?? $ this ->DEFAULTS ["background " ], "background " );
81- $ this ->size = $ this ->checkNumber ($ params ["size " ] ?? $ this ->DEFAULTS ["size " ], "Font size " );
85+ $ this ->size = $ this ->checkNumberPositive ($ params ["size " ] ?? $ this ->DEFAULTS ["size " ], "Font size " );
8286 $ this ->center = $ this ->checkBoolean ($ params ["center " ] ?? $ this ->DEFAULTS ["center " ]);
8387 $ this ->vCenter = $ this ->checkBoolean ($ params ["vCenter " ] ?? $ this ->DEFAULTS ["vCenter " ]);
84- $ this ->width = $ this ->checkNumber ($ params ["width " ] ?? $ this ->DEFAULTS ["width " ], "Width " );
85- $ this ->height = $ this ->checkNumber ($ params ["height " ] ?? $ this ->DEFAULTS ["height " ], "Height " );
88+ $ this ->width = $ this ->checkNumberPositive ($ params ["width " ] ?? $ this ->DEFAULTS ["width " ], "Width " );
89+ $ this ->height = $ this ->checkNumberPositive ($ params ["height " ] ?? $ this ->DEFAULTS ["height " ], "Height " );
8690 $ this ->multiline = $ this ->checkBoolean ($ params ["multiline " ] ?? $ this ->DEFAULTS ["multiline " ]);
87- $ this ->duration = $ this ->checkNumber ($ params ["duration " ] ?? $ this ->DEFAULTS ["duration " ], "duration " );
91+ $ this ->duration = $ this ->checkNumberPositive ($ params ["duration " ] ?? $ this ->DEFAULTS ["duration " ], "duration " );
92+ $ this ->pause = $ this ->checkNumberNonNegative ($ params ["pause " ] ?? $ this ->DEFAULTS ["pause " ], "pause " );
8893 $ this ->fontCSS = $ this ->fetchFontCSS ($ this ->font );
8994 }
9095
@@ -136,13 +141,13 @@ private function checkColor($color, $field)
136141 }
137142
138143 /**
139- * Validate numeric parameter and return valid integer
144+ * Validate positive numeric parameter and return valid integer
140145 *
141146 * @param string $num Parameter to validate
142147 * @param string $field Field name for displaying in case of error
143148 * @return int Sanitized digits and int
144149 */
145- private function checkNumber ($ num , $ field )
150+ private function checkNumberPositive ($ num , $ field )
146151 {
147152 $ digits = intval (preg_replace ("/[^0-9\-]/ " , "" , $ num ));
148153 if ($ digits <= 0 ) {
@@ -151,6 +156,22 @@ private function checkNumber($num, $field)
151156 return $ digits ;
152157 }
153158
159+ /**
160+ * Validate non-negative numeric parameter and return valid integer
161+ *
162+ * @param string $num Parameter to validate
163+ * @param string $field Field name for displaying in case of error
164+ * @return int Sanitized digits and int
165+ */
166+ private function checkNumberNonNegative ($ num , $ field )
167+ {
168+ $ digits = intval (preg_replace ("/[^0-9\-]/ " , "" , $ num ));
169+ if ($ digits < 0 ) {
170+ throw new InvalidArgumentException ("$ field must be a non-negative number. " );
171+ }
172+ return $ digits ;
173+ }
174+
154175 /**
155176 * Validate "true" or "false" value as string and return boolean
156177 *
0 commit comments