reformo / backendbase-specification
Basic classes for Specification pattern with Notification pattern in PHP.
Installs: 1 745
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 5
pkg:composer/reformo/backendbase-specification
Requires
- php: ^8.3
- malukenho/mcbumpface: ^1.2.0
Requires (Dev)
- doctrine/coding-standard: ^12.0.0
- phpstan/phpstan: ^1.11
- phpunit/phpunit: ^11.2.8
This package is auto-updated.
Last update: 2025-09-25 21:51:17 UTC
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