Recommend this page to a friend! |
Download |
Info | Documentation | Files | Install with Composer | Download | Reputation | Support forum | Blog | Links |
Last Updated | Ratings | Unique User Downloads | Download Rankings | |||||
2024-02-24 (7 months ago) | Not enough user ratings | Total: 42 | All time: 10,853 This week: 73 |
Version | License | PHP version | Categories | |||
php-criteria 1.0 | Custom (specified... | 8.1 | Databases, PHP 8 |
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 (23) |
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 (23) | / | .github |
File | Role | Description | ||
---|---|---|---|---|
ISSUE_TEMPLATE (2 files) | ||||
workflows (2 files) | ||||
CODEOWNERS | Data | Auxiliary data |
Files (23) | / | .github | / | ISSUE_TEMPLATE |
File | Role | Description |
---|---|---|
bug_report.md | Data | Auxiliary data |
feature_request.md | Data | Auxiliary data |
Files (23) | / | .github | / | workflows |
File | Role | Description |
---|---|---|
documentation.yml | Data | Auxiliary data |
test.yml | Data | Auxiliary data |
Files (23) | / | 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 (23) | / | tests |
File | Role | Description |
---|---|---|
CriteriaTest.php | Class | Class source |
FilterGroupTest.php | Example | Example script |
Pest.php | Aux. | Auxiliary script |
The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page. |
Install with Composer |
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.