gbprod/specification
最新稳定版本:v2.0.1
Composer 安装命令:
composer require gbprod/specification
包简介
Yet another specification pattern implementation
README 文档
README
Yet another specification pattern implementation in PHP.
Usage
Create a Specification
<?php use GBProd\Specification\CompositeSpecification; class PriceGreaterThan extends CompositeSpecification { private $threshold; public function __construct($threshold) { $this->threshold = $threshold; } public function isSatisfiedBy($product): bool { return $product->getPrice() > $this->threshold; } }
Compose your specifications
$expensive = new PriceGreaterThan(1000); $available = new IsAvailable(); $hightStock = new StockGreaterThan(4); $lowStockExpensiveProduct = $expensive ->andX($available) ->andX($hightStock->not()) ;
Use it !
foreach($products as $product) { if ($lowStockExpensiveProduct->isSatisfiedBy($product)) { $this->makeSomethingAwesome($product); } }
Requirements
- PHP 7.0+
For PHP 5 compatibility, use version 1.0
Installation
Using composer
composer require gbprod/specification
统计信息
- 总下载量: 27.07k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 7
- 点击次数: 2
- 依赖项目数: 3
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2016-03-03