定制 ralphschindler/basic-query-filter 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

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 > 100
  • price > 100 AND active = 1
  • product.price > 100 AND category.id = 7
  • name =~ "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.81k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 14
  • 点击次数: 1
  • 依赖项目数: 3
  • 推荐数: 0

GitHub 信息

  • Stars: 14
  • Watchers: 0
  • Forks: 2
  • 开发语言: PHP

其他信息

  • 授权协议: Unknown
  • 更新时间: 2017-03-28

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固