mpyw/sharable-value-objects
Composer 安装命令:
composer require mpyw/sharable-value-objects
包简介
Share value objects that contain the same primitive value as a singleton.
README 文档
README
Share value objects that contain the same primitive value as a singleton.
Important
Singleton objects are kept under WeakReference.
Tip
You can compare objects like primitives through === operator!
Value::create('one') === Value::create('one') // This should be true Value::create('one') === Value::create('two') // This should be false
Requirements
- PHP:
^8.2
Note
Older versions have outdated dependency requirements. If you cannot prepare the latest environment, please refer to past releases.
Installing
composer require mpyw/sharable-value-objects
Caution
PHP 8.3.2 is incompatible due to the bug in the PHP core.
Usage
class ScreenName { // 1. Mixin Sharable trait family use SharableString; // 2. Write your instantiation logic here public static function create(string $value): static { // Validation/Assertion if (!preg_match('/\A@\w{4,15}\z/', $value)) { throw new \InvalidArgumentException("invalid screen_name: $value"); } // ** Call static::acquire() to get instance ** return static::acquire($value); } // 3. Write your raw presentation logic here public function value(): string { // ** Call $this->getOriginalValue() to retrieve original value ** return $this->getOriginalValue(); } }
class ScreenNameTest extends TestCase { public function testSame(): void { // Same parameters yield the same instance $this->assertSame( ScreenName::create('@mpyw'), ScreenName::create('@mpyw'), ); } public function testDifferent(): void { // Different parameters yield different instances $this->assertNotSame( ScreenName::create('@mpyw'), ScreenName::create('@X'), ); } }
mpyw/sharable-value-objects 适用场景与选型建议
mpyw/sharable-value-objects 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 84.65k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 11 月 11 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 mpyw/sharable-value-objects 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 mpyw/sharable-value-objects 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 84.65k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 12
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-11-11