atyagi / specifier
A library to help implement the specification design pattern
Installs: 21
Dependents: 0
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/atyagi/specifier
Requires (Dev)
- mockery/mockery: dev-master
- nesbot/carbon: ~1.14
- phpunit/phpunit: 4.7.*
- satooshi/php-coveralls: dev-master
This package is not auto-updated.
Last update: 2025-10-25 23:21:42 UTC
README
Provides a basic set of classes to utilize the specification design pattern.
Usage
The included tests provide common usage of the classes.
Basic Usage
Upon creating your specification classes, simply extend the AbstractSpecification class
and implement the isSatisfiedBy method.
Any specifications that you create are flexible enough to take in any arguments in the constructor, such as repositories or services.
In addition, an isNotSatisfiedBy method is provided to provide a logical not if
needed.
Composite Usage
When you need to chain multiple specifications on the same object, you can leverage the
AbstractSpecification chain methods plus and either.
For example:
(new CustomerIsPremium()) ->either(new CustomerRegisteredBeforeLastWeek()) ->isSatisfiedBy($customer);
or
(new CustomerIsPremium()) ->plus(new CustomerRegisteredBeforeLastWeek()) ->isSatisfiedBy($customer);