https://github.com/windwalker-io/compare
[DEPRECATED] String comparation library.
https://github.com/windwalker-io/compare
compare conditions
Last synced: 24 days ago
JSON representation
[DEPRECATED] String comparation library.
- Host: GitHub
- URL: https://github.com/windwalker-io/compare
- Owner: windwalker-io
- Created: 2014-02-19T02:18:01.000Z (almost 12 years ago)
- Default Branch: master
- Last Pushed: 2023-07-18T08:29:42.000Z (over 2 years ago)
- Last Synced: 2025-01-02T06:44:52.421Z (about 1 year ago)
- Topics: compare, conditions
- Language: PHP
- Homepage: https://github.com/ventoviro/windwalker
- Size: 47.9 KB
- Stars: 0
- Watchers: 4
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Windwalker Compare
## What is Compare
Sometimes we will need a dynamic compare interface, but it hard to convert `=` or `<=` string to be php operator.
Compare object can help us create an object with compare logic between two values, and convert it to string, then we can use this string to build SQL or other use.
## Installation via Composer
Add this to the require block in your `composer.json`.
``` json
{
"require": {
"windwalker/compare": "~3.0"
}
}
```
## Basic Usage
``` php
echo new GteCompare('published', '1');
```
We will get `published >= 1` string. This is easy to integate into query string.
``` php
$conditions = array(
GteCompare('published', '1'),
EqCompare('entry_id', 25),
LteCompare('date', $query->quote($date))
);
$sql = 'WHERE ' . implode(' AND ' , $conditions);
```
We will get this string: `WHERE published >= 1 AND entry_id = 25 AND data <= '2014-03-02'`.
## Do Compare
``` php
$compare = new GteCompare(3, '1');
$result = $compare->compare();
var_dump($result); // bool(true)
```
## Available Compare Object
| Name | Description | Operator |
| ---------- | ------------------- | -------- |
| EqCompare | Equal | `=` |
| NeqCompare | Not Equal | `!=` |
| GtCompare | Greater than | `>` |
| GteCompare | Greater than or Equal | `>=` |
| LtCompare | Less than | `<` |
| LteCompare | Less than or Equal | `<=` |
| InCompare | In an array or list | `IN` |
| NinCompare | Not In an array or list | `IN` |