1. Go to this page and download the library: Download adnanmula/criteria library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
adnanmula / criteria example snippets
// Create a criteria object with filters, pagination and sorting
$criteria = new Criteria(
filters: new Filters(
FilterType::AND, // How top-level filters are combined
// Simple filter
new Filter(
new FilterField('status'),
new StringArrayFilterValue('active', 'pending', 'review'),
FilterOperator::IN,
),
// Filter composed of other filters
new CompositeFilter(
FilterType::OR, // How each expression of this composite filter is combined
new Filter(
new FilterField('id'),
new StringFilterValue('abc123'),
FilterOperator::EQUAL,
),
new Filter(
new FilterField('id'),
new StringFilterValue('asdasd'),
FilterOperator::EQUAL,
),
),
// Composite filters can contain other composite filters (example: (id = 'abc123') OR (amount <= 3 AND json_field @> '["value"]')
new CompositeFilter(
FilterType::OR,
new Filter(
new FilterField('id'),
new StringFilterValue('abc123'),
FilterOperator::EQUAL,
),
new CompositeFilter(
FilterType::AND,
new Filter(
new FilterField('amount'),
new IntFilterValue(3),
FilterOperator::LESS_OR_EQUAL,
),
new Filter(
new FilterField('json_field'),
new ArrayElementFilterValue('value'),
FilterOperator::IN_ARRAY,
),
),
),
// You can add any number of filters or composite filters
),
offset: 10,
limit: 20,
sorting: new Sorting(
new Order(
new FilterField('name'),
OrderType::ASC,
),
new Order(
new FilterField('created_at'),
OrderType::DESC,
),
),
);
// Helper methods
// Copy a criteria adding any number of filters
$originalCriteria = new Criteria();
$newCriteria = new Criteria()->with(
new Filter(new FilterField('otherField'), new NullFilterValue(), FilterOperator::IS_NULL),
new CompositeFilter(
FilterType::OR,
new Filter(new FilterField('domainId'), new IntFilterValue(3), FilterOperator::EQUAL),
new Filter(new FilterField('random_string_or_null'), new StringFilterValue('imnotrandom'), FilterOperator::EQUAL),
),
);
// Copy a criteria removing pagination
$newCriteria = $criteria->withoutPagination();
// Copy a criteria removing pagination and sorting
$newCriteria = $criteria->withoutPaginationAndSorting();
// Copy a criteria removing filters
$newCriteria = $criteria->withoutFilters();
// Get a query builder from your Doctrine DBAL connection
$builder = $this->connection->createQueryBuilder();
// Build your base query
$query = $builder->select('a.fields')
->from('table', 'a');
// Apply criteria to the query builder
(new DbalCriteriaAdapter($builder))->execute($criteria);
// Execute the query
$result = $query->executeQuery()->fetchAllAssociative();
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.