PHP code example of letkode / query-filter-bundle
1. Go to this page and download the library: Download letkode/query-filter-bundle 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/ */
letkode / query-filter-bundle example snippets
// config/bundles.php
return [
Letkode\QueryFilterBundle\LetkodeQueryFilterBundle::class => ['all' => true],
];
use Letkode\QueryFilterBundle\Filter\FilterCriteria;
$criteria = new FilterCriteria(field: 'firstName', operator: 'is', values: ['Ana']);
use Letkode\QueryFilterBundle\Filter\FilterInput;
$input = FilterInput::text(); // no casting
$input = FilterInput::bool(); // 'true'/'false' -> bool
$input = FilterInput::int();
$input = FilterInput::float();
$input = FilterInput::number(); // float, for numeric comparisons
$input = FilterInput::date(); // string -> DateTimeImmutable
$input = FilterInput::array();
$input->castValue('42.5'); // typed value
$input->castValues(['1', '2']); // list<mixed>
use Letkode\QueryFilterBundle\Filter\FilterQuery;
$parsed = FilterQuery::fromArray([
'firstName' => [['op' => 'is', 'value' => ['Ana']]],
]);
// $parsed->criteria, $parsed->rejected
use Letkode\QueryFilterBundle\Request\FilterQueryStringRequest;
$request = new FilterQueryStringRequest(page: 1, perPage: 20, q: 'search', sort: 'name', dir: 'asc');
use Letkode\QueryFilterBundle\Request\FilterQueryRequest;
$query = FilterQueryRequest::fromArray($request->query->all());
// $query->page, $query->perPage, $query->q, $query->sort, $query->dir, $query->filters
// $query->rejected — list<QueryParameterRejection> for malformed filter entries
use Letkode\QueryFilterBundle\Factory\FilterQueryRequestFactory;
$query = FilterQueryRequestFactory::build($queryStringRequest);
use Letkode\QueryFilterBundle\Result\PaginatedResultRepository;
$result = new PaginatedResultRepository(data: $items, total: 120, page: 1, perPage: 20);
$result->totalPages; // computed, e.g. 6
use Letkode\QueryFilterBundle\Response\PaginationValueResponse;
$pagination = new PaginationValueResponse(
total: $result->total,
perPage: $result->perPage,
totalPages: $result->totalPages,
page: $result->page,
);