Skip to content

Commit 3ac9412

Browse files
author
Jeroen de Graaf
committed
Update gember packages to ^0.3
1 parent 0fdfcb9 commit 3ac9412

21 files changed

+227
-296
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ More about the library and the DCB pattern, see [Gember Event Sourcing](https://
55

66
## This example project
77
_The DCB pattern is an interesting concept, but this does not advocate to remove aggregates completely.
8-
Instead, a hybrid solution with aggregates and business decision models is probably more likely, depending on your domain._
8+
Instead, a hybrid solution with aggregates and use cases is probably more likely, depending on your domain._
99

1010
This example project is using a fictive domain (taken from Sara Pellegrini's blog) where students can subscribe to courses (of any kind).
1111
Deliberately this is all what is defined for this domain, to focus on how this could be implemented when using Event Sourcing with the DCB pattern in mind.
1212

13-
It contains both classic aggregates (e.g. [Course](src/Domain/Course/Course.php), [Student](src/Domain/Student/Student.php)) as well as business decision models (e.g. [ChangeCourseCapacity](src/Domain/Course/ChangeCourseCapacity.php), [SubscribeStudentToCourse](src/Domain/StudentToCourseSubscription/SubscribeStudentToCourse.php), [UnsubscribeStudentFromCourse](src/Domain/StudentToCourseSubscription/UnsubscribeStudentFromCourse.php)).
13+
It contains both classic aggregates (e.g. [Course](src/Domain/Course/Course.php), [Student](src/Domain/Student/Student.php)) as well as use cases (e.g. [ChangeCourseCapacity](src/Domain/Course/ChangeCourseCapacity.php), [SubscribeStudentToCourse](src/Domain/StudentToCourseSubscription/SubscribeStudentToCourse.php), [UnsubscribeStudentFromCourse](src/Domain/StudentToCourseSubscription/UnsubscribeStudentFromCourse.php)).
1414

1515
Inspired by other PHP libraries such as [Broadway](https://github.com/broadway), [EventSauce](https://github.com/EventSaucePHP), [Prooph](https://github.com/prooph) and [Ecotone](https://github.com/ecotoneframework) as well as [Axon Framework](https://github.com/AxonFramework) for Java.
1616

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727
"doctrine/doctrine-migrations-bundle": "^3.3",
2828
"doctrine/orm": "^3.2",
2929
"fakerphp/faker": "^1.23",
30-
"gember/event-sourcing": "^0.1",
31-
"gember/event-sourcing-symfony-bundle": "^0.1",
30+
"gember/event-sourcing": "^0.3",
31+
"gember/event-sourcing-symfony-bundle": "^0.3",
3232
"symfony/console": "7.1.*",
3333
"symfony/dotenv": "7.1.*",
3434
"symfony/flex": "^2",

composer.lock

Lines changed: 125 additions & 194 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Application/Command/Course/ChangeCourseCapacityHandler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Gember\ExampleEventSourcingDcb\Application\Command\Course;
66

7-
use Gember\EventSourcing\Repository\DomainContextNotFoundException;
8-
use Gember\EventSourcing\Repository\DomainContextRepository;
9-
use Gember\EventSourcing\Repository\DomainContextRepositoryFailedException;
7+
use Gember\EventSourcing\Repository\UseCaseNotFoundException;
8+
use Gember\EventSourcing\Repository\UseCaseRepository;
9+
use Gember\EventSourcing\Repository\UseCaseRepositoryFailedException;
1010
use Gember\ExampleEventSourcingDcb\Domain\Course\ChangeCourseCapacity;
1111
use Gember\ExampleEventSourcingDcb\Domain\Course\CourseId;
1212
use Gember\ExampleEventSourcingDcb\Domain\Course\CourseNotFoundException;
@@ -15,21 +15,21 @@
1515
final readonly class ChangeCourseCapacityHandler
1616
{
1717
public function __construct(
18-
private DomainContextRepository $repository,
18+
private UseCaseRepository $repository,
1919
) {}
2020

2121
/**
2222
* @throws CourseNotFoundException
23-
* @throws DomainContextNotFoundException
24-
* @throws DomainContextRepositoryFailedException
23+
* @throws UseCaseNotFoundException
24+
* @throws UseCaseRepositoryFailedException
2525
*/
2626
#[AsMessageHandler(bus: 'command.bus')]
2727
public function __invoke(ChangeCourseCapacityCommand $command): void
2828
{
29-
$context = $this->repository->get(ChangeCourseCapacity::class, new CourseId($command->courseId));
29+
$useCase = $this->repository->get(ChangeCourseCapacity::class, new CourseId($command->courseId));
3030

31-
$context->changeCapacity($command->capacity);
31+
$useCase->changeCapacity($command->capacity);
3232

33-
$this->repository->save($context);
33+
$this->repository->save($useCase);
3434
}
3535
}

src/Application/Command/Course/CreateCourseHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55
namespace Gember\ExampleEventSourcingDcb\Application\Command\Course;
66

7-
use Gember\EventSourcing\Repository\DomainContextRepository;
8-
use Gember\EventSourcing\Repository\DomainContextRepositoryFailedException;
7+
use Gember\EventSourcing\Repository\UseCaseRepository;
8+
use Gember\EventSourcing\Repository\UseCaseRepositoryFailedException;
99
use Gember\ExampleEventSourcingDcb\Domain\Course\Course;
1010
use Gember\ExampleEventSourcingDcb\Domain\Course\CourseId;
1111
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
1212

1313
final readonly class CreateCourseHandler
1414
{
1515
public function __construct(
16-
private DomainContextRepository $repository,
16+
private UseCaseRepository $repository,
1717
) {}
1818

1919
/**
20-
* @throws DomainContextRepositoryFailedException
20+
* @throws UseCaseRepositoryFailedException
2121
*/
2222
#[AsMessageHandler(bus: 'command.bus')]
2323
public function __invoke(CreateCourseCommand $command): void

src/Application/Command/Course/RenameCourseHandler.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,22 @@
44

55
namespace Gember\ExampleEventSourcingDcb\Application\Command\Course;
66

7-
use Gember\EventSourcing\Repository\DomainContextNotFoundException;
8-
use Gember\EventSourcing\Repository\DomainContextRepository;
9-
use Gember\EventSourcing\Repository\DomainContextRepositoryFailedException;
7+
use Gember\EventSourcing\Repository\UseCaseNotFoundException;
8+
use Gember\EventSourcing\Repository\UseCaseRepository;
9+
use Gember\EventSourcing\Repository\UseCaseRepositoryFailedException;
1010
use Gember\ExampleEventSourcingDcb\Domain\Course\Course;
1111
use Gember\ExampleEventSourcingDcb\Domain\Course\CourseId;
1212
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
1313

1414
final readonly class RenameCourseHandler
1515
{
1616
public function __construct(
17-
private DomainContextRepository $repository,
17+
private UseCaseRepository $repository,
1818
) {}
1919

2020
/**
21-
* @throws DomainContextNotFoundException
22-
* @throws DomainContextRepositoryFailedException
21+
* @throws UseCaseNotFoundException
22+
* @throws UseCaseRepositoryFailedException
2323
*/
2424
#[AsMessageHandler(bus: 'command.bus')]
2525
public function __invoke(RenameCourseCommand $command): void

src/Application/Command/Student/CreateStudentHandler.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55
namespace Gember\ExampleEventSourcingDcb\Application\Command\Student;
66

7-
use Gember\EventSourcing\Repository\DomainContextRepository;
8-
use Gember\EventSourcing\Repository\DomainContextRepositoryFailedException;
7+
use Gember\EventSourcing\Repository\UseCaseRepository;
8+
use Gember\EventSourcing\Repository\UseCaseRepositoryFailedException;
99
use Gember\ExampleEventSourcingDcb\Domain\Student\Student;
1010
use Gember\ExampleEventSourcingDcb\Domain\Student\StudentId;
1111
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
1212

1313
final readonly class CreateStudentHandler
1414
{
1515
public function __construct(
16-
private DomainContextRepository $repository,
16+
private UseCaseRepository $repository,
1717
) {}
1818

1919
/**
20-
* @throws DomainContextRepositoryFailedException
20+
* @throws UseCaseRepositoryFailedException
2121
*/
2222
#[AsMessageHandler(bus: 'command.bus')]
2323
public function __invoke(CreateStudentCommand $command): void

src/Application/Command/StudentToCourseSubscription/SubscribeStudentToCourseHandler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Gember\ExampleEventSourcingDcb\Application\Command\StudentToCourseSubscription;
66

7-
use Gember\EventSourcing\Repository\DomainContextNotFoundException;
8-
use Gember\EventSourcing\Repository\DomainContextRepository;
9-
use Gember\EventSourcing\Repository\DomainContextRepositoryFailedException;
7+
use Gember\EventSourcing\Repository\UseCaseNotFoundException;
8+
use Gember\EventSourcing\Repository\UseCaseRepository;
9+
use Gember\EventSourcing\Repository\UseCaseRepositoryFailedException;
1010
use Gember\ExampleEventSourcingDcb\Domain\Course\CourseId;
1111
use Gember\ExampleEventSourcingDcb\Domain\Course\CourseNotFoundException;
1212
use Gember\ExampleEventSourcingDcb\Domain\Student\StudentId;
@@ -19,28 +19,28 @@
1919
final readonly class SubscribeStudentToCourseHandler
2020
{
2121
public function __construct(
22-
private DomainContextRepository $repository,
22+
private UseCaseRepository $repository,
2323
) {}
2424

2525
/**
2626
* @throws CourseCannotAcceptMoreStudentsException
2727
* @throws CourseNotFoundException
2828
* @throws StudentCannotSubscribeToMoreCoursesException
2929
* @throws StudentNotFoundException
30-
* @throws DomainContextNotFoundException
31-
* @throws DomainContextRepositoryFailedException
30+
* @throws UseCaseNotFoundException
31+
* @throws UseCaseRepositoryFailedException
3232
*/
3333
#[AsMessageHandler(bus: 'command.bus')]
3434
public function __invoke(SubscribeStudentToCourseCommand $command): void
3535
{
36-
$context = $this->repository->get(
36+
$useCase = $this->repository->get(
3737
SubscribeStudentToCourse::class,
3838
new CourseId($command->courseId),
3939
new StudentId($command->studentId),
4040
);
4141

42-
$context->subscribe();
42+
$useCase->subscribe();
4343

44-
$this->repository->save($context);
44+
$this->repository->save($useCase);
4545
}
4646
}

src/Application/Command/StudentToCourseSubscription/UnsubscribeStudentFromCourseHandler.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
namespace Gember\ExampleEventSourcingDcb\Application\Command\StudentToCourseSubscription;
66

7-
use Gember\EventSourcing\Repository\DomainContextNotFoundException;
8-
use Gember\EventSourcing\Repository\DomainContextRepository;
9-
use Gember\EventSourcing\Repository\DomainContextRepositoryFailedException;
7+
use Gember\EventSourcing\Repository\UseCaseNotFoundException;
8+
use Gember\EventSourcing\Repository\UseCaseRepository;
9+
use Gember\EventSourcing\Repository\UseCaseRepositoryFailedException;
1010
use Gember\ExampleEventSourcingDcb\Domain\Course\CourseId;
1111
use Gember\ExampleEventSourcingDcb\Domain\Course\CourseNotFoundException;
1212
use Gember\ExampleEventSourcingDcb\Domain\Student\StudentId;
@@ -17,26 +17,26 @@
1717
final readonly class UnsubscribeStudentFromCourseHandler
1818
{
1919
public function __construct(
20-
private DomainContextRepository $repository,
20+
private UseCaseRepository $repository,
2121
) {}
2222

2323
/**
2424
* @throws CourseNotFoundException
2525
* @throws StudentNotFoundException
26-
* @throws DomainContextNotFoundException
27-
* @throws DomainContextRepositoryFailedException
26+
* @throws UseCaseNotFoundException
27+
* @throws UseCaseRepositoryFailedException
2828
*/
2929
#[AsMessageHandler(bus: 'command.bus')]
3030
public function __invoke(UnsubscribeStudentFromCourseCommand $command): void
3131
{
32-
$context = $this->repository->get(
32+
$useCase = $this->repository->get(
3333
UnsubscribeStudentFromCourse::class,
3434
new CourseId($command->courseId),
3535
new StudentId($command->studentId),
3636
);
3737

38-
$context->unsubscribe();
38+
$useCase->unsubscribe();
3939

40-
$this->repository->save($context);
40+
$this->repository->save($useCase);
4141
}
4242
}

src/Domain/Course/ChangeCourseCapacity.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,20 @@
44

55
namespace Gember\ExampleEventSourcingDcb\Domain\Course;
66

7-
use Gember\EventSourcing\DomainContext\Attribute\DomainEventSubscriber;
8-
use Gember\EventSourcing\DomainContext\Attribute\DomainId;
9-
use Gember\EventSourcing\DomainContext\EventSourcedDomainContext;
10-
use Gember\EventSourcing\DomainContext\EventSourcedDomainContextBehaviorTrait;
7+
use Gember\EventSourcing\UseCase\Attribute\DomainEventSubscriber;
8+
use Gember\EventSourcing\UseCase\Attribute\DomainId;
9+
use Gember\EventSourcing\UseCase\EventSourcedUseCase;
10+
use Gember\EventSourcing\UseCase\EventSourcedUseCaseBehaviorTrait;
1111

1212
/**
13-
* Business decision model based one domain identifier.
13+
* Use case based one domain identifier.
1414
*/
15-
final class ChangeCourseCapacity implements EventSourcedDomainContext
15+
final class ChangeCourseCapacity implements EventSourcedUseCase
1616
{
17-
use EventSourcedDomainContextBehaviorTrait;
17+
use EventSourcedUseCaseBehaviorTrait;
1818

1919
/*
20-
* Define to which domain identifiers this context belongs to.
20+
* Define to which domain identifiers this use case belongs to.
2121
*/
2222
#[DomainId]
2323
private CourseId $courseId;
@@ -54,7 +54,7 @@ public function changeCapacity(int $capacity): void
5454

5555
/*
5656
* Change internal state by subscribing to relevant domain events for any of the domain identifiers,
57-
* so that this context can apply its business rules.
57+
* so that this use case can apply its business rules.
5858
*/
5959
#[DomainEventSubscriber]
6060
private function onCourseCreatedEvent(CourseCreatedEvent $event): void

0 commit comments

Comments
 (0)