kayladnls/spec
最新稳定版本:v0.1.2
Composer 安装命令:
composer require kayladnls/spec
包简介
Specification in PHP
README 文档
README
#Spec A Simple Specification library for PHP
Installation
composer require kayladnls/spec
What is it?
"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." -- wikipedia
How do I use it?
Use the builder
$all_spec = Kayladnls/Spec/Builder::all(new MustHaveFourLegs(), new MustHaveStripesSpec()); $all_spec->isSatisfiedBy($elephpant) //False $all_spec->isSatisfiedBy($zebra) // True $any_spec = Kayladnls/Spec/Builder::any($all_spec, new IsLizardSpec()); $any_spec->isSatisfiedBy($iguana) // True
Or, you can use functions if that's what tickles your fancy.
Function Based
$all_spec = Kayladnls/Spec/all([new MustHaveFourLegs(), new MustHaveStripesSpec()]); Kayladnls/Spec/satisfies($elephpant, $all_spec) //False Kayladnls/Spec/satisfies($zebra, $all_spec) //True $any_spec = Kayladnls/Spec/any([$all_spec, new IsLizardSpec()]); Kayladnls/Spec/satisfies($iguana, $any_spec) // True $none_spec = Kayladnls/Spec/none([new MustHaveFourLegs(), new MustHaveSpotsSpec()]); Kayladnls/Spec/satisfies($kangaroo, $none_spec) // true Kayladnls/Spec/satisfies($cheetah, $none_spec) // false
Example
if ($all_spec->isSatisfiedBy($zebra)){ // Do Some cool Zebra Stuff here. } // Function Based if (satisfies($iguana, $any_spec)){ // do some cool lizard-based stuff here. }
统计信息
- 总下载量: 17
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 12
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-11-03