pauci / cqrs
CQRS library
Installs: 25 024
Dependents: 4
Suggesters: 0
Security: 0
Stars: 15
Watchers: 3
Forks: 3
Open Issues: 4
Requires
- php: ^8.1 || ^8.2
- ext-json: *
- psr/clock: ^1.0
- psr/container: ^1.0 || ^2.0
- ramsey/uuid: ^4.0
Requires (Dev)
- ext-pdo: *
- ext-redis: *
- doctrine/dbal: ^3.2
- doctrine/orm: ^2.8
- guzzlehttp/guzzle: ^7.2
- php-parallel-lint/php-parallel-lint: ^1.3
- phpstan/phpstan: ^1.9
- phpunit/phpunit: ^10.1
- squizlabs/php_codesniffer: ^3.7
- symfony/cache: ^6.0
- symfony/serializer: ^6.0
Suggests
- ramsey/uuid-doctrine: Provides the ability to use ramsey/uuid as a Doctrine field type
- dev-master
- v0.7.1
- v0.7.0
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.2
- v0.5.1
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- v0.3.3
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.5
- v0.2.4
- 0.2.3
- 0.2.2
- 0.2.1
- 0.2.0
- 0.1.3
- 0.1.2
- 0.1.1
- 0.1.0
- dev-feature/doctrine-deprecations
- dev-phpunit-10
- dev-feature/remove-composer-extra
- dev-feature/php-8.2
- dev-feature/psr-20-clock
- dev-feature/event-date-microseconds
This package is auto-updated.
Last update: 2024-12-05 15:05:45 UTC
README
Installation & Requirements
The core library has no dependencies on other libraries. Plugins have dependencies on their specific libraries.
Install with composer:
composer require pauci/cqrs
Usage
final class User extends \CQRS\Domain\Model\AbstractEventSourcedAggregateRoot { private int $id; private string $name; public static function create(int $id, string $name): self { $user = new self($id); $user->apply(new UserCreated($name)); return $user; } private function __construct(int $id) { $this->id = $id; } protected function applyUserCreated(UserCreated $event): void { $this->name = $event->getName(); } public function getId(): int { return $this->id; } public function changeName(string $name): void { if ($name !== $this->name) { $this->apply(new UserNameChanged($name)); } } protected function applyUserNameChanged(UserNameChanged $event): void { $this->name = $event->getName(); } } final class UserCreated { private string $name; public function __construct(string $name) { $this->name = $name; } public function getName(): string { return $this->name; } } final class ChangeUserName { public int $id; public string $name; } final class UserNameChanged { private string $name; public function __construct(string $name) { $this->name = $name; } public function getName(): string { return $this->name; } } class UserService { protected $repository; public function __construct($repository) { $this->repository = $repository; } public function changeUserName(ChangeUserName $command): void { $user = $this->repository->find($command->id); $user->changeName($command->name); } } class EchoEventListener { public function onUserNameChanged( UserNameChanged $event, \CQRS\Domain\Message\Metadata $metadata, \DateTimeInterface $timestamp, int $sequenceNumber, int $userId ): void { echo "Name of user #{$userId} changed to {$event->getName()}.\n"; } } $command = new ChangeUserName([ 'id' => 1, 'name' => 'Jozko Mrkvicka', ]); $commandBus->dispatch($command);