Download the PHP package onemustcode/query without Composer
On this page you can find all versions of the php package onemustcode/query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package query
Query
It simply transforms the given filters, sortings and paging to a Doctrine or Eloquent query. Handy for interal usage or it can be used for API's.
Installation
Require the Query library trough composer.
Query
The Query holds the paging, sortings, filters and includes.
Create new Query instance;
Paging
Change the results per page;
Change the page;
Create an Query instance directly from given Paging object;
Filtering
The following filters can be used;
Type | Class |
---|---|
Equals | new Equals('field', 'value') |
Not Equals | new NotEquals('field', 'value') |
Greather than | new GreatherThan('field', 20) |
Greather than or Equals | new GreatherThanOrEquals('field', 25) |
Less than | new LessThan('field', 50) |
Less than or Equals | new LessThanOrEquals('field', 55) |
Is null | new IsNull('field') |
Is not null | new IsNotNull('field') |
In | new In('field', '1,2,3,4,5') |
Not in | new NotIn('field', '1,2,3,4,5') |
Like | new Like('field', '%ohn%') |
Add new filter to existing Query instance;
Create an Query instance directly from one or more filters;
Sorting
Add new sorting to existing Query instance;
Create an Query instance directly from one or more sortings;
Includes
Add new include to existing Query instance;
Create an Query instance directly from one or more includes;
Builder
Warning: The Builder class is deprecated, use the transformer instead.
The builder turns an given array to an Query instance;
Transformer
The builder transforms an given array to an Query instance;
It is possible to add your own custom filters. In order to do this you should pass them as an associative array in the constructor (note that the filter should implement the OneMustCode\Query\Filters\FilterInterface]). The key should be the filters's operator and the value the filter's FQN;
Writer
The writer can export the given Query instance to json, query parameters and an array.
Json
Array
Query parameters
Doctrine Query Builder
The following example code shows you how to use the Doctrine Query Builder. Just pass the Query instance, Doctrine Query Builder, the accepted filters or sortings and it will automatically generate the query for you.
Example;
It is possible to add your own custom filter handlers. In order to do this you should pass in the handler in the QueryBuilder's constructor (note that the filter handler should implement the OneMustCode\Query\Builders\Doctrine\Filters\FilterHandlerInterface);
License
MIT