ernilambar / classifier
A PHP library for classifying and grouping data based on JSON configuration rules with schema validation support.
1.0.0
2025-08-17 11:22 UTC
Requires
- php: >=7.4
- justinrainbow/json-schema: ^6.4
Requires (Dev)
- dealerdirect/phpcodesniffer-composer-installer: ^1
- ernilambar/coding-standard: ^1
- php-parallel-lint/php-parallel-lint: ^1.4
- phpcompatibility/php-compatibility: dev-develop#9013cd039fe5740953f9fdeebd19d901b80e26f2
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^8
- wp-coding-standards/wpcs: ^3.2
This package is not auto-updated.
Last update: 2025-08-23 22:02:25 UTC
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-schema
for schema validation
License
MIT License