danfekete/spec
Composer 安装命令:
composer require danfekete/spec
包简介
Specification pattern
README 文档
README
Spec is a PHP implementation of the Specification pattern which can be used for building simple or complex business rules.
In computer programming, the specification pattern is a particular software design pattern, whereby business rules can be recombined by chaining the business rules together using boolean logic. The pattern is frequently used in the context of domain-driven design.
The library uses the incredible expression-language component from Symfony to provide the DSL for expressions.
Installation
$ composer require danfekete/spec
Usage
1. Simple expression
$d = [2]; $spec = new Specification(new ExpressionSpec('1 > d[0]')); $spec->isSatisfiedBy(['d' => $d]); // return false
2. Boolean chaining
/* * You can use classes in expression code */ class Nan { public function isNan($value) { return is_nan($value); } } $spec = new Specification(new AndSpec( new NotSpec(new ExpressionSpec('checker.isNan(d)')), new OrSpec( new ExpressionSpec('d != 12'), new ExpressionSpec('d > 10') ), new AndSpec( new ExpressionSpec('d > 5'), new ExpressionSpec('d < 20') ) )); $spec->isSatisfiedBy(['d' => 17, 'checker' => new Nan()]); // return true
TODO
- Cache parsed code permanently
Array builder, builds specification from arraysJSON builder
License
MIT, see LICENSE
统计信息
- 总下载量: 58
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-05-25