Download the PHP package everon/criteria-builder without Composer
On this page you can find all versions of the php package everon/criteria-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download everon/criteria-builder
More information about everon/criteria-builder
Files in everon/criteria-builder
Package criteria-builder
Short Description Everon Criteria Builder Component
License MIT
Informations about the package criteria-builder
Everon Criteria Builder
Library to generate complete statements, with simple, fluid and intuitive interface.
Versions
- Use v1.x and v2.x with PHP 7.2+
- Use v3.x with PHP 8+
Features
- It's not a DQL
- SQL for what's important, fluid interface for boring stuff
- Automatic PDO parameter name escaping and uniqueness, custom parameters
- Fluid interface
- Easily to create multiple conditions
- Almost 20 ready to use Operators
- Easy to extend with Custom Operators
- Intuitive Interface: clear, small and simple API
- Clean code
No boring Sql
Focus on what's important
You can attach your own via and have easy and flexible way of generating fast sql queries without dealing with boring string concatenations, code duplication and vast amount of if/else, switch statements or constants required to handle logic related to LIMIT, OFFSET or SORT statements. All those boring parts were eliminated with .
Hammer won't do when you need a screwdriver
Putting boring stuff aside you have full control on how the is constructed, which is helpful for highly complex, complicated or very specific queries where using DQL makes things actually harder then easier. DQL is great for everyday use, however sometimes you need to express yourself in very specific way, and raw is the best way to get you there.
Translate request into something database can understand
Easy to translate request parameters into something database can understand with , statements and methods like , , or . Useful for pagination or filtering, for example.
Clear separation between , , and applying concepts like aggregation, sort, or limit. Now you can focus only on what's important, the part.
Very easy to use with thanks to
Examples
Simple Query
Will be converted into:
With parameters:
Where, orWhere, andWhere
Each statement creates new Container with Criteria object. A Criteria object contains set of Criterium objects. A Criterium is a condition.
You can append Criterium by using and methods.
Every time you use statement a new Criteria will be created, ready for new set of conditions.
Will be converted into:
With parameters:
To connect Criteria with operator use method.
Will be converted into:
RAW SQL
RAW SQL is easy to implement with methods.
Will be converted into:
Group By
Group By is easily usable with method
Will be converted into:
With parameters:
Limit and Offset
Pretty straightforward with and methods.
Will be converted into:
Order By
Order By is implemented using and keywords, in an associative array with method.
Will be converted into:
Custom Gluing
Manual Criteria handling is also possible by using the methods.
Will be converted into:
With parameters:
Operators
There are almost 20 operators ready for use like Equal, NotIn, Between or Is. Check them all here.
Equal
Will output:
NotIn
Will output:
Between
There must be exactly 2 parameters provided or an exception will be thrown.
Will output:
There are many more. See here for more examples.
Custom Operators
You can register your own Operators with:
For example:
You can use your own operator with methods.
Will output:
See https://github.com/oliwierptak/everon-criteria-builder/tree/development/src/Operator for more examples
How to use
Dependency Injection is done with Everon Factory.
Initialize with .
Setup your conditions.
Append criteria string to already existing sql.
Fetch sample data. After you attached to the , it's even easier to retrieve sql query and its parameters, with and methods like and .
Putting it all together
Test Driven
All versions of criteria-builder with dependencies
everon/collection Version ^3
everon/factory Version ^3
everon/utils Version ^3