Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
WinterSilence authored Apr 14, 2022
1 parent 3397515 commit de266f9
Showing 1 changed file with 45 additions and 11 deletions.
56 changes: 45 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,52 @@
The flexible comparation of any values.
The flexible comparation of
- index/assoc arrays
- objects/closures
- floats/NANs
- binary/text strings
- stream resources

### Installation
Via Composer:
Via [Composer](https://getcomposer.org):
~~~bash
composer require ensostudio/comparator
~~~
### API
### Usage
~~~php
use EnsoStudio\Comparator\Comparator;
$comparator = Comparator(Comparator::EQUAL_ARRAY | Comparator::EQUAL_FLOAT);
if ($comparator->compare($value, $value2)) {
echo 'same values';
}
~~~
~~~php
$comparator->setFlags(Comparator::EQUAL_FLOAT);
var_dump(3 - 2.4 == 0.6, $comparator->compare(3 - 2.4, 0.6));
// false, true

$comparator->setFlags(Comparator::EQUAL_STRING);
var_dump('foo' == 'FOO', $comparator->compare('foo', 'FOO'));
// false, true
// Case-issensetive comparation supports only for English:
var_dump($comparator->compare('я', 'Я'));
// false

$comparator->setFlags(Comparator::EQUAL_CLOSURE);
$createClosure = function () {
return function ($value) {
return $value * 2;
};
};
var_dump($createClosure() == $createClosure(), $comparator->compare($createClosure(), $createClosure()));
// false, true

$comparator->setFlags(Comparator::EQUAL_ARRAY | Comparator::EQUAL_FLOAT);
var_dump($comparator->compare(
['float' => 2 - 1.6, 'int' => 3],
['int' => 3, 'float' => 0.4]
));
// true
~~~
### Public API
~~~php
namespace EnsoStudio\Comparator;
class Comparator
Expand All @@ -16,11 +58,3 @@ class Comparator
public function compare(mixed $value, mixed $value): bool;
}
~~~
### Usage
~~~php
use EnsoStudio\Comparator\Comparator;
$comparator = new Comparator(Comparator::EQUAL_ARRAY | Comparator::EQUAL_FLOAT);
if ($comparator->compare(['float' => 2 - 1.6, 'int' => 3], ['int' => 3, 'float' => 0.4])) {
echo 'equal values';
}
~~~

0 comments on commit de266f9

Please sign in to comment.