https://github.com/tanigami/specification-php
Basic classes for Specification pattern in PHP.
https://github.com/tanigami/specification-php
php7 specification-pattern
Last synced: 8 months ago
JSON representation
Basic classes for Specification pattern in PHP.
- Host: GitHub
- URL: https://github.com/tanigami/specification-php
- Owner: tanigami
- License: mit
- Created: 2017-11-19T15:16:27.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2023-06-06T06:27:46.000Z (over 2 years ago)
- Last Synced: 2025-05-15T07:08:02.847Z (9 months ago)
- Topics: php7, specification-pattern
- Language: PHP
- Size: 17.6 KB
- Stars: 31
- Watchers: 1
- Forks: 5
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# PHP Specification
[](https://scrutinizer-ci.com/g/tanigami/specification-php/?branch=master)
[](https://scrutinizer-ci.com/g/tanigami/specification-php/?branch=master)
[](https://scrutinizer-ci.com/g/tanigami/specification-php/build-status/master)
Basic classes for [Specification pattern](https://en.wikipedia.org/wiki/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](https://github.com/dddinphp/ddd).
## Installation
```
$ composer require tanigami/specification
```
## Usage example
```php
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
```