pleets/units-of-measurement
Composer 安装命令:
composer require pleets/units-of-measurement
包简介
PHP Units of Measurement
README 文档
README
This project collects some units of measurement and encapsulates symbols and names in simple constant classes. Some behavior was added to handle and interact with it in a more comfortable way.
In this version, the following units were implemented:
- Time (s, m, h, ...)
- Information (B, KB, MB, ...)
Installation
Use following command to install this library:
composer require pleets/units-of-measurement
Usage
Displaying Units and Symbols
You can get the name of a unit of measurement as follows
use Pleets\Units\Symbols\TimeSymbol; use Pleets\Units\Units\TimeUnit; use Pleets\Units\Symbols\InformationSymbol; use Pleets\Units\Units\InformationUnit; // second $symbol = TimeUnit::fromSymbol(TimeSymbol::SECOND); // kilobyte $symbol = InformationUnit::fromSymbol(InformationSymbol::KILOBYTE);
As the same way, you can get the symbol of a unit measurement as follows
use Pleets\Units\Symbols\TimeSymbol; use Pleets\Units\Units\TimeUnit; use Pleets\Units\Symbols\InformationSymbol; use Pleets\Units\Units\InformationUnit; // s $symbol = TimeSymbol::fromUnit(TimeUnit::SECOND); // KB $symbol = InformationSymbol::fromUnit(InformationUnit::KILOBYTE);
Grouping Units and Symbols
You can group as units as you need in the following way.
use Pleets\Units\Units\TimeUnit; use Pleets\Units\Units\Sets\TimeUnitSet; $timeSet = new TimeUnitSet(); $timeSet->addUnit(TimeUnit::MINUTE); $timeSet->addUnit(TimeUnit::HOUR); // ['minute', 'hour'] $units = $timeSet->toArray();
As the same way, you can group as symbols as you need in the following way.
use Pleets\Units\Symbols\TimeSymbol; use Pleets\Units\Symbols\Sets\TimeSymbolSet; $timeSet = new TimeSymbolSet(); $timeSet->addSymbol(TimeSymbol::MINUTE); $timeSet->addSymbol(TimeSymbol::HOUR); // ['min', 'h'] $symbols = $timeSet->toArray();
Conversions
You can convert between units using the main class of each unit.
use Pleets\Units\Time; $time = Time::fromUnit('minute', 5); // 300s $time->toMinutes()->toString(); // 300 seconds $time->toString(false);
pleets/units-of-measurement 适用场景与选型建议
pleets/units-of-measurement 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 102 次下载、GitHub Stars 达 0, 最近一次更新时间为 2021 年 07 月 21 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「si units」 「Units of Measurement」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 pleets/units-of-measurement 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 pleets/units-of-measurement 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 pleets/units-of-measurement 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
The "View Counter" bundle
A small client implementing the Measurement Protocol for Google Analytics 4.
Physical quantities and formulas
Measurement unit management for Laravel Enso
Packaging unit management for Laravel Enso
Symfony 2 bundle, push your google analytics hits from the server
统计信息
- 总下载量: 102
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-07-21