fragoe / ddd-business-rules-specification
Core library implementing the Specification Pattern for DDD business rules with composable boolean operations.
Package info
github.com/fragoe/ddd-business-rules-specification
pkg:composer/fragoe/ddd-business-rules-specification
Requires
- php: ^8.3
Requires (Dev)
- phpunit/phpunit: ^12.5
README
A lightweight PHP library implementing the Specification Pattern for Domain-Driven Design. Compose business rules with a fluent API using and(), or(), not(), and xor().
Installation
composer require fragoe/ddd-business-rules-specification
Requirements: PHP ^8.3
Usage
Extend CompositeBusinessRule and implement isSatisfiedBy(). Compose rules using the fluent API.
See tests/CompositeBusinessRulesTest.php for comprehensive usage examples including rule creation, composition, and fluent chaining. For a real-world domain example, see tests/CoffeeExamplesTest.php.
Built-in Composites
| Class | Description |
|---|---|
AndBusinessRule |
All rules must be satisfied |
OrBusinessRule |
At least one rule must be satisfied |
XorBusinessRule |
Exactly one rule must be satisfied |
NotBusinessRule |
Inverts the rule result |
Design Philosophy
This library follows strict DDD principles and intentionally excludes infrastructure concerns. Database queries, visualization, and validation framework integration are handled by companion packages:
- ddd-business-rules-doctrine - Doctrine bridge
- ddd-business-rules-analyzer - Static analysis and visualization
Package Ecosystem
| Package | Description |
|---|---|
| fragoe/ddd-business-rules | Meta package |
| fragoe/ddd-business-rules-specification | Core library (this package) |
| fragoe/ddd-business-rules-doctrine | Doctrine bridge |
| fragoe/ddd-business-rules-validation | Validation integration |
| fragoe/ddd-business-rules-analyzer | Analysis tools |
License
MIT - See LICENSE