ralphschindler/basic-query-filter
最新稳定版本:0.1.0
Composer 安装命令:
composer require ralphschindler/basic-query-filter
包简介
Basic Query Filter
README 文档
README
This started out as a weekend-project. A DSL Parser for a filter query langague that primarily can be used in an API or similar setting where filtering is based on predicate logic.
The goal is to be able to take string filters and parse them into predicate expression objects in order to adjoin them to a backend implementation. This backend implementation could be Doctrine, Laravel Eloquent, or document storage.
Example queries in this language:
price > 100price > 100 AND active = 1product.price > 100 AND category.id = 7name =~ "Foo%"created_at > "2017-01-01" and created_at < "2017-01-31"status = 1 AND (name = "PHP Rocks" || name = "I ♥ API's")
Install
composer require "ralphschindler/basic-query-filter"
Usage
Basic usage is to take a string and parse it, using the ParseTree to be able to convert the expressions to whatever is required by the library you are adjoining.
$parseTree = (new QueryFilter\Parser)->parse($filter); foreach ($parseTree->getPredicates() as $predicateInfo) { list($combinedBy, $predicate) = $predicateInfo; // ... }
Laravel
Expand usage as necessary to accommodate more filtering features.
// $modelQuery is a Model::newQuery() instance (Illuminate\Database\Eloquent\Builder) foreach ($parseTree->getPredicates() as $predicateInfo) { list($combinedBy, $predicate) = $predicateInfo; $op = ($predicate->op == '=~') ? 'like' : $predicate->op; if ($combinedBy === 'OR') { $modelQuery->orWhere((string)$predicate->left, $op, $predicate->right); } else { $modelQuery->where((string)$predicate->left, $op, $predicate->right); } }
统计信息
- 总下载量: 5.63k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 14
- 点击次数: 0
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: Unknown
- 更新时间: 2017-03-28