dwo/comparator

v1.0.3 2016-06-22 16:36 UTC

This package is not auto-updated.

Last update: 2024-11-06 17:02:49 UTC


README

Build Status Coverage Status

Comparator

The Comparator is a little library to compare values in a easy way. Very useful for dynamic comparisons.

$operator = '==';
$argument1 = 1;
$argument2 = 1;
if(Comparator::compare($operator, $argument1, $argument2)) {
    //do something
}

Operators

The Comparator comes with some operators:

  • '==', '!=', '>', '>=', '<', '<='
  • 'version'
  • 'substr'
  • 'bit'
  • 'between'
  • 'bool'
  • 'day'
  • 'date_range'
//Example 'bool' operator
if(Comparator::compare('bool', true, $_GET['activated'])) {
    //do something
}

//Example 'date' operator
if(Comparator::compare('day', 'now', $date)) {
    //do something
}

//Example 'date_range' operator
if(Comparator::compare('date_range', new \DateTime(), $dateFrom, $dateTo)) {
    //do something
}

The 'date' and 'date_range' operators can handle Timestamps, DateTimeObjects as well as DateStrings ('now' or '-2 days').

Installation

Installation with Composer

composer.phar require dwo/comparator