承接 parscore/laravel-parscore 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

parscore/laravel-parscore

Composer 安装命令:

composer require parscore/laravel-parscore

包简介

A lightweight and extensible rules engine for Laravel

README 文档

README

A lightweight and extensible rules engine for Laravel. Parse and evaluate conditions with a simple syntax: fn[param1,param2,...]. Built with pure PHP for maximum compatibility and zero external dependencies.

Installation

Install via Composer:

composer require parscore/laravel-parscore

The service provider is automatically registered via Laravel's auto-discovery.

Usage

use ParsCore\Laravel\ParsCore;

$parser = app(ParsCore::class);
$result = $parser->parse('AND[equals[1,1],greater_than[10,5]]');

if ($result) {
    echo "Condition met!";
}

Example Syntax

  • Check if values are equal and one is greater than another:

    AND[equals[1,1],greater_than[10,5]]
    
  • Nested conditions:

    OR[AND[equals[1,1],greater_than[10,5]],NOT[less_than[2,3]]]
    

Supported Commands

Extending ParsCore

  • Define custom commands in app/ParsCore/CustomCommands.php to extend functionality without affecting package updates:

    <?php
    
    use ParsCore\Laravel\ParsCore;
    
    ParsCore::registerCommand('is_positive', function ($params) {
        return $params[0] > 0;
    }, [
        'params' => [
            ['type' => 'any', 'required' => true],
        ],
        'type' => 'condition',
    ]);
    
    ParsCore::registerCommand('contains', function ($params) {
        return str_contains($params[0], $params[1]);
    }, [
        'params' => [
            ['type' => 'any', 'required' => true],
            ['type' => 'any', 'required' => true],
        ],
        'type' => 'condition',
    ]);
  • Then use them:

    $parser = app(ParsCore::class);
    $result = $parser->parse('is_positive[5]'); // true
    $result = $parser->parse('contains[hello world,world]'); // true

Contributing

Submit issues or pull requests to the GitHub repository. We welcome contributions to make ParsCore even better!

License

This package is open-sourced under the .

统计信息

  • 总下载量: 0
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-05-17