fleshgrinder/equalable
最新稳定版本:1.0.0
Composer 安装命令:
composer require fleshgrinder/equalable
包简介
Interface for custom equality determination of objects.
README 文档
README
Equalable
The equalable library provides a single interface that defines a method that implementing classes can use to provide custom equality determination. This is useful for value objects and entities alike, since the former might want to allow equality checks against scalar types, and the latter need to exclude all encapsulated values from the equality determination which are not part of their identity defining values.
Installation
Open a terminal, enter your project directory and execute the following command to add this package to your dependencies:
composer require fleshgrinder/equalable
This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.
Usage
Simply implement the interface and the required equals method. The actual
implementation of the method’s body depends on the use-case. Value objects
for instance might want to allow equality checks against scalar types, e.g.:
final class UserId implements Equalable { private $uid; // ... public function equals($other): bool { if ($other instanceof $this) { $other = $other->uid; } return \is_int($other) && $this->uid === $other; } }
Entities on the other hand want to exclude all encapsulated values which are not part of their identity defining values from the determination, e.g.:
final class User implements Equalable { private $uid; private $name; private $email; // ... public function equals($other): bool { return $other instanceof $this && $this->uid->equals($other->uid); } }
Testing
There are not tests since this library provides a single interface, which obviously has no implementation.
fleshgrinder/equalable 适用场景与选型建议
fleshgrinder/equalable 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 718 次下载、GitHub Stars 达 0, 最近一次更新时间为 2015 年 09 月 22 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 fleshgrinder/equalable 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 fleshgrinder/equalable 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 718
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 25
- 依赖项目数: 2
- 推荐数: 2
其他信息
- 授权协议: Unlicense
- 更新时间: 2015-09-22