MacroPageMiddleware.php 750 B

12345678910111213141516171819202122232425262728
  1. <?php
  2. declare(strict_types=1);
  3. namespace SixShop\System\Middleware;
  4. use Closure;
  5. use SixShop\Core\Request;
  6. use think\Exception;
  7. use think\Response;
  8. /**
  9. * @deprecated
  10. */
  11. class MacroPageMiddleware
  12. {
  13. public function handle(Request $request, Closure $next): Response
  14. {
  15. $request->macro('pageAndLimit', function (): array {
  16. $page = $this->get('page/d', 1);
  17. $limit = $this->get('limit/d', $this->get('per_page/d', 10));
  18. throw_if($page < 1, Exception::class, '页码不能小于1');
  19. throw_if($limit < 1 || $limit > 200, Exception::class, '每页数量必须在1-200之间');
  20. return ['page' => $page, 'list_rows' => $limit];
  21. });
  22. return $next($request);
  23. }
  24. }