reformo/backendbase-specification
最新稳定版本:1.0
Composer 安装命令:
composer require reformo/backendbase-specification
包简介
Basic classes for Specification pattern with Notification pattern in PHP.
README 文档
README
Basic classes for Specification pattern in PHP. On top of the typical set of and, or and not specificaitons, anyOf, oneOf, noneOf specifications are proposed.
This package is based on the implementation in carlosbuenosvinos/ddd.
Installation
$ composer require reformo/backendbase-specification
Usage example
<?php use Backendbase\Specification\Specification; use Backendbase\Specification\OneOfSpecification; class Order { public function isPaid() { return true; } public function isShipped() { return false; } public function isCancelled() { return false; } } class UnshippedOrderSpecification extends Specification { public function isSatisfiedBy($order): bool { return !$order->isShipped(); } } class PaidOrderSpecification extends Specification { public function isSatisfiedBy($order): bool { return $order->isPaid(); } } class CancelledOrderSpecification extends Specification { public function isSatisfiedBy($order): bool { return $order->isCancelled(); } } $paid = new PaidOrderSpecification; $unshipped = new UnshippedOrderSpecification; $cancelled = new CancelledOrderSpecification; $paid->and($unshipped)->isSatisfiedBy(new Order); // => true (new OneOfSpecification($paid, $unshipped, $cancelled))->isSatisfiedBy(new Order); // => true
统计信息
- 总下载量: 1.9k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 1
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-07-25