alexandrebulete / ddd-foundation
Pure PHP DDD Foundation - Domain, Application, and InMemory infrastructure for building DDD projects
Installs: 0
Dependents: 1
Suggesters: 0
Security: 0
Stars: 0
Watchers: 0
Forks: 0
Open Issues: 0
pkg:composer/alexandrebulete/ddd-foundation
Requires
- php: ^8.2
- symfony/uid: ^7.0
- webmozart/assert: ^1.11
README
Pure PHP DDD Foundation for building Domain-Driven Design projects. This package provides the core building blocks: Domain layer (ValueObjects, Repository interfaces, Exceptions), Application layer (Command/Query/Handler), and InMemory infrastructure for testing.
Installation
composer require alexandrebulete/ddd-foundation
Structure
src/
├── Domain/
│ ├── Exception/
│ │ └── EntityNotFoundException.php
│ ├── Repository/
│ │ ├── PaginatorInterface.php
│ │ └── RepositoryInterface.php
│ └── ValueObject/
│ ├── DatetimeVO.php
│ ├── IdentifierInterface.php
│ ├── IdentifierVO.php
│ └── StringVO.php
├── Application/
│ ├── Command/
│ │ ├── AsCommandHandler.php
│ │ ├── CommandBusInterface.php
│ │ └── CommandInterface.php
│ ├── Handler/
│ │ ├── QueryCollectionHandler.php
│ │ └── QuerySingleHandler.php
│ └── Query/
│ ├── AsQueryHandler.php
│ ├── QueryBusInterface.php
│ └── QueryInterface.php
└── Infrastructure/
└── InMemory/
├── InMemoryPaginator.php
└── InMemoryRepository.php
Usage
Value Objects
use AlexandreBulete\DddFoundation\Domain\ValueObject\IdentifierVO; use AlexandreBulete\DddFoundation\Domain\ValueObject\StringVO; // Generate a new identifier $id = IdentifierVO::generate(); // Create from string $id = IdentifierVO::fromString('01HZXYZ...'); // String value object $title = StringVO::fromString('My Title');
Repository Interface
use AlexandreBulete\DddFoundation\Domain\Repository\RepositoryInterface; class PostRepository implements RepositoryInterface { // Implement the interface methods }
Command/Query Bus
use AlexandreBulete\DddFoundation\Application\Command\CommandInterface; use AlexandreBulete\DddFoundation\Application\Command\AsCommandHandler; // Define a command readonly class CreatePostCommand implements CommandInterface { public function __construct( public string $title, public string $content, ) {} } // Define a handler #[AsCommandHandler] readonly class CreatePostHandler { public function __invoke(CreatePostCommand $command): void { // Handle the command } }
Related Packages
Bridges (pure PHP, no framework dependency)
alexandrebulete/ddd-doctrine-bridge- Doctrine ORM integrationalexandrebulete/ddd-apiplatform-bridge- API Platform integration
Bundles (Symfony integration)
alexandrebulete/ddd-symfony-bundle- Symfony Messenger integrationalexandrebulete/ddd-doctrine-bundle- Doctrine bundle for Symfonyalexandrebulete/ddd-apiplatform-bundle- API Platform bundle for Symfonyalexandrebulete/ddd-sylius-bundle- Sylius Stack integration