Download the PHP package lmc/api-filter without Composer

On this page you can find all versions of the php package lmc/api-filter. 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 api-filter

API Filter

Latest Stable Version Build Status Coverage Status

Parser/builder for filters from API query parameters.

It is just a parser/builder for filters, it is not a place for business logic so it should be wrapped by your class if you want to be more strict about filters. Same if you want different settings per entity/table, it should be done by a specific wrapper around this library.

Table of Contents

Installation

Usage

For example lets have query parameters from following request

Initialization

With Doctrine Query Builder Applicator

Example

Shorter example (same as ☝)

With SQL Applicator

SQL Applicator must be registered explicitly

Example

Shorter example (same as ☝)

Supported filters

Equals - EQ (=)

Both examples ☝ are equal

Not Equals - NEQ (!=)

Greater Than - GT (>)

Greater Than Or Equals - GTE (>=)

Lower Than - LT (<)

Lower Than Or Equals - LTE (<=)

IN

Function

Tuples in filters

Tuples

Column with Tuple

Columns declared by Tuple behaves the same as a single value but its value must be a Tuple as well. Columns can contain a filter specification for each value.

Values with Tuple

Values in the Tuple must have the same number of items as is the number of columns. Values can contain a filter specification for all values in a Tuple.

NOTE: A filter specification must not be in both columns and values.

Usage

☝ means that you have two columns first and second and they must be sent together. Column first must equal the value "one" and column second must equal the value "two".

Examples

❗For simplicity of examples, they are shown on the SQL Applicator which is NOT auto-registered❗

IN + EQ filter

GT + LT filter (between)

EQ with Tuple

More Examples

Equals (implicit and explicit)

Result:

Multiple filters (implicit and explicit)

By single values

By Tuples

Result:

Multiple filters

You can mix all types of filters (tuples, explicit, implicit).

Perfect wife by generic filters

By single values

By Tuples

Result:

Want to see movies by generic filters

By single values

By Tuples

Result:

Functions in filters

With function you can handle all kinds of problems, which might be problematic with just a simple filters like eq, etc.

Example for fullName function

Let's see how to work with functions and what is required to do. We will show it right on the example.

Expected api

☝️ example above shows what we want to offer to our consumers. It's easy and explicit enough.

It may even hide some inner differences, for example with simple filters, database column must have same name as field in filter, but with function, we can change it.

Let's say that in database we have something like:

Initialization

First of all, you have to define functions you want to use.

Method declareFunction will create a function with filters based on parameters.
There is also registerFunction method, which allows you to pass any function you want. This may be useful when you dont need filter functionality at all or have some custom storage, etc.

Parsing and applying filters

Now when request with ?fullName=(Jon,Snow) come, ApiFilter can parse it to:

Supported function usage

All examples below results the same. We have that many options, so we can allow as many different consumers as possible.

Function Parameters Definition

To declare or register function, you have to define its parameters. There are many ways/needs to do it.

Defined as string

This is the easiest way to do it. You just define a name.

It means:

Defined as array

This allows you to pass more options for a paramater.

Only one item

If you declare it just by giving the only item, it is the same as definition by string above.

More than one item

It means

Defined as object

This allows you to pass same options as with the array, but explicitly defined object. (It even has some special constructor methods to simplify creation)

Combinations

All options can be combined to best suite the parameter.

Declaration
Usage

Register and Execute function

Example below is just for explicit demonstration, you should probably never allow execute SQL queries like this.

Usage in PHP

Usage of the API

All examples below results the same. We have that many options, so we can allow as many different consumers as possible.

Exceptions and error handling

Known exceptions occurring inside ApiFilter implements Lmc\ApiFilter\Exception\ApiFilterExceptionInterface. The exception tree is:

Exception Thrown when
ApiFilterExceptionInterface Common interface of all ApiFilter exceptions
└ InvalidArgumentException Base exception for assertion failed
└ UnknownFilterException Unknown filter is used in query parameters
└ UnsupportedFilterableException This exception will be thrown when no applicator supports given filterable.
└ UnsupportedFilterException This exception should not be thrown on the client side. It is meant for developing an ApiFilter library - to ensure all Filter types are supported.
└ TupleException Common exception for all problems with a Tuple. It also implements MF\Collection\Exception\TupleExceptionInterface which might be thrown inside parsing.

Please note if you register a custom applicator to the ApiFilter (via $apiFilter->registerApplicator()), it may throw other exceptions which might not implement ApiFilterExceptionInterface.

Development

Install

Tests

Todo


All versions of api-filter with dependencies

PHP Build Version
Package Version
Requires php Version ^8.0
ext-mbstring Version *
beberlei/assert Version ^3.0
mf/collections-php Version ^6.0
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 lmc/api-filter contains the following files

Loading the files please wait ....