Download the PHP package brandembassy/query-language-parser without Composer

On this page you can find all versions of the php package brandembassy/query-language-parser. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package query-language-parser

Query language parser

Thanks to this library parsing custom query language in PHP is a piece of cake for you. Just define your own fields, operators and values and everything else will work out of the box for you. So would you like to have query language like this?

This library works on top of the ferno/loco parser. See https://github.com/qntm/loco for more details. Thanks for this great library!

How it works

You will define supported fields and operators, and also possible relations of those two. And then for every possible relation you will define what's the output of the parsing.

Thanks to this library you are able to transform you query language into set of objects that represent database query, or into SQL like syntax. It's completely up to you what will be the output.

Language parts

Logical operators

This library includes standard logical operators out of the box. More concretely we are talking about these:

  1. AND

  2. OR

  3. NOT

You can also adjust operators priority by adding brackets like this:

Relation operators

The most common relation operators are already part of the library. You can use operators =, !=, ~, !~, <, <=, >, >=, LIKE, NOT LIKE, IN, NOT IN, IS NULL and IS NOT NULL without any special effort.

Custom operators

To enrich query language with your own relation operator you must do these two steps:

  1. Create interface defining contract for fields using this operator. See QueryLanguageFieldSupportingEqualToOperator for an example.

    Generally it should define two things:

    • Form of the value that should follow the operator - you can define this by extending certain interface. In case of operator without value (eg. IS NULL) don't extend anything special. In case of operator with single value (eg. =) extend QueryLanguageFieldSupportingSingleValueOperator interface. In case multiple values should follow after the operator, extend interface QueryLanguageFieldSupportingMultipleValuesOperator.

    • Method that will receive parsed field name and eventually parsed value and will return output value for this certain field and operator combination.
  2. Class representing the operator. It must implement interface QueryLanguageOperator. See eg. EqualToQueryLanguageOperator for an example.

    It must implement these methods:

    • getOperatorIdentifier - returns string identifier of the operator
    • createOperatorParser - returns parser for the operator
    • isFieldSupported - returns if the given field is supported by the operator. Typically you will test if the given field implements interface created in step 1.
    • createFieldExpressionParser - creates parser for combination of given field and the operator

Fields

Fields are core of your query language. It defines domain your query language works in.

Every field you want to support in the query language is defined by a class implementing interface QueryLanguageField. This interface defines 3 basic methods:

Every field should also implement all interfaces of the relation operators that it supports (eg. QueryLanguageFieldSupportingEqualToOperator for support of equal to operator).

Query language parser

To create query language parser use QueryParserFactory. Just pass list of your fields, list of supported relation operators and output definition for logical operators (implement LogicalOperatorOutputFactory interface for this) and your query language parser should be ready to use!

Example

See examples dir in this repository for example car-based query language.


All versions of query-language-parser with dependencies

PHP Build Version
Package Version
Requires php Version >=7.4
beberlei/assert Version ^3.3
ferno/loco Version dev-main
nette/utils Version ^3.2
ramsey/uuid Version ^4.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package brandembassy/query-language-parser contains the following files

Loading the files please wait ....