samsin33/laravel-decision-engine
Composer 安装命令:
composer require samsin33/laravel-decision-engine
包简介
This package provide support for making decision engine in laravel.
README 文档
README
Decision Engine package for laravel. This package provide support for making decision engine in laravel version 9.
Installation
Just install samsin33/laravel-decision-engine package with composer.
$ composer require samsin33/laravel-decision-engine
Database Migration
Decision Engine service provider registers its own database migration directory, so remember to migrate your database after installing the package. The migrations will add 3 tables to your database:
$ php artisan migrate
If you need to overwrite the migrations that ship with this package, you can publish them using the vendor:publish Artisan command:
$ php artisan vendor:publish --tag="decision-engine-migrations"
If you would like to prevent Decision Engine's migrations from running entirely, you may use the ignoreMigrations method provided by DecisionEngine. Typically, this method should be called in the register method of your AppServiceProvider:
use Samsin33\DecisionEngine\DecisionEngine; /** * Register any application services. * * @return void */ public function register() { DecisionEngine::ignoreMigrations(); }
Publish Config
If you need to overwrite the config file that ship with this package, you can publish them using the vendor:publish Artisan command:
$ php artisan vendor:publish --tag="decision-engine-config"
Env Configuration
You can change your database connection for models, default will be your DB_CONNECTION if not then mysql. If you wish to change this you can specify a different connection in your .env file:
DECISION_ENGINE_CONNECTION=mysql
You can change your database primary key type for models, default is bigInt. If you wish to change this to uuid you can specify it in your .env file.
For now only bit integer and uuid is supported.
DECISION_ENGINE_PRIMARY_KEY_TYPE=uuid
Publish Views
You need to overwrite the view files that ship with this package and can change according to your design, you can publish them using the vendor:publish Artisan command:
$ php artisan vendor:publish --tag="decision-engine-views"
Showing and Creating Rule Engine
For index page and create page of Rule Engine goto routes
/decision-engine/rule-engines /decision-engine/rule-engines/create
You can add these routes to your menu to access them. All the required routes are already registered.
Rule Engine Types
For now this package supports only 2 types of Rule Engine.
- Code - Set of code will be executed which u will put in business rules column on the basis of the input you provide.
- Command - A command will be executed which u will put in business rules column on the basis of the input you provide.
Route Guards
Your web routes are contained inside web_guards. Your api routes are contained inside api_guards. You can change them in config files.
Example - Making a calculator
As an example lets a make a calculator.
Create a rule engine:
Name - Calculator
Type - Code
Validation - This should be an array of validation rules of your input. E.g.
You can also make your own validations and use.
Business Rules - This should be the code which runs when the validation will pass.

Status - It should be active for rule execution.
Your business rules should always return a value to show an output.
For a command example. Make a command Calculator with:
signature - calc {num1} {num2} {process}
and in the Business Rules field should be:
Business Rules - calc $num1 $num2 $process
the output of command type has 2 attributes result and info
result - returns integer from command.
info - save the output of the command, i.e. anything printed in line, info, comment, question, warn, and error methods.
Executing Business Rules on input
To execute business rules you need to call the api.
URL: /decision-engine/rule-executions
Headers: {
"accept": "application/json",
"content-type": "application/json"
}
# Other headers attributes depends on your api guards.
Request:
{
"rule_execution": {
"rule_engine_id": 1,
"input": {
"num1": 45,
"num2": 6,
"process": "add"
}
}
}
Response:
{
"output": {
"status": "Code Success",
"output": {
"add": 51
}
},
"rule_execution": {
"rule_engine_id": 1,
"input": {
"num1": 45,
"num2": 6,
"process": "add"
},
"id": 1,
"status": "Code Success",
"updated_at": "2022-11-20T16:10:59.000000Z",
"created_at": "2022-11-20T16:10:58.000000Z",
"output": "{\"add\":51}"
}
}
Note
- Input should be associative array.
- Your input keys will be converted to variables in the business rules value.
samsin33/laravel-decision-engine 适用场景与选型建议
samsin33/laravel-decision-engine 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 11 次下载、GitHub Stars 达 4, 最近一次更新时间为 2022 年 11 月 08 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「rule engine」 「decision engine」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 samsin33/laravel-decision-engine 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 samsin33/laravel-decision-engine 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 samsin33/laravel-decision-engine 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
ContentElement for Contao to generate hr. Simply choose element type "divider" and save.
Magento 2 Discount Amount Limiter
A SilverStripe module to optimise the Meta, crawling, indexing, and sharing of your website content (forked from Cyber-Duck/Silverstripe-SEO)
Business rules engine tools.
A Processor for Markup written in PHP. Allows extraction of Markup into a data structure, orchestrated nested manipulation of said structure, and output as (optimized) Markup.
Allow KoolReport to use twig template engine to render view
统计信息
- 总下载量: 11
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 6
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2022-11-08