rumd3x/php-countable
Composer 安装命令:
composer require rumd3x/php-countable
包简介
Library providing several Object Oriented Counters and utilities for counting stuff
README 文档
README
Library providing several Object Oriented utilities for Counting stuff.
Install
composer require rumd3x/php-countable
Usage Examples
- As a while loop exit condition:
use use Rumd3x\Countable\Counters\BasicCounter; $counter = new BasicCounter(10); while (!$counter->isZero()) { // Do stuff... $counter->decrement(); }
- As an iterator counter:
use use Rumd3x\Countable\Counters\BasicCounter; $counter = new BasicCounter(); foreach($myArrayOfStuff as $value) { // Do stuff... $counter->incrementBy($value->quantity); } echo "Found {$counter->getCounter()} stuff";
API Description
This Library provides:
- 2 counter interfaces
DecrementableandIncrementable. - A basic
AbstractCounterthat can be extended upon. - 4 counter implementations, all of them implementing both interfaces, and using
AbstractCounteras a base.
The Incrementable and Decrementable interfaces provides the following methods:
/** Incrementable **/ public function increment(): int; // Increment the counter by one and returns the previous value public function incrementBy(int $incrementQuantity): int; //Increments the counter by incrementQuantity and returns the previous value /** Decrementable **/ public function decrement(): int; // Decrements the counter by one and returns the previous value public function decrementBy(int $decrementQuantity): int; // Decrements the counter by decrementQuantity and returns the previous value
Each Counter implementation handles incrementing and decrementing the counter differently:
BasicCounter
Rumd3x\Countable\Counters\BasicCounter
It is the most basic implementation of both Incrementable and Decrementable interfaces, it does not do any transformation with your inputs, and does not raise any Exceptions.
StandardCounter
Rumd3x\Countable\Counters\StandardCounter
StandardCounter holds a counter, and can increment or decrement its value by implementing both Incrementable and Decrementable interfaces. It can also count to negatives.
SmartCounter
Rumd3x\Countable\Counters\SmartCounter
SmartCounter is the same as StandardCounter, but it does not throw Rumd3x\Countable\Exceptions\NegativeQuantityException when trying to increment or decrement by negatives, instead it swiftly converts the value to a positive one.
AbsoluteCounter
Rumd3x\Countable\Counters\AbsoluteCounter
The AbsoluteCounter is just like a StandardCounter but throws Rumd3x\Countable\Exceptions\NegativeCounterExpcetion if tries the program tries to decrement past 0. It ensures the counter is always positive.
AbstractCounter
The AbstractCounter implements the following methods below:
(Which makes it also available for all 4 Counter implementations provided by the library)
/** * Retrieve the current counter value * @return integer */ public function getCounter(): int; /** * Returns true if the counter is zero, false otherwise * @return boolean */ public function isZero(): bool; /** * Returns true if the counter is less than zero, false otherwise * @return boolean */ public function isNegative(): bool; /** * Returns true if the counter is greater than zero, false otherwise * @return boolean */ public function isPositive(): bool;
rumd3x/php-countable 适用场景与选型建议
rumd3x/php-countable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2019 年 10 月 01 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 rumd3x/php-countable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 rumd3x/php-countable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 4
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-10-01