makedo/php-paginator 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

makedo/php-paginator

Composer 安装命令:

composer require makedo/php-paginator

包简介

Data source independent paginator for php

README 文档

README

This is yet another paginator for php. Main idea of this package is to build data source independent paginator, which has an ability to work in several modes:

  • Count skip by id

        $loader = function (int $limit, int $skip): iterable
        {
            //SELECT * from users  WHERE id > $skip LIMIT $limit
        };
        
        $perPage = 100;
        $lastIdOnPreviousPage = 34;
        
        $paginatorFactory = new SkipById($perPage);
      
        $page = $paginatorFactory
            ->createPaginator(new CallableLoader($loader), $lastIdOnPreviousPage)
            ->paginate()
        ;

    In this example you have an ability use id as skip value. As you can see, Loader function accepts id in $skip variable. It should be id of last item on previous page and it comes from client side. For 1st page it should be 0. For $page->hasNext paginator will load $perPage + 1 item, and then check if actual count of loaded items is more than $perPage.

    Optionally, you can set $currentPage value, which will be set to $page->currentPage.

  • Count skip by id with total count

       $loader = function (int $limit, int $skip): iterable {
           //SELECT * from users  WHERE id > $skip LIMIT
       };
      
       $counter = function (): int {
           //SELECT count(id) from users
       };
       
       $perPage = 100;
       $lastIdOnPreviousPage = 35;
       
       $paginatorFactory = new SkipByIdCountable($perPage);
       $page = $paginatorFactory
           ->createPaginator(
               new CallableLoader($loader),
               new CallableCounter($counter),
               $lastIdOnPreviousPage
           )
           ->paginate()
       ;

    In above example paginator counts skip by id and uses total count for $page->total, $page->totalPages values. For $page->hasNext paginator will load $perPage + 1 item, and then check if actual count of loaded items is more than $perPage.

  • Count skip by id with total count and current page

       $loader = function (int $limit, int $skip): iterable {
           //SELECT * from users  WHERE id > $skip LIMIT
       };
      
       $counter = function (): int {
           //SELECT count(id) from users
       };
       
       $perPage = 100;
       $lastIdOnPreviousPage = 35;
       $currentPage = 4;
       
       $paginatorFactory = new SkipByIdCountable($perPage);
       $page = $paginatorFactory
           ->createPaginator(
               new CallableLoader($loader),
               new CallableCounter($counter),
               $lastIdOnPreviousPage,
               $currentPage
           )
           ->paginate()
       ;

    In above example paginator counts skip by id and uses total count for $page->total, $page->totalPages, $page->hasNext values. In this case, we know $currentPage value, which in real case comes from client, so we can use total count and $currentPage for counting $page->hasNext except using $perPage + 1 strategy.

  • Count skip by offset

    $loader = function (int $limit, int $skip): iterable
    {
        //SELECT * from users LIMIT $limit OFFSET $skip
    };
    
    $perPage = 100;
    $currentPage = 2;
    
    $paginatorFactory = new SkipByOffset($perPage);
    
    $page = $paginatorFactory
        ->createPaginator(new CallableLoader($loader), $currentPage)
        ->paginate()
    ;

    In above example paginator counts skip as offset according to $perPage and $currentPage values. For counting $page->hasNext paginator will load $perPage + 1 item, and then check if actual count of loaded items is more than $perPage.

    • Count skip by offset and use total count

         $loader = function (int $limit, int $skip): iterable {
             //SELECT * from users LIMIT $limit OFFSET $skip
         };
        
         $counter = function (): int {
             //SELECT count(id) from users
         };
         
         $perPage = 100;
         $currentPage = 2;
         
         $paginatorFactory = new SkipByOffsetCountable($perPage);
      
         $page = $paginatorFactory
             ->createPaginator(new CallableLoader($loader), new CallableCounter($counter), $currentPage)
             ->paginate()
         ;

      In above example paginator counts skip by offset and uses total count for $page->total, $page->totalPages, $page->hasNext values.

makedo/php-paginator 适用场景与选型建议

makedo/php-paginator 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 12 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 09 月 03 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 makedo/php-paginator 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 makedo/php-paginator 我们能提供哪些服务?
定制开发 / 二次开发

基于 makedo/php-paginator 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 12
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 4
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2019-09-03