graviton/rql-parser
最新稳定版本:v3.1.0
Composer 安装命令:
composer require graviton/rql-parser
包简介
README 文档
README
This is a RQL parsing library written in PHP.
This library consists of the following parts:
- lexer for tokenization RQL code
- parser for creating abstract syntax tree
Installation
The preferred way to install library is through composer.
Either run
composer require graviton/rql-parser
or add
"graviton/rql-parser": "*",
to the require section of your composer.json.
Basic usage
<?php require 'vendor/autoload.php'; // default lexer supports all RQL rules $lexer = new Graviton\RqlParser\Lexer(); // default parser contains all parsing strategies $parser = new Graviton\RqlParser\Parser(); // RQL code $rql = '(eq(a,string:1)|lt(b,2)|(c<>3&d>=string:4&e=eq=boolean:1))&u!=5¬(or(u=6,ge(i,10)))&z=1&(a==2|b<-3|in(c,(2,float:3)))&select(a,b)&sort(+a,-b)&limit(1,2)'; // tokenize RQL $tokens = $lexer->tokenize($rql); // parsing var_dump($parser->parse($tokens));
See also rql-command library. This is a console application to debug RQL lexing and parsing.
Advanced usage
See examples:
- Enable only FIQL operators
- Add new query operators
- Add support for aggregate functions
- Convert RQL to SQL
- Add date support
- Use scalars in array nodes
- Add
timestampcaster - Wrap strings with quotes
Current state
Operators
Basic syntax
- scalar operators
eq(a,b)ne(a,b)lt(a,b)gt(a,b)le(a,b)ge(a,b)
- array operators
in(a,(b,c))out(a,(b,c))
- logic operators
and(eq(a,b),ne(c,d))or(eq(a,b),ne(c,d))not(eq(a,b))
Short logic syntax
(eq(a,b)&ne(b,c))(eq(a,b)|ne(b,c))
FIQL syntax
- scalar operators
a=eq=ba=ne=ba=lt=ba=gt=ba=le=ba=ge=b
- array operators
a=in=(b,c)a=out=(b,c)
Simplified FIQL syntax
a=ba==ba<>ba!=ba<ba>ba<=ba>=b
Other
select(a,b,c)sort(+a,-b)limit(1,2)
All syntax variations may be used together.
Value types
- string
abcabc%20def
- integer
1,+1,-1
- float
1.,+1.,-1.0.1,+0.1,-0.1,0.1e5,+0.1e+5,-0.1e-5.1,+.1,-.1.1e5,+.1e+5,-.1e-5
- boolean
true()false()
- null
null()
- empty
empty()
- date
2015-06-02T20:00:00Z
- glob
abc*?abcabc*def?
Type casting
string:1boolean:0integer:afloat:1
Encoding rules
String values
In string values all non-alphanumeric characters must be encoded with a percent (%) sign followed by two hex digits.
Examples:
eq(string,2015%2D05%2D30T15%3A10%3A00Z)
in(string,(%2B1%2E5,%2D1%2E5))
in(string,(null%28%29,empty%28%29,true%28%29,false%28%29))
String encoding in PHP:
function encodeString($value) { return strtr(rawurlencode($value), [ '-' => '%2D', '_' => '%5F', '.' => '%2E', '~' => '%7E', ]); }
String encoding in JavaScript:
function encodeString(value) { return encodeURIComponent(value).replace(/[\-_\.~!\\'\*\(\)]/g, function (char) { return '%' + char.charCodeAt(0).toString(16).toUpperCase(); }); }
Other values
Date, number and const-function values must not be encoded.
Examples:
eq(date,2015-05-30T15:10:00Z)
in(number,(+1.5,-1.5))
in(const,(null(),empty(),true(),false()))
Resources
graviton/rql-parser 适用场景与选型建议
graviton/rql-parser 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 98.82k 次下载、GitHub Stars 达 31, 最近一次更新时间为 2019 年 06 月 20 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「rest」 「parser」 「query」 「language」 「resource」 「rql」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 graviton/rql-parser 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 graviton/rql-parser 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 graviton/rql-parser 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Query filtering in your frontend
Anax Database Active Record module for model classes.
An MT940 bank statement parser for PHP
A PSR-7 compatible library for making CRUD API endpoints
Api bundle
统计信息
- 总下载量: 98.82k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 31
- 点击次数: 19
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2019-06-20