PHPackages                             bravepickle/query-filters-serializer - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [API Development](/categories/api)
4. /
5. bravepickle/query-filters-serializer

ActiveLibrary[API Development](/categories/api)

bravepickle/query-filters-serializer
====================================

Serializer of query filters from arrays or strings. Provides constraints and parsing logic for preconfigured filters

v2.0b(7y ago)091GNU LGPLPHPPHP &gt;=5.5CI failing

Since Aug 23Pushed 5y ago1 watchersCompare

[ Source](https://github.com/bravepickle/query-filters-serializer)[ Packagist](https://packagist.org/packages/bravepickle/query-filters-serializer)[ RSS](/packages/bravepickle-query-filters-serializer/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (1)Versions (5)Used By (0)

README
======

[](#readme)

Serializer of query filters from arrays or strings. Provides constraints and parsing logic for preconfigured filters

Description
-----------

[](#description)

This is a PHP library that provides serialization/deserialization of abstract filters using query string, compatible with URL format. The main purpose of this library is to help developers to make more or less standard filters within URIs and convert it to neatly formed structure for further usage. Also it can provide (optionally) SQL builder that helps to append those filters to SQL queries. It is more less SQL implementation independent and can be used in various DBs: Doctrine, MySQL, SphinxQL etc.

Filters can be easily configured using configs per each field

Contents
--------

[](#contents)

1. [Installation](#installation)
2. [Features](#features)
3. [Usage](#usage)
    1. [String Format](#string-fmt)
        1. [Additional Examples](#string-fmt-additional-examples)
    2. [URL Query Format](#url-query-fmt)
        1. [Additional Examples](#url-query-fmt-additional-examples)
4. [Configuration](#config)
5. [Advanced Usage](#advanced-usage)
6. [TODOs](#todo)

Installation
--------------------------------------------------

[](#installation)

Add to composer.json

1. Add dependency to composer.json
2. Install new dependencies

    ```
    $ composer install
    ```

Features
------------------------------------------

[](#features)

- currently supports filters:
    - integer
    - datetime
    - date
    - enum
    - string
    - boolean
    - embedded
- 2 formats of string queries to parse supported:
    - string: `type:cool|foo:bar;baz|num:>10;constraints = array('age' => array('type' => 'integer'));
$filterString = 'age:>=14;=14,=2015-11-28T16:59:13UTC,2015-9-28T16:59:13UTC`\['constraints' =&gt; \['date\_from' =&gt; \['type' =&gt; 'datetime'\]\]\]Will convert this set to =2015-08-28T16:59:13UTC. Datetime search`user:(name:John;status:active)`\['constraints' =&gt; \['user' =&gt; \['type' =&gt; 'embedded', 'options' =&gt; \['constraints' =&gt; \['name' =&gt; \['type' =&gt; 'string'\],'status' =&gt; \['type' =&gt; 'string'\]\]\]\]\]\]Embedded search. Will search for records that have reference to entity "user", which have name "John" and status "active"`age: array('type' => 'integer'));
$filterQuery = '_[age][]=>=14&_[age][]=baz')`.

#### Additional examples

[](#additional-examples-1)

InputConfigDescription`_[name]=John, hello`\['constraints' =&gt; \['name' =&gt; \['type' =&gt; 'string', 'name'=&gt; 'title'\]\]\]Will search for string "John, hello" within field "title" (see config)`_[name][]=John&_[name][]=hello&_[name][]=!Jake&_[name][]=Jim!`\['constraints' =&gt; \['name' =&gt; \['type' =&gt; 'string', 'options' =&gt; \['use\_not' =&gt; true, 'multiple' =&gt; true\]\]\]\]Will search for names, that conatin words "John" and "hello" and does not contain words "Jake" and "Jim"`_[status]=active`\['constraints' =&gt; \['status' =&gt; \['type' =&gt; 'string','options' =&gt; \['allowed' =&gt; \['active', 'passive'\]\]\]\]\]Will search status that equals to "active". If given value will not have either "active" or "passive" words, then error will be thrown`_[email]=user@example.com&_[id]=2`\['constraints' =&gt; \['email' =&gt; \['type' =&gt; 'string'\], 'id' =&gt; \['type' =&gt; 'integer'\]\]\]Contains complex filters. Will search records that have email equal to "" and id equal to "2"`_[age][]=>=14&_[age][]==2015-11-28T16:59:13+03:00&_[date_from][]=2015-9-28T16:59:13UTC`\['constraints' =&gt; \['date\_from' =&gt; \['type' =&gt; 'datetime'\]\]\]Will convert this set to =2015-08-28T16:59:13UTC. Datetime search`_[user][name]=John&_[user][status]=active`\['constraints' =&gt; \['user' =&gt; \['type' =&gt; 'embedded', 'options' =&gt; \['constraints' =&gt; \['name' =&gt; \['type' =&gt; 'string'\],'status' =&gt; \['type' =&gt; 'string'\]\]\]\]\]\]Embedded search. Will search for records that have reference to entity "user", which have name "John" and status "active"`_[age][]=
