Download the PHP package madong/query without Composer
On this page you can find all versions of the php package madong/query. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Vendor madong
Package query
Short Description The Madong Query component - A powerful query parameter parsing and filtering library
License Apache-2.0
Package query
Short Description The Madong Query component - A powerful query parameter parsing and filtering library
License Apache-2.0
Please rate this library. Is it a good library?
Informations about the package query
Madong Query
一个强大的查询参数解析和过滤库,为 PHP 8.1+ 项目提供灵活、类型安全的查询构建能力。
✨ 特性
- 🚀 高性能: 轻量级设计,最小化性能开销
- 🔒 类型安全: 使用 PHP 8.1+ 枚举提供编译时类型检查
- 🎯 灵活配置: 支持多种查询模式和参数格式
- 🛠 易于集成: 提供多种集成方式(Trait、依赖注入、门面)
- 📝 优雅 API: 直观的接口设计,降低学习成本
- 🧪 完整测试: 全面的测试覆盖
- 📦 零依赖: 仅依赖 Illuminate 组件
- 🎛 高度可配置: SelectInput 支持字段过滤、格式限定、自定义返回格式等
📦 安装
通过 Composer 安装:
环境要求
- PHP >= 8.1
- illuminate/database >= 11.0
- illuminate/pagination >= 11.0
🚀 快速开始
基本使用
使用 Trait(推荐)
在 Controller 中使用:
使用门面(CLI 环境)
📖 核心概念
查询参数格式
支持多种查询参数格式:
1. 标准 filters 格式
2. 大写前缀格式
3. 数组格式
支持的操作符
| 操作符 | 说明 | 示例 |
|---|---|---|
eq |
等于 | ['field' => 'status', 'operator' => 'eq', 'value' => 'active'] |
ne |
不等于 | ['field' => 'status', 'operator' => 'ne', 'value' => 'deleted'] |
gt |
大于 | ['field' => 'age', 'operator' => 'gt', 'value' => 18] |
gte |
大于等于 | ['field' => 'age', 'operator' => 'gte', 'value' => 18] |
lt |
小于 | ['field' => 'age', 'operator' => 'lt', 'value' => 60] |
lte |
小于等于 | ['field' => 'age', 'operator' => 'lte', 'value' => 60] |
like |
模糊匹配 | ['field' => 'name', 'operator' => 'like', 'value' => 'John'] |
ilike |
不区分大小写模糊匹配 | ['field' => 'name', 'operator' => 'ilike', 'value' => 'john'] |
in |
包含 | ['field' => 'id', 'operator' => 'in', 'value' => [1, 2, 3]] |
not_in |
不包含 | ['field' => 'id', 'operator' => 'not_in', 'value' => [4, 5, 6]] |
between |
范围 | ['field' => 'price', 'operator' => 'between', 'value' => [10, 100]] |
not_between |
非范围 | ['field' => 'price', 'operator' => 'not_between', 'value' => [10, 100]] |
null |
为空 | ['field' => 'deleted_at', 'operator' => 'null'] |
not_null |
不为空 | ['field' => 'deleted_at', 'operator' => 'not_null'] |
枚举类型
Operator 枚举
QueryMode 枚举
ParamFormat 枚举
🎯 高级用法
自定义查询选项
关键词搜索
分页查询
排序
多层查询
🔧 集成方式
1. Controller 集成
2. Service 集成
3. DAO 集成
4. 依赖注入
5. SelectInput 集成(灵活参数解析)
WithSelectInput Trait 提供高度可配置的参数解析功能,适用于需要精确控制的场景。
基本使用
自定义配置
配置选项
| 选项 | 类型 | 默认值 | 说明 |
|---|---|---|---|
return_format |
string |
'array' |
返回格式:array、object、compact |
param_format |
string |
'auto' |
参数格式:filters、uppercase、array、where、auto |
allowed_fields |
array\|null |
null |
允许的字段白名单 |
skip_fields |
array |
[] |
跳过的字段黑名单 |
sort_fields |
array\|null |
null |
允许排序的字段 |
default_sort |
array |
[] |
默认排序规则 |
default_page_size |
int |
10 |
默认每页数量 |
max_page_size |
int |
100 |
最大每页数量 |
default_page |
int |
1 |
默认页码 |
keyword_fields |
array |
[] |
关键词搜索字段 |
enable_keyword_search |
bool |
false |
是否启用关键词搜索 |
keyword_param |
string |
'keyword' |
关键词参数名 |
enable_range_query |
bool |
true |
是否启用范围查询 |
enable_like_query |
bool |
true |
是否启用模糊匹配 |
auto_convert_datetime |
bool |
true |
是否自动转换日期时间 |
skip_empty_values |
bool |
true |
是否跳过空值 |
debug_mode |
bool |
false |
是否启用调试模式 |
在 Crud 中使用(推荐)
配置优先级:方法参数配置 > 类属性配置 > 默认配置
🛠️ 核心类
QueryParamsManager
查询参数管理器,提供统一的查询处理入口。
QueryCondition
查询条件对象,封装单个查询条件。
QueryParamParser
查询参数解析器,支持多种参数格式。
QueryBuilderHelper
查询构建器辅助类,应用查询条件到构建器。
QueryParamConverter
参数转换器,转换不同格式的参数。
QueryFacade
门面类,提供静态访问接口(适用于 CLI 环境)。
🧪 异常处理
QueryException
基础查询异常。
QueryParseException
查询参数解析异常。
📚 完整示例
用户管理接口
高级查询示例
关键词搜索示例
🎨 最佳实践
1. 使用 Trait 简化代码
2. 配置允许查询的字段
3. 设置分页限制
4. 使用关键词搜索
🔒 安全建议
- 限制允许查询的字段: 使用
allowed_fields选项 - 设置分页上限: 使用
max_page_size选项 - 验证输入数据: 对用户输入进行验证
- 使用参数绑定: 底层自动使用参数绑定防止 SQL 注入
📄 许可证
Apache-2.0 License
👨💻 作者
Mr. April - [email protected]
🌐 官方网站
🤝 贡献
欢迎提交 Issue 和 Pull Request!
📞 支持
如有问题,请提交 Issue 或联系作者。
All versions of query with dependencies
PHP Build Version
Package Version
Requires
php Version
>=8.1
illuminate/database Version ^11.0
illuminate/pagination Version ^11.0
madong/helper Version ^1.1
illuminate/database Version ^11.0
illuminate/pagination Version ^11.0
madong/helper Version ^1.1
The package madong/query contains the following files
Loading the files please wait ...