karboosx/procer 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

karboosx/procer

Composer 安装命令:

composer require karboosx/procer

包简介

Custom language for writing business logic

README 文档

README

logo

Procer

Tests Documentation License Composer

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 supports method should return true if the function is supported by the provider, otherwise it should return false.

Note: The custom_function method receives a Context object as its first argument, followed by the function's arguments as individual parameters (not an array).

The Context object 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

Advanced

  • In-DepthInterruptReason, bytecode debugging, MathExpressionReflection, stopping loops, 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 我们能提供哪些服务?
定制开发 / 二次开发

基于 karboosx/procer 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2024-09-06