PluginProbe
404 Solution / trunk
404 Solution vtrunk
4.3.5 4.3.4 4.3.3 4.3.2 4.3.1 4.3.0 4.2.0 4.1.19 4.1.18 4.1.17 4.1.16 4.1.15 4.1.13 4.1.12 4.1.11 4.1.10 4.1.9 4.1.8 4.1.7 4.1.6 4.1.5 4.1.4 4.1.3 trunk 2.30.0 All 109 releases
404-solution / includes / services / PerPageOptionUpdater.php

PerPageOptionUpdater.php in 404 Solution trunk, at includes/services/PerPageOptionUpdater.php

48 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 if (!defined('ABSPATH')) {
4 exit;
5 }
6
7 /**
8 * Clamps and persists the admin table rows-per-page preference.
9 *
10 * Shared by the admin action facade and AJAX pagination paths so every caller
11 * applies the same min/max bounds before writing the options row.
12 */
13 class ABJ_404_Solution_PerPageOptionUpdater {
14
15 /**
16 * @param int $rows Requested number of rows per page.
17 * @return void
18 */
19 public function update(int $rows): void {
20 $tracer = ABJ_404_Solution_OptionPersistenceTracer::begin();
21 try {
22 $normalization = static function () use ($rows): int {
23 $showRows = max($rows, ABJ404_OPTION_MIN_PERPAGE);
24 return min($showRows, ABJ404_OPTION_MAX_PERPAGE);
25 };
26 $showRows = $tracer === null
27 ? $normalization()
28 : $tracer->traceOperation('rows_per_page_normalization', $normalization);
29
30 $optionsRead = static function () {
31 $repository = abj_service('options_repository');
32 return array($repository, $repository->getOptions());
33 };
34 $resolved = $tracer === null
35 ? $optionsRead()
36 : $tracer->traceOperation('options_read', $optionsRead);
37 $repository = $resolved[0];
38 $options = $resolved[1];
39 $options['perpage'] = $showRows;
40 $repository->updateOptions($options);
41 } finally {
42 if ($tracer !== null) {
43 $tracer->finish();
44 }
45 }
46 }
47 }
48