karboosx/procer
Composer 安装命令:
composer require karboosx/procer
包简介
Custom language for writing business logic
README 文档
README
Procer
Procer is a simple and lightweight language designed to describe processes and workflows in a natural and human-readable way. The big advantage of Procer is that it functions can halt the execution of the code and wait for a signal to resume the execution.
Example code:
let shopping_cart be new_shopping_cart(user_account).
let item be product_from_store("apple").
add(item) on shopping_cart.
on user_account do checkout.
Each function call in this example code (new_shopping_cart, product_from_store, add, checkout) is actually a function in php land.
Here you only write the business logic and the implementation is done in php.
Check the Procer Syntax for more information.
Installation
You can install Procer using composer:
composer require karboosx/procer
Usage
use Karboosx\Procer; $procer = new Karboosx\Procer(); $result = $procer->run('let a be 1.'); echo $result->get('a'); // 1
Usage with custom functions
In order to use custom functions in Procer, you need to create a class that implements the FunctionProviderInterface interface and pass an instance of this class to the Karboosx\Procer constructor.
use Karboosx\Procer; $procer = new Karboosx\Procer([ new CustomFunctionProvider() ]); $result = $procer->run('let x be custom_function("hello world!").'); echo $result->get('x'); // "custom function result with argument: hello world!"
The CustomFunctionProvider class should look like this:
class CustomFunctionProvider implements \Karboosx\Procer\FunctionProviderInterface { public function custom_function(Context $context, string $argument): string { return "custom function result with argument: {$argument}"; } public function supports(string $functionName): bool { return in_array($functionName, ['custom_function']); } }
Note: The
supportsmethod should returntrueif the function is supported by the provider, otherwise it should returnfalse.
Note: The
custom_functionmethod receives aContextobject as its first argument, followed by the function's arguments as individual parameters (not an array).The
Contextobject provides access to the variables defined in the Procer code.
Check the Custom Functions documentation for more information.
Evaluation expression
If you want to evaluate just an expression, you can use the runExpression method of the Karboosx\Procer class.
use Karboosx\Procer; $procer = new Procer(); $result = $procer->runExpression('1 + 2 * 3'); echo $result; // 7
Check out the Expression documentation for more information.
Pausing and resuming execution
You can pause the execution of the Procer code and resume it later by resume method.
Good way to stop the execution is to use the wait for signal statement.
use Karboosx\Procer; $procer = new Procer(); $result = $procer->run(<<<CODE let a be 1. wait for signal test_signal. let a be 2. CODE); echo $result->get('a'); // 1 $result = $procer->resume(null, [], ['test_signal']); echo $result->get('a'); // 2
That way you can pause the execution of the script at one point. Wait for user input, or for some event to happen, and then resume the execution of the script.
Check out the Signals documentation for more information.
Also, check out the Serialization documentation for more information how to serialize and unserialize the script.
Documentation
Language
- Procer Syntax — variables, loops, conditions, procedures,
stop, signals - Expressions — operators, precedence, string concatenation, comparisons
PHP integration
- Custom Functions —
FunctionProviderInterface,ContextAPI - Object Functions —
ObjectFunctionProviderInterface - Signals —
wait for signal,wait for all signals, signal statefulness - Interrupts — pausing from inside a function provider
- Serialization — persist and resume a paused process
- Error Handling — exception types and how to catch them
- Security — cycle limits, user-submitted scripts
Advanced
- In-Depth —
InterruptReason, bytecode debugging,MathExpressionReflection,stoppingloops, cycle counter
User submitted code safeness
Code submitted by users is safe to run as far as the provided functions are safe.
Procer does not allow to run any php code (except for the provided functions) and does not allow to include files, write to files, read from files, create objects, use eval, or have access to global variables.
License
This project is open-sourced software licensed under the MIT License. Please see License File for more information.
karboosx/procer 适用场景与选型建议
karboosx/procer 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 48 次下载、GitHub Stars 达 1, 最近一次更新时间为 2024 年 09 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「parser」 「buisness logic」 「procer」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 karboosx/procer 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 karboosx/procer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 karboosx/procer 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Easy to use SDK with grabber for multiple platforms at once like YouTube, Dailymotion, Facebook and more.
Addons to the display-logic module by UncleCheese
An MT940 bank statement parser for PHP
Routes HTTP requests to your code.
Extension provide very simply use enum for models (and others) in yii2
Tests of exceptions hierarchy
统计信息
- 总下载量: 48
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 5
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-09-06
