Skip to content

andersao/php-fiql-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

32 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FIQL Parser

Latest Stable Version Total Downloads License PHP Version Require Maintainability Test Coverage

A PHP parser for the Feed Item Query Language (FIQL).

Installation

composer require prettus/php-fiql-parser

Using Parser

use \Prettus\FIQLParser\Parser;
use \Prettus\FIQLParser\Expression;
use \Prettus\FIQLParser\Exceptions\FiqlException;

$expression = Parser::fromString('last_name==foo*,(age=lt=55;age=gt=5)');

print_r($expression->toArray());
print_r($expression->toJson());

/**
 * Output of toJson()
 *
 * {"or":[["last_name","==","foo*"],{"and":[["age","<","55"],["age",">","5"]]}]}
 */

/**
 * Output of toArray()
 *
 * [
 *     'or' => [
 *         ['last_name', '==', 'foo*'],
 *         [
 *             'and' => [
 *                 ['age', '<', 55],
 *                 ['age', '>', 5],
 *             ]
 *         ]
 *     ]
 * ]
 * /

Using Builder

use \Prettus\FIQLParser\Expression;
use \Prettus\FIQLParser\Constraint;
use \Prettus\FIQLParser\Operator;
use \Prettus\FIQLParser\Exceptions\FiqlException;

$expression = new Expression();
$expression->addElement(new Constraint('last_name', '==', 'foo*'));
$expression->addElement(new Operator(','));

$subExpression = new Expression();
$subExpression->addElement(new Constraint('age', '=lt=', '55'));
$subExpression->addElement(new Operator(';'));
$subExpression->addElement(new Constraint('age', '=gt=', '5'));

$expression->addElement($subExpression);

print_r(strval($expression));
// last_name==foo*,age=lt=55;age=gt=5

Credits

This project is completely inspired by python fiql-parser

Releases

No releases published

Packages

No packages published

Languages