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.
composer require alexandrebulete/ddd-foundationsrc/
├── 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
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');use AlexandreBulete\DddFoundation\Domain\Repository\RepositoryInterface;
class PostRepository implements RepositoryInterface
{
// Implement the interface methods
}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
}
}alexandrebulete/ddd-doctrine-bridge- Doctrine ORM integrationalexandrebulete/ddd-apiplatform-bridge- API Platform 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