somework/offset-page-logic
Composer 安装命令:
composer require somework/offset-page-logic
包简介
Utility functions to convert offset/limit requests into page/page-size arguments
README 文档
README
Author: Igor Pinchuk Email: i.pinchuk.work@gmail.com
Utility functions to convert offset/limit requests into page/page-size arguments.
Installation
Install the package via Composer:
composer require somework/offset-page-logic
Usage
Offset::logic() returns a DTO containing the calculated page (1-based) and page size
for the given offset and limit. The method also guards against requesting more
rows than are available. All inputs are strict integers; negative values are coerced to
0.
Behavior
Offset::logic() branches through several scenarios to normalize offset/limit inputs
into page-based pagination:
- Zeroed inputs – if
offset,limit, andnowCountare all0, the method returns page0and size0, representing a request for “everything” without pagination. - Limit-only – with
offsetat0, a positivelimitsets the page size while the page is1. - Offset-only – with
limitat0, a positiveoffsetyields page2and a size ofoffset + nowCount(the offset is always at least the page size). - Limit exceeds current count – when
nowCountis positive and smaller than the requestedlimit, the method recurses by subtractingnowCountfromlimitand adding it tooffset, then resolves the pagination with the remaining values. - Standard offset/limit division – when both are positive and
nowCountis0, the page and size are derived fromoffsetdivided bylimit, using the largest divisor of the offset to maximize page size. AlreadyGetNeededCountExceptioncondition – ifnowCountis positive and not less than the requestedlimit, the method throwsAlreadyGetNeededCountExceptionto signal that all required rows are already retrieved.
| Offset | Limit | nowCount | Outcome | Notes |
|---|---|---|---|---|
0 |
0 |
0 |
Page 0, Size 0 |
Zeroed inputs return a sentinel “all rows” response. |
0 |
10 |
0 |
Page 1, Size 10 |
Limit-only scenario with a page starting at 1. |
22 |
0 |
0 |
Page 2, Size 22 |
Offset-only scenario; size grows with the offset. |
0 |
22 |
10 |
Page 2, Size 10 |
Limit exceeds nowCount; recursion reduces the limit. |
44 |
22 |
0 |
Page 3, Size 22 |
Standard offset/limit division (44/22 + 1). |
0 |
5 |
5 |
Throws AlreadyGetNeededCountException |
Requested limit is already satisfied by nowCount. |
use SomeWork\OffsetPage\Logic\Offset; $offset = 0; // start from the first record $limit = 10; // request ten records $nowCount = 0; // no rows have been processed yet $result = Offset::logic($offset, $limit, $nowCount); $result->getPage(); // 1 (first page) $result->getSize(); // 10 (page size derived from limit)
If the requested limit is already satisfied by nowCount, an exception is thrown:
use SomeWork\OffsetPage\Logic\AlreadyGetNeededCountException; use SomeWork\OffsetPage\Logic\Offset; $offset = 0; $limit = 5; $nowCount = 5; $result = Offset::logic($offset, $limit, $nowCount); // throws AlreadyGetNeededCountException
Development
Run the automated checks locally using Composer scripts:
composer install composer test # PHPUnit test suite composer stan # PHPStan static analysis composer cs-check # PHP CS Fixer dry-run for coding standards
License
MIT
somework/offset-page-logic 适用场景与选型建议
somework/offset-page-logic 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 6.31k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2017 年 06 月 04 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「page」 「pagination」 「converter」 「limit」 「offset」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 somework/offset-page-logic 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 somework/offset-page-logic 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 somework/offset-page-logic 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
DataTables is a plug-in for the jQuery Javascript library. It is a highly flexible tool, based upon the foundations of progressive enhancement, which will add advanced interaction controls to any HTML table.
Plug-ins for DataTables
Tools to convert between .NET and PHP date formats
Encode integer IDs using a preset or customized symbol set
This package helps you use bitwise enums in PHP and Laravel.
TCMB Currenct Converter
统计信息
- 总下载量: 6.31k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 21
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-04