gbprod / specification
This package is abandoned and no longer maintained.
No replacement package was suggested.
Yet another specification pattern implementation
v2.0.1
2018-02-08 07:08 UTC
Requires
- php: ^7.0
Requires (Dev)
- phpunit/phpunit: ^6.0|^7.0
This package is auto-updated.
Last update: 2021-01-07 09:13:44 UTC
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