imponeer / criteria
Small library for building database criteria strings
Installs: 19 398
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 1
Forks: 1
Open Issues: 0
Requires
- php: >=8.3
Requires (Dev)
- fakerphp/faker: ^1.24
- phpstan/phpstan: ^2.1
- phpunit/phpunit: ^12
- squizlabs/php_codesniffer: ^3.13
README
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.