Download the PHP package arraypress/comparator without Composer

On this page you can find all versions of the php package arraypress/comparator. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package comparator

Comparator Library

The Comparator library provides a flexible and powerful way to compare values in PHP, supporting various data types and comparison operators. It is designed to be easy to use while offering extensive functionality for complex comparison scenarios.

Features

Installation

Ensure you have the package installed in your project. If not, you can typically include it using Composer:

Global Comparison Function

The library provides a convenient global Compare class to facilitate easy comparisons between two values with extensive customization options. This function leverages the Comparator class internally while offering additional flexibility for custom comparison logic and error handling.

Function Signature

Parameters

Return Value

Returns a boolean indicating the result of the comparison, or null in case of an error.

Usage Example

This function simplifies complex comparisons by abstracting the instantiation and setup of the Comparator class, allowing developers to perform comparisons with minimal setup and handling errors gracefully.

Supported Comparison Operators and Their Aliases

The Comparator class provides a flexible way to compare different types of values by supporting a wide range of comparison operators. To make the class more intuitive and user-friendly, it allows the use of human-readable aliases for these operators. Below is a table that maps these aliases to their corresponding standard operator symbols, providing an easy reference for users to construct their comparison expressions.

Operator Symbol Human-Readable Aliases Description
== equal_to, equals, = Checks if two values are equal
=== strict_equal_to Checks if two values are strictly equal (identical)
!= not_equal_to, not_equals Checks if two values are not equal
!== strict_not_equal_to Checks if two values are strictly not equal
> more_than, greater_than Checks if value on the left is greater than the value on the right
< less_than Checks if value on the left is less than the value on the right
>= at_least, greater_than_or_equal_to Checks if value on the left is greater than or equal to the value on the right
<= at_most, less_than_or_equal_to Checks if value on the left is less than or equal to the value on the right
starts startswith, starts_with, begins_with Checks if a string starts with a specified substring
ends endswith, ends_with Checks if a string ends with a specified substring
all includes_all, contains_all, has_all, match_all Checks if all specified conditions or values are included or match
any includes_any, contains_any, contains, has, match_any Checks if any of the specified conditions or values are included or match
between between Checks if a value falls within a specified range (inclusive)
not between not_between, not between Checks if a value does not fall within a specified range (inclusive)

Updated translateOperator Function You've already included the necessary updates in your translateOperator function to

This feature enhances the readability and expressiveness of your code, making it easier to understand and maintain.

Automatic Type Detection

The Comparator class is equipped with an intelligent automatic type detection system, designed to simplify the comparison process between different types of values. This feature automatically identifies the type of the provided values and applies the most appropriate comparison logic based on their types. The table below explains the types that can be automatically detected and the conditions under which each type is identified.

Detected Type Conditions
float At least one of the values is a floating-point number.
int Both values are integers, or one is an integer (if no floating-point numbers are detected).
string Both values are strings. Special case: If either value is a valid JSON string, json is returned.
json Both values are strings formatted as valid JSON.
bool At least one of the values is a boolean.
array Both values are arrays.
object Both values are objects.
date Both values are strings that can be converted to valid dates using strtotime.
unknown The type cannot be determined or does not match any of the above criteria.

This automatic type detection facilitates a more dynamic and error-resistant comparison process, allowing users to compare different types of data without the need for explicit type casting or manual type checks. It ensures that the comparison logic is always aligned with the nature of the data being compared, enhancing the robustness and versatility of the Comparator class.

Example Test 1: Integer Comparison

Compare two integers to check if the first is less than the second.

Example Test 2: Float Comparison with Epsilon

Compare two floats for equality, considering a small margin (epsilon).

Example Test 3: String Case-Sensitive Comparison

Compare two strings with case sensitivity.

Example Test 4: Custom Function Comparison

Use a custom function for comparison. In this example, checking if the first number is double the second.

Example Test 5: JSON String Comparison

Compare two JSON strings for equality.

Example Test 6: Regular Expression Comparison

Use a regular expression to compare if a string matches the pattern.

Example Test 7: Array Comparison

Compare two arrays for equality.

Example Test 8: Boolean Comparison

Compare two booleans for equality.

Example Test 9: Object Comparison

Compare two objects for equality.

Example Test 10: Date Comparison

Compare two dates to check if the first is less than the second.

Example Test 11: String Contains

Check if a string contains another string.

Example Test 12: String Starts With

Check if a string starts with another string.

Example Test 13: String Ends With

Check if a string ends with another string.

Example Test 14: Not Equal Comparison

Compare two integers to check if they are not equal.

Example Test 15: Greater Than Comparison

Compare two integers to check if the first is greater than the second.

Example Test 16: Between Comparison for Numbers

Check if an integer is between two other integers (inclusive).

Example Test 17: Not Between Comparison for Numbers

Check if an integer is not between two other integers (inclusive).

Example Test 18: Between Comparison for Dates

Check if a date is between two other dates.

Example Test 19: Not Between Comparison for Dates

Check if a date is not between two other dates.

Contributions

Contributions to this library are highly appreciated. Raise issues on GitHub or submit pull requests for bug fixes or new features. Share feedback and suggestions for improvements.

License: GPLv2 or later

This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.


All versions of comparator with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4 || ^8.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package arraypress/comparator contains the following files

Loading the files please wait ....