, (*1)
Specification design pattern
Implementation of the "Specification" design pattern., (*2)
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., (*3)
How to
All the classes should extend Kanel/Specification (abstract class), (*4)
$isAvailable = new isProductAvailable();
$isShippable = new isProductShippable();
$isOnSale = new isProductOnSale();
Then perform a composition of specification, (*5)
$specification = $isAvailable->and($isOnSale)->xor($isShippable);
if ($specification->isSatisfiedBy($product)) {
}
Available operators :
If you look for another implementation of the specification design pattern look at kanel/specifications2, (*6)