intriro/clock
Composer 安装命令:
composer require intriro/clock
包简介
A simple wrapper for abstracting the system date
README 文档
README
A simple clock abstraction library for PHP.
Motivation
The problem with DateTime instances is that they are not testable and mockable. They always rely on the system date and time. Therefore you should never directly create DateTime instances.
With the Clock interface you are able to switch implementations and therefore have control over the returned DateTime instances.
Installation
Install it using Composer.
composer require intriro/clock
Implementation
The Clock object provides access to the current date and time. Basically it is just a object which returns a
DateTimeImmutable instance that represents the current date and time.
With a Clock interface you can always swap implementations and get DateTimeImmutable instances which don't rely on the system time.
The library ships with a Clock interface and three implementations.
SystemClock gives you access to the system date and time. It just returns new DateTimeImmutable('now') and it's the
default implementation.
ShiftedSystemClock returns the system date and time that is shifted for a provided interval.
FixedClock returns a predefined fixed date and time.
Example
class Event { /** * @var DateTimeImmutable */ private $date; public function hasPassed(Clock $clock): bool { if ($this->clock->now() > $this->date) { return true; } return false; } }
intriro/clock 适用场景与选型建议
intriro/clock 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.64k 次下载、GitHub Stars 达 0, 最近一次更新时间为 2016 年 12 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 intriro/clock 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 intriro/clock 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 8.64k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-12-20