hoathis / symfony-ruler-bundle
此包已被放弃,不再维护。未建议替代包。
Hoa\Ruler Symfony2 扩展包。
0.16.12.05
2016-12-05 19:55 UTC
Requires
- php: >=5.5
- hoa/ruler: ~2.0
- symfony/framework-bundle: ~2.5|~3.0
This package is auto-updated.
Last update: 2021-09-20 08:34:07 UTC
README
Hoa 是一套 模块化、可扩展 和 结构化 的 PHP 库。此外,Hoa 旨在成为工业和科研世界之间的桥梁。
Hoathis\SymfonyRulerBundle
将 Hoa\Ruler
集成到 Symfony。
安装
使用 Composer,要将此扩展包包含到依赖中,您需要添加 hoathis/symfony-ruler-bundle
{ "require": { "hoathis/symfony-ruler-bundle": "~0.0" } }
并将 RulerBundle
添加到您的 AppKernel
// app/AppKernel.php class AppKernel extends Kernel { // … public function registerBundles() { $bundles = array( // … new Hoathis\SymfonyRulerBundle\HoathisSymfonyRulerBundle(), ); // … } }
快速使用
Ruler 服务
RulerBundle
定义了一个 hoathis.ruler
服务,可以按照 Hoa\Ruler
的文档 进行使用。
public function indexAction(Request $request) { // 1. Write a rule. $ruler = $this->get('hoathis.ruler'); $rule = 'group in ["customer", "guest"] and points > 30'; // 2. Create a context. $context = $ruler->getNewContext(); $context['group'] = 'customer'; $context['points'] = function () { return 42; }; // 3. Assert! var_dump( $ruler->assert($rule, $context) // bool(true) ); }
分析器
当启用调试模式时,所有断言都会被记录并显示在 Web 分析器中
配置参考
hoathis_symfony_ruler: debug: %kernel.debug%
许可证
Hoa 采用新 BSD 许可证 (BSD-3-Clause)。请参阅 LICENSE
。