PHP code example of bravepickle / query-filters-serializer

1. Go to this page and download the library: Download bravepickle/query-filters-serializer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bravepickle / query-filters-serializer example snippets


// ...
use QueryFilterSerializer as App;

$options = new App\Config\Options();
$options->constraints = array('age' => array('type' => 'integer'));
$filterString = 'age:>=14;<18'; // string to parse

$serializer = new QuerySerializer(); // default encoder is StringEncoder so we can skip its init
$serializer->setOptions($options);
$filters = $serializer->unserialize($filterString);

var_export($filters);

// Output:
array (
  'age' => array (
    'constraints' => array (
      array (
        'condition' => 'gte',
        'value' => '14',
      ),
      array (
        'condition' => 'lt',
        'value' => '18',
      ),
    ),
    'type' => 'integer',
    'field' => 'age',
  ),
);


// ...
use QueryFilterSerializer as App;

$options = new App\Config\Options();
$options->constraints = array('age' => array('type' => 'integer'));
$filterQuery = '_[age][]=>=14&_[age][]=<18'; // string to parse
# $filterQuery = ["age" => [">=14", "<18"]];  // this is an alternative way to specify filters. Array used instead

$encoder = new App\Encoder\UrlQueryEncoder();
$options->filterTypeEncoders[App\Filter\Type\EmbeddedType::NAME] =
    App\Encoder\Filter\ArrayEmbeddedTypeEncoder::class; //