imponeer/criteria

Small library for building database criteria strings

v2.0.0 2025-06-03 23:26 UTC

This package is auto-updated.

Last update: 2025-06-04 10:17:47 UTC


README

License GitHub release PHP Packagist

Criteria

A small PHP library to generate SQL WHERE, ORDER BY, and GROUP BY query parts. Inspired by Xoops CMS classes (CriteriaElement, Criteria, and CriteriaCompo), but fully rewritten and released under a more permissive open-source license.

Installation

The recommended way to install this package is via Composer:

composer require imponeer/criteria

Alternatively, you can manually include the files from the src/ directory.

Usage

Here is a basic example of how to use the Criteria library:

use Imponeer\Database\Criteria\CriteriaItem;
use Imponeer\Database\Criteria\CriteriaCompo;

$criteria = new CriteriaCompo();
$criteria->add(new CriteriaItem('status', 'active'));
$criteria->add(new CriteriaItem('age', 18, '>='));

// Generate SQL WHERE clause
$where = $criteria->render();
// $where will be: "(`status` = 'active' AND `age` >= 18)"

API Documentation

Full API documentation is available in the repository wiki. Documentation is automatically updated with every release.

Development

For development, use the following Composer commands:

  • Run tests:
    composer test
  • Run static analysis:
    composer phpstan
  • Run code style checks:
    composer phpcs

How to contribute?

If you want to add functionality or fix bugs, fork the repository, make your changes, and create a pull request.

If you find any bugs or have questions, please use the issues tab to report them or ask questions.