定制 codeliner/php-equalsbuilder 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

codeliner/php-equalsbuilder

Composer 安装命令:

composer require codeliner/php-equalsbuilder

包简介

EqualsBuilder for PHP.

README 文档

README

EqualsBuilder for PHP

Build Status

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

统计信息

  • 总下载量: 4.52k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 2
  • 依赖项目数: 4
  • 推荐数: 0

GitHub 信息

  • Stars: 6
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-01-10

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固