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.
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.
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)"
Full API documentation is available in the repository wiki. Documentation is automatically updated with every release.
For development, use the following Composer commands:
- Run tests:
composer test
- Run static analysis:
composer phpstan
- Run code style checks:
composer phpcs
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.