PHP code example of digitlab / search-parser

1. Go to this page and download the library: Download digitlab/search-parser 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/ */

    

digitlab / search-parser example snippets


DigitLab\SearchParser\SearchParserServiceProvider::class,

$parser = new SearchParser();
$filters = $parser->parse('string to parse');

[
    'search' => 'string&to&parse'
]

class CustomSearchParser extends SearchParser
{
    /**
     * The filters that should be returned without handlers.
     *
     * @var array
     */
    protected $passthruFilters = ['other'];

    /**
     * Handle the state filter.
     *
     * @param mixed $state
     * @return array
     */
    protected function handleState($state)
    {
        return ['some' => $state];
    }
}

$parser = new CustomSearchParser();
$filters = $parser->parse('state:pending other:string string to parse');

[
    'search' => 'string&to&parse',
    'some' => 'pending',
    'other' => 'string'
]

class CustomSearchParser extends SearchParser
{
    /**
     * The name of the query in the result array.
     *
     * @var string
     */
    protected $queryName = 'other';
}

$parser = new CustomSearchParser();
$filters = $parser->parse('string to parse');

[
    'other' => 'string&to&parse'
]