bbprojectnet/unit-helpers
最新稳定版本:1.0.0
Composer 安装命令:
composer require bbprojectnet/unit-helpers
包简介
Simple unit helpers for configuration purposes.
README 文档
README
This package is intended to make it easier to specify time and size in configuration files more clearly.
Example 1:
// Before $query->where('size', '>=', 209715200)->get(); // After $query->where('size', '>=', Size::mb(200))->get();
Example 2:
// Before $config = [ 'expiration' => 4680, // 3 days and 6 hours in minutes ]; // After $config = [ 'expiration' => Time::of(days: 3, hours: 6, 'minutes'), // or 'expiration' => Time::of(days: 3.25, 'minutes'), // or 'expiration' => Time::days(3.25, 'minutes'), ];
Example 3:
// Before class Job { protected int $timeout = 10800; } // After class Job { protected int $timeout = Time::HOUR * 3; }
Requirements
- PHP 8.0 and above
Installation
Require this package with composer using the following command:
composer require bbprojectnet/unit-helpers
Usage
As simple static call:
$timeout = Time::hours(4);
Static call with output unit specified:
$timeout = Time::hours(4, 'minutes');
As method parameter:
$timeout = Time::of(days: 2);
With mixed unit types:
$timeout = Time::of(days: 2, hours: 10);
With mixed unit types and output unit specified:
$timeout = Time::of(days: 2, hours: 10, as: 'minutes');
With mixed unit types, fractions, negative values and output unit specified:
$timeout = Time::of(days: 2.4, hours: -2, minutes: 0.5, as: 'minutes');
As constant in places where method invocation is not possible:
protected int $timeout = Time::HOUR * 3;
License
The Unit helpers package is open-sourced software licensed under the MIT license.
统计信息
- 总下载量: 4k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 1
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-07-13