kanel / specification
An implementation of the Specification design pattern
1.0.0
2017-07-13 12:34 UTC
Requires
- php: >=7.0.0
Requires (Dev)
- phpspec/phpspec: ^3.4
- phpunit/phpunit: 6.0.8
This package is not auto-updated.
Last update: 2024-11-10 04:53:27 UTC
README
Specification design pattern
Implementation of the "Specification" design pattern.
The Goal of this pattern is to have separate classes of logic in order to do condition composition without rewriting and maintaining the conditions at different places.
How to
All the classes should extend Kanel/Specification (abstract class)
$isAvailable = new isProductAvailable();
$isShippable = new isProductShippable();
$isOnSale = new isProductOnSale();
Then perform a composition of specification
$specification = $isAvailable->and($isOnSale)->xor($isShippable);
if ($specification->isSatisfiedBy($product)) {
}
Available operators :
- and
- or
- xor
- not
If you look for another implementation of the specification design pattern look at kanel/specifications2