codeliner/php-equalsbuilder
Composer 安装命令:
composer require codeliner/php-equalsbuilder
包简介
EqualsBuilder for PHP.
关键字:
README 文档
README
EqualsBuilder for PHP
Installation
Installation of codeliner/php-equalsbuilder uses composer. For composer documentation, please refer to getcomposer.org. Add following requirement to your composer.json
"codeliner/php-equalsbuilder" : "1.2.*"
Usage
Use the EqualsBuilder to compare any number of value pairs at once.
echo EqualsBuilder::create() ->append('equals', 'equals') ->append(1, 1) ->append(1, '1') ->equals() ? "All value pairs are equal" : "At least one value pair is not equal"; //Output: All value pairs are equal
You can enable strict mode to compare against the value types, too.
echo EqualsBuilder::create() ->append('equals', 'equals') ->append(1, 1) ->append(1, '1') ->strict() //enable strict mode ->equals() ? "All value pairs are equal" : "At least one value pair is not equal"; //Output: At least one value pair is not equal
If you only provide the first parameter the second one is set to true. This enables you to use comparison methods of objects together with the EqualsBuilder.
echo EqualsBuilder::create() ->append($vo->sameValueAs($otherVo)) ->append(1, 1) ->append(1, '1') ->equals() ? "All value pairs are equal" : "At least one value pair is not equal"; //Output: All value pairs are equal
You can also provide a callback as third parameter which is called with the value pair. The callback should return a boolean value.
echo EqualsBuilder::create() ->append($vo, $otherVo, function($a, $b) { return $a->sameValueAs($b);}) ->append(1, 1) ->append(1, '1') ->equals() ? "All value pairs are equal" : "At least one value pair is not equal"; //Output: All value pairs are equal
The callback option gets really interesting when $a and $b are array lists (arrays with continuous integer keys starting at 0 and ending at count - 1 ). In this case the callback is called for every item in list $a together with the corresponding item of list $b assumed that count($a) == count($b) is true.
$aList = array($vo1, $vo2, $vo3); $bList = array($vo1, $vo2, $vo3); echo EqualsBuilder::create() ->append($aList, $bList, function($aVO, $bVO) { return $aVO->sameValueAs($bVO);}) ->append(1, 1) ->append(1, '1') ->equals() ? "All value pairs are equal" : "At least one value pair is not equal"; //Output: All value pairs are equal
codeliner/php-equalsbuilder 适用场景与选型建议
codeliner/php-equalsbuilder 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4.52k 次下载、GitHub Stars 达 6, 最近一次更新时间为 2014 年 01 月 10 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「equals」 「EqualsBuilder」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 codeliner/php-equalsbuilder 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 codeliner/php-equalsbuilder 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 codeliner/php-equalsbuilder 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This plugin makes sure that the slug is always the same as the title.
Equatable objects and collections in PHP
Additional rules for conditional equals validation
Implements equivalence relations on non-null object references as a PHP component.
Simple implementation for asserting PHP7 scalar type declarations and return types
统计信息
- 总下载量: 4.52k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 5
- 依赖项目数: 4
- 推荐数: 0
其他信息
- 授权协议: BSD-3-Clause
- 更新时间: 2014-01-10