Recommend this page to a friend! |
Download .zip |
Info | Documentation | View files (23) | Download .zip | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2024-02-24 (1 month ago) | Not enough user ratings | Total: 36 This week: 1 | All time: 10,919 This week: 140 |
Version | License | PHP version | Categories | |||
php-criteria 1.0 | Custom (specified... | 8.1 | Databases, PHP 8 |
Description | Author | |||
This package can compose query conditions from criteria clauses. Innovation Award
|
Small implementation of a criteria pattern in PHP for Complex Heart SDK. Compose several filters using fluent interface.
Just install the package from Packagist using composer:
composer require complex-heart/criteria
Import the class and use the fluent interface:
namespace ComplexHeart\Domain\Criteria;
// Match the users with status active and more than 7k followers and from Spain and France
$g1 = FilterGroup::create()
->addFilterEqual('status', 1)
->addFilterGreaterThan('followers', 7000)
->addFilterIn('country', ['es', 'fr']);
$criteria = Criteria::default()
->withFilterGroup($g1)
->withOrderBy('surname')
->withOrderType('asc')
->withPageLimit(25)
->withPageOffset(50);
$users = $repository->match($criteria);
// alternative, same as above
$criteria = Criteria::default()
->withFilterGroup(FilterGroup::create()
->addFilterEqual('status', 1)
->addFilterGreaterThan('followers', 7000)
->addFilterIn('country', ['es', 'fr']))
->withOrderBy('surname')
->withOrderType('asc')
->withPageLimit(25)
->withPageOffset(50);
// In SQL, we may have something like:
// WHERE status = 1 AND followers >= 700 AND country in ('es', 'fr')
$users = $repository->match($criteria);
A FilterGroup
is a set of filters or conditions that must match all together (AND
). To match one group or another
(OR
), just add more FilterGroup
.
// Match articles with given term in title, or in tagline, or in content.
$criteria = Criteria::default()
->withFilterGroup(FilterGroup::create()->addFilterContains('title', $term))
->withFilterGroup(FilterGroup::create()->addFilterContains('tagline', $term))
->withFilterGroup(FilterGroup::create()->addFilterContains('content', $term))
->withOrderBy('created_at')
->withOrderType(Order::TYPE_ASC)
->withPageNumber(3);
Files |
File | Role | Description | ||
---|---|---|---|---|
.github (1 file, 2 directories) | ||||
src (7 files, 2 directories) | ||||
tests (3 files) | ||||
wiki (1 file) | ||||
composer.json | Data | Auxiliary data | ||
LICENSE | Lic. | License text | ||
phpunit.xml | Data | Auxiliary data | ||
README.md | Doc. | Documentation | ||
sonar-project.properties | Data | Auxiliary data |
Files | / | .github |
File | Role | Description | ||
---|---|---|---|---|
ISSUE_TEMPLATE (2 files) | ||||
workflows (2 files) | ||||
CODEOWNERS | Data | Auxiliary data |
Files | / | .github | / | ISSUE_TEMPLATE |
File | Role | Description |
---|---|---|
bug_report.md | Data | Auxiliary data |
feature_request.md | Data | Auxiliary data |
Files | / | .github | / | workflows |
File | Role | Description |
---|---|---|
documentation.yml | Data | Auxiliary data |
test.yml | Data | Auxiliary data |
Files | / | src |
File | Role | Description | ||
---|---|---|---|---|
Contracts (1 file) | ||||
Errors (1 file) | ||||
Criteria.php | Class | Class source | ||
Filter.php | Class | Class source | ||
FilterGroup.php | Class | Class source | ||
Operator.php | Aux. | Auxiliary script | ||
Order.php | Class | Class source | ||
OrderType.php | Aux. | Auxiliary script | ||
Page.php | Class | Class source |
Files | / | tests |
File | Role | Description |
---|---|---|
CriteriaTest.php | Class | Class source |
FilterGroupTest.php | Example | Example script |
Pest.php | Aux. | Auxiliary script |
Version Control | Unique User Downloads | Download Rankings | |||||||||||||||
100% |
|
|
Applications that use this package |
If you know an application of this package, send a message to the author to add a link here.