ernilambar/classifier
最新稳定版本:1.0.0
Composer 安装命令:
composer require ernilambar/classifier
包简介
A PHP library for classifying and grouping data based on JSON configuration rules with schema validation support.
README 文档
README
A PHP library for classifying and grouping data based on JSON configuration rules with schema validation support.
Features
- Flexible Classification: Group data based on prefix or contains matching rules
- JSON Schema Validation: Validate configuration files against JSON schemas
Installation
composer require ernilambar/classifier
Usage
Workflow
The classifier follows this simple workflow:
- Plugin provides JSON file path (via constructor)
- Validate JSON content with schema
- If failed, do not proceed
- If pass, then group based on that JSON file config
use Nilambar\Classifier\Classifier; // Define JSON file path. $json_file_path = '/path/to/groups.json'; // Initialize classifier with JSON file path. $classifier = new Classifier($json_file_path); // Sample data to classify. $data = [ [ 'code' => 'trademark_wordpress', 'type' => 'error', 'message' => 'WordPress trademark violation', ], [ 'code' => 'WordPress.Security.NonceVerification', 'type' => 'warning', 'message' => 'Nonce verification missing', ], ]; // Execute the workflow $result = $classifier->classify($data); if (empty($result)) { echo "Validation failed. Process stopped."; } else { // Process the classified data foreach ($result as $group_id => $items) { echo "Group: {$group_id}\n"; foreach ($items as $item) { echo " - {$item['code']}: {$item['message']}\n"; } } }
Configuration Format
The classifier uses a JSON configuration file to define grouping rules:
{
"$schema": "./groups-schema.json",
"trademark": {
"id": "trademark",
"title": "Trademarks",
"children": {
"trademark_prefix": {
"id": "trademark_prefix",
"title": "Trademarks Prefix",
"type": "prefix",
"parent": "trademark",
"checks": ["trademark_"]
}
}
}
}
Requirements
- PHP 7.4 or higher
- Composer
justinrainbow/json-schemafor schema validation
License
MIT License
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-08-23