2017 © Pedro Peláez
 

library php-equalsbuilder

EqualsBuilder for PHP.

image

codeliner/php-equalsbuilder

EqualsBuilder for PHP.

  • Friday, June 13, 2014
  • by codeliner
  • Repository
  • 1 Watchers
  • 6 Stars
  • 4,287 Installations
  • PHP
  • 5 Dependents
  • 0 Suggesters
  • 0 Forks
  • 4 Open issues
  • 5 Versions
  • 0 % Grown

The README.md

EqualsBuilder

EqualsBuilder for PHP, (*1)

Build Status, (*2)

Installation

Installation of codeliner/php-equalsbuilder uses composer. For composer documentation, please refer to getcomposer.org. Add following requirement to your composer.json, (*3)

"codeliner/php-equalsbuilder" : "1.2.*"

Usage

Use the EqualsBuilder to compare any number of value pairs at once., (*4)

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., (*5)

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., (*6)

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., (*7)

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., (*8)

$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

The Versions

13/06 2014

dev-master

9999999-dev https://github.com/codeliner/php-equalsbuilder

EqualsBuilder for PHP.

  Sources   Download

BSD-3-Clause

The Development Requires

equals equalsbuilder

13/06 2014

1.2.0

1.2.0.0 https://github.com/codeliner/php-equalsbuilder

EqualsBuilder for PHP.

  Sources   Download

BSD-3-Clause

The Development Requires

equals equalsbuilder

10/01 2014

1.1.1

1.1.1.0 https://github.com/codeliner/php-equalsbuilder

EqualsBuilder for PHP.

  Sources   Download

BSD-3-Clause

The Development Requires

equals equalsbuilder

10/01 2014

1.1.0

1.1.0.0 https://github.com/codeliner/php-equalsbuilder

EqualsBuilder for PHP.

  Sources   Download

BSD-3-Clause

The Development Requires

equals equalsbuilder

10/01 2014

1.0.0

1.0.0.0 https://github.com/codeliner/php-equalsbuilder

EqualsBuilder for PHP.

  Sources   Download

BSD-3-Clause

The Development Requires

equals equalsbuilder