nicoswd/symfony-rule-engine-bundle
Composer 安装命令:
composer require nicoswd/symfony-rule-engine-bundle
包简介
Symfony Rule Engine Bundle - Parses & Evaluates Rules Written in a JavaScript-like Syntax
README 文档
README
This package bundles nicoSWD/php-rule-parser
Requires PHP >= 7.0
Compatible with Symfony 3 and 4!
Install
$ composer require nicoswd/symfony-rule-engine-bundle
<?php // in AppKernel::registerBundles() $bundles = [ // ... new nicoSWD\RuleBundle\RuleBundle(), // ... ];
Usage Example
<?php $rule = '[1, 4, 3].join(glue) === "1-4-3"'; $variables = ['glue' => '-']; $result = $this->get('rule_parser')->isTrue($rule, $variables); var_dump($result); // bool(true)
Custom Functions
Custom functions are automatically discovered. They just need to be configured
as service with the tag nico_swd.rule.function.
If you have multiple functions inside the same directory, the easiest way to make them visible to the bundle is this:
services.yml
AppBundle\Functions\: resource: '../../src/AppBundle/Functions' tags: ['nico_swd.rule.function']
Furthermore, custom functions must implement nicoSWD\Rules\Core\CallableUserFunction
like in the example below
<?php namespace AppBundle\Functions; use nicoSWD\Rules\Core\CallableUserFunction; use nicoSWD\Rules\Tokens\BaseToken; use nicoSWD\Rules\Tokens\TokenArray; class ArrayFilter implements CallableUserFunction { /** * @param BaseToken $param * @param BaseToken $param ... * @return BaseToken */ public function call($param = null) { // Make sure this functions only works on arrays if (!$param instanceof TokenArray) { throw new \InvalidArgumentException(); } return new TokenArray( array_values( array_filter( $param->toArray() ) ) ); } public function getName(): string { return 'array_filter'; } }
The functions optionally retrieve instances of nicoSWD\Rules\Tokens\BaseToken as arguments,
and always must return one as well.
<?php $rule = 'array_filter([0, false, 1]) === [1]'; $result = $this->get('rule_parser')->isTrue($rule); var_dump($result); // bool(true)
nicoswd/symfony-rule-engine-bundle 适用场景与选型建议
nicoswd/symfony-rule-engine-bundle 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 766 次下载、GitHub Stars 达 3, 最近一次更新时间为 2017 年 10 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 nicoswd/symfony-rule-engine-bundle 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 nicoswd/symfony-rule-engine-bundle 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 766
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 3
- 点击次数: 4
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-10-12