@@ -202,9 +202,19 @@ class PageIndex implements \Stringable
202202 * "url;start=offset". Default: false.
203203 * @param bool $show_prevnext Whether the Previous and Next links should be
204204 * shown. Default: true.
205+ * @param array|null $templateOverrides Array of template strings to override defaults.
206+ * Supported keys: extra_before, previous_page, current_page, page,
207+ * expand_pages, next_page, extra_after.
205208 */
206- public function __construct (string $ base_url , int &$ start , int $ max_value , int $ num_per_page , bool $ short_format = false , bool $ show_prevnext = true )
207- {
209+ public function __construct (
210+ string $ base_url ,
211+ int &$ start ,
212+ int $ max_value ,
213+ int $ num_per_page ,
214+ bool $ short_format = false ,
215+ bool $ show_prevnext = true ,
216+ ?array $ templateOverrides = null
217+ ) {
208218 $ this ->base_url = $ base_url ;
209219 $ this ->max_value = $ max_value ;
210220 $ this ->num_per_page = $ num_per_page ;
@@ -225,6 +235,15 @@ public function __construct(string $base_url, int &$start, int $max_value, int $
225235 if (!isset (Utils::$ context ['current_page ' ])) {
226236 Utils::$ context ['current_page ' ] = $ this ->start / $ this ->num_per_page ;
227237 }
238+
239+ // Override templates if provided
240+ if ($ templateOverrides ) {
241+ foreach ($ templateOverrides as $ key => $ value ) {
242+ if (property_exists ($ this , $ key )) {
243+ $ this ->{$ key } = $ value ;
244+ }
245+ }
246+ }
228247 }
229248
230249 /**
@@ -276,11 +295,32 @@ public function __toString(): string
276295 /**
277296 * Static wrapper for constructor.
278297 *
298+ * @param string $base_url The basic URL to be used for each link.
299+ * @param int &$start The start position, by reference. If this is not a
300+ * multiple of the number of items per page, it is sanitized to be so and
301+ * the value will persist upon the function's return.
302+ * @param int $max_value The total number of items you are paginating for.
303+ * @param int $num_per_page The number of items to be displayed on a given
304+ * page. $start will be forced to be a multiple of this value.
305+ * @param bool $short_format Whether to use "url.offset" instead of
306+ * "url;start=offset". Default: false.
307+ * @param bool $show_prevnext Whether the Previous and Next links should be
308+ * shown. Default: true.
309+ * @param array|null $templateOverrides Array of template strings to override defaults.
310+ * Supported keys: extra_before, previous_page, current_page, page,
311+ * expand_pages, next_page, extra_after.
279312 * @return self An instance of this class.
280313 */
281- public static function load (string $ base_url , int &$ start , int $ max_value , int $ num_per_page , bool $ short_format = false , bool $ show_prevnext = true ): self
282- {
283- return new self ($ base_url , $ start , $ max_value , $ num_per_page , $ short_format , $ show_prevnext );
314+ public static function load (
315+ string $ base_url ,
316+ int &$ start ,
317+ int $ max_value ,
318+ int $ num_per_page ,
319+ bool $ short_format = false ,
320+ bool $ show_prevnext = true ,
321+ ?array $ templateOverrides = null
322+ ): self {
323+ return new self ($ base_url , $ start , $ max_value , $ num_per_page , $ short_format , $ show_prevnext , $ templateOverrides );
284324 }
285325
286326 /******************
0 commit comments