From f3a9a7e63b1fe6bd21fef3fcc4c2ee9b35856a37 Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Thu, 1 Jan 2026 22:00:17 +0000 Subject: [PATCH 1/8] wip: initial restructure of bus --- deptrac.yaml | 48 ++++---- .../application/asynchronous-processing.md | 7 +- docs/guide/application/commands.md | 57 +++------ docs/guide/application/domain-events.md | 113 ++++++++---------- docs/guide/application/integration-events.md | 63 +++------- docs/guide/application/queries.md | 35 ++---- docs/guide/application/units-of-work.md | 34 ++---- .../infrastructure/dependency-injection.md | 27 ++--- .../infrastructure/exception-reporting.md | 8 +- docs/guide/infrastructure/outbox.md | 8 +- .../guide/infrastructure/publishing-events.md | 23 ++-- docs/guide/infrastructure/queues.md | 65 +++++----- .../AbortOnFailureException.php | 2 +- src/Application/Bus/CommandQueuer.php | 6 +- .../Bus/Middleware/ExecuteInUnitOfWork.php | 19 +-- .../Bus/Middleware/FlushDeferredEvents.php | 16 +-- .../Middleware/FlushDeferredEvents.php | 38 ------ .../Middleware/HandleInUnitOfWork.php | 40 ------- .../UnitOfWork/UnitOfWorkManager.php | 4 +- src/Bus/BusException.php | 19 +++ .../Bus/CommandDispatcher.php | 11 +- src/{Application => }/Bus/CommandHandler.php | 7 +- .../Bus/CommandHandlerContainer.php | 11 +- .../InboundEventBus => Bus}/EventHandler.php | 7 +- .../EventHandlerContainer.php | 13 +- .../Messages => Bus}/HandlesMessages.php | 4 +- .../InboundEventDispatcher.php | 11 +- .../Loggable/ObjectDecorator.php | 6 +- .../Loggable/ResultDecorator.php | 6 +- src/{Toolkit => Bus}/Loggable/Sensitive.php | 2 +- .../Loggable/SimpleContextFactory.php | 8 +- .../Middleware/LogInboundEvent.php | 10 +- .../Bus/Middleware/LogMessageDispatch.php | 17 ++- .../Bus/Middleware/SetupBeforeDispatch.php | 9 +- .../Middleware/SetupBeforeEvent.php | 6 +- .../Bus/Middleware/TearDownAfterDispatch.php | 9 +- .../Middleware/TearDownAfterEvent.php | 6 +- .../Bus/Middleware/ValidateCommand.php | 10 +- .../Bus/Middleware/ValidateQuery.php | 10 +- src/Bus/PsrPipeContainer.php | 56 +++++++++ src/{Application => }/Bus/QueryDispatcher.php | 11 +- src/{Application => }/Bus/QueryHandler.php | 7 +- .../Bus/QueryHandlerContainer.php | 11 +- .../SwallowInboundEvent.php | 4 +- .../Validation}/ValidationProcessor.php | 6 +- .../Bus => Bus/Validation}/Validator.php | 8 +- src/{Application => }/Bus/WithCommand.php | 4 +- .../InboundEventBus => Bus}/WithDefault.php | 2 +- .../InboundEventBus => Bus}/WithEvent.php | 4 +- src/{Application => }/Bus/WithQuery.php | 4 +- .../Application/Bus/BusMiddleware.php | 29 ----- .../Ports/{Driven => }/ExceptionReporter.php | 2 +- .../{Driven => }/OutboundEventPublisher.php | 4 +- .../Application/Ports/{Driven => }/Queue.php | 4 +- .../Ports/{Driven => }/UnitOfWork.php | 2 +- .../{Toolkit/Messages => Bus}/Command.php | 2 +- .../Driving => Bus}/CommandDispatcher.php | 3 +- .../{Application => }/Bus/CommandHandler.php | 4 +- .../Bus/CommandHandlerContainer.php | 4 +- .../Ports/Driving => Bus}/CommandQueuer.php | 4 +- .../DispatchThroughMiddleware.php | 2 +- .../InboundEventBus => Bus}/EventHandler.php | 5 +- .../EventHandlerContainer.php | 4 +- .../InboundEventDispatcher.php | 4 +- .../Messages => Bus}/IntegrationEvent.php | 2 +- .../Loggable/ContextFactory.php | 4 +- .../Loggable/ContextProvider.php | 2 +- .../{Toolkit => Bus}/Loggable/Contextual.php | 2 +- .../{Toolkit/Messages => Bus}/Message.php | 2 +- .../Bus/Middleware/BusMiddleware.php | 28 +++++ .../Middleware}/CommandMiddleware.php | 4 +- .../Middleware}/InboundEventMiddleware.php | 4 +- .../Middleware}/QueryMiddleware.php | 4 +- .../{Toolkit/Messages => Bus}/Query.php | 2 +- .../Ports/Driving => Bus}/QueryDispatcher.php | 3 +- .../{Application => }/Bus/QueryHandler.php | 4 +- .../Bus/QueryHandlerContainer.php | 4 +- .../Bus => Bus/Validation}/Bail.php | 2 +- .../Bus => Bus/Validation}/Validator.php | 6 +- .../OutboundEventMiddleware.php | 2 +- .../OutboundEventBus/PublisherHandler.php | 2 +- .../PublisherHandlerContainer.php | 2 +- .../Infrastructure/Queue/Enqueuer.php | 2 +- .../Queue/EnqueuerContainer.php | 2 +- .../Infrastructure/Queue/QueueMiddleware.php | 2 +- .../Toolkit/Identifiers/Identifier.php | 8 +- .../PsrLogExceptionReporter.php | 4 +- .../OutboundEventBus/ClosurePublisher.php | 14 ++- .../OutboundEventBus/ComponentPublisher.php | 8 +- .../Middleware/LogOutboundEvent.php | 6 +- .../OutboundEventBus/PublisherHandler.php | 2 +- .../PublisherHandlerContainer.php | 4 +- .../OutboundEventBus/Publishes.php | 2 +- src/Infrastructure/Queue/ClosureQueue.php | 14 ++- src/Infrastructure/Queue/ComponentQueue.php | 8 +- src/Infrastructure/Queue/Enqueuer.php | 2 +- .../Queue/EnqueuerContainer.php | 2 +- .../Queue/Middleware/LogPushedToQueue.php | 6 +- src/Infrastructure/Queue/Queues.php | 2 +- src/Testing/FakeContainer.php | 4 +- src/Testing/FakeExceptionReporter.php | 2 +- src/Testing/FakeOutboundEventPublisher.php | 4 +- src/Testing/FakeQueue.php | 4 +- src/Testing/FakeUnitOfWork.php | 2 +- src/Toolkit/Pipeline/PipeContainer.php | 11 -- src/Toolkit/Pipeline/PipelineBuilder.php | 7 +- src/Toolkit/Result/FailedResultException.php | 9 +- .../{Application => }/Bus/AddCommand.php | 4 +- .../Bus/AddCommandHandler.php | 2 +- .../DefaultEventHandler.php} | 6 +- .../{Application => }/Bus/DivideQuery.php | 4 +- .../Bus/DivideQueryHandler.php | 2 +- .../{Application => }/Bus/FloorCommand.php | 4 +- .../{Application => }/Bus/MathCommandBus.php | 8 +- .../Bus/MathCommandBusTest.php | 4 +- .../InboundEventBus => Bus}/MathEventBus.php | 12 +- .../MathEventBusTest.php | 12 +- .../{Application => }/Bus/MathQueryBus.php | 8 +- .../Bus/MathQueryBusTest.php | 4 +- .../{Application => }/Bus/MultiplyCommand.php | 4 +- .../Bus/MultiplyCommandHandler.php | 2 +- .../InboundEventBus => Bus}/NumbersAdded.php | 4 +- .../NumbersAddedHandler.php | 2 +- .../NumbersDivided.php | 4 +- .../NumbersSubtracted.php | 4 +- .../NumbersSubtractedHandler.php | 6 +- .../{Application => }/Bus/SubtractQuery.php | 4 +- .../Bus/SubtractQueryHandler.php | 2 +- .../OutboundEventBus/MathEventPublisher.php | 6 +- .../MathEventPublisherTest.php | 6 +- .../NumbersAddedPublisher.php | 2 +- .../NumbersSubtractedPublisher.php | 2 +- .../TestClosurePublisherTest.php | 2 +- .../OutboundEventBus/TestDefaultPublisher.php | 2 +- .../Queue/AddCommandEnqueuer.php | 2 +- .../Infrastructure/Queue/MathQueue.php | 4 +- .../Infrastructure/Queue/MathQueueTest.php | 6 +- .../Queue/MultiplyCommandEnqueuer.php | 2 +- .../Queue/TestClosureQueueTest.php | 2 +- .../Queue/TestDefaultEnqueuer.php | 2 +- .../Application/Bus/CommandDispatcherTest.php | 8 +- .../Bus/CommandHandlerContainerTest.php | 12 +- .../Application/Bus/CommandHandlerTest.php | 2 +- .../Application/Bus/CommandQueuerTest.php | 2 +- .../Middleware/ExecuteInUnitOfWorkTest.php | 2 +- .../Middleware/FlushDeferredEventsTest.php | 2 +- .../Bus/Middleware/LogMessageDispatchTest.php | 10 +- .../Middleware/SetupBeforeDispatchTest.php | 6 +- .../Middleware/TearDownAfterDispatchTest.php | 6 +- .../Bus/Middleware/ValidateCommandTest.php | 8 +- .../Bus/Middleware/ValidateQueryTest.php | 8 +- .../Application/Bus/QueryDispatcherTest.php | 8 +- .../Bus/QueryHandlerContainerTest.php | 12 +- .../Unit/Application/Bus/QueryHandlerTest.php | 2 +- tests/Unit/Application/Bus/TestCommand.php | 2 +- .../Application/Bus/TestCommandHandler.php | 2 +- tests/Unit/Application/Bus/TestQuery.php | 2 +- .../Unit/Application/Bus/TestQueryHandler.php | 2 +- tests/Unit/Application/Bus/ValidatorTest.php | 6 +- .../EventHandlerContainerTest.php | 8 +- .../InboundEventBus/EventHandlerTest.php | 2 +- .../InboundEventDispatcherTest.php | 8 +- .../Middleware/FlushDeferredEventsTest.php | 94 --------------- .../Middleware/HandleInUnitOfWorkTest.php | 91 -------------- .../Middleware/LogInboundEventTest.php | 6 +- .../Middleware/SetupBeforeEventTest.php | 4 +- .../Middleware/TearDownAfterEventTest.php | 4 +- .../SwallowInboundEventTest.php | 2 +- .../InboundEventBus/TestEventHandler.php | 2 +- .../InboundEventBus/TestInboundEvent.php | 2 +- .../UnitOfWork/UnitOfWorkManagerTest.php | 4 +- .../Loggable/ObjectDecoratorTest.php | 12 +- .../Loggable/ResultDecoratorTest.php | 10 +- tests/Unit/Bus/PsrPipeContainerTest.php | 61 ++++++++++ .../PsrLogExceptionReporterTest.php | 4 +- .../OutboundEventBus/ClosurePublisherTest.php | 2 +- .../Middleware/LogOutboundEventTest.php | 4 +- .../OutboundEventBus/TestOutboundEvent.php | 2 +- .../Infrastructure/Queue/ClosureQueueTest.php | 2 +- .../Queue/ComponentQueueTest.php | 2 +- .../Queue/EnqueuerContainerTest.php | 2 +- .../Infrastructure/Queue/EnqueuerTest.php | 2 +- .../Queue/Middleware/LogPushedToQueueTest.php | 4 +- .../Infrastructure/Queue/TestEnqueuer.php | 2 +- .../Testing/FakeExceptionReporterTest.php | 2 +- .../FakeOutboundEventPublisherTest.php | 4 +- tests/Unit/Testing/FakeQueueTest.php | 4 +- tests/Unit/Testing/FakeUnitOfWorkTest.php | 2 +- .../Toolkit/Pipeline/PipeContainerTest.php | 24 ---- .../Result/FailedResultExceptionTest.php | 4 - 190 files changed, 747 insertions(+), 1066 deletions(-) rename src/Application/Bus/{Exceptions => }/AbortOnFailureException.php (85%) delete mode 100644 src/Application/InboundEventBus/Middleware/FlushDeferredEvents.php delete mode 100644 src/Application/InboundEventBus/Middleware/HandleInUnitOfWork.php create mode 100644 src/Bus/BusException.php rename src/{Application => }/Bus/CommandDispatcher.php (88%) rename src/{Application => }/Bus/CommandHandler.php (77%) rename src/{Application => }/Bus/CommandHandlerContainer.php (76%) rename src/{Application/InboundEventBus => Bus}/EventHandler.php (70%) rename src/{Application/InboundEventBus => Bus}/EventHandlerContainer.php (77%) rename src/{Application/Messages => Bus}/HandlesMessages.php (84%) rename src/{Application/InboundEventBus => Bus}/InboundEventDispatcher.php (86%) rename src/{Toolkit => Bus}/Loggable/ObjectDecorator.php (92%) rename src/{Toolkit => Bus}/Loggable/ResultDecorator.php (92%) rename src/{Toolkit => Bus}/Loggable/Sensitive.php (86%) rename src/{Toolkit => Bus}/Loggable/SimpleContextFactory.php (73%) rename src/{Application/InboundEventBus => Bus}/Middleware/LogInboundEvent.php (76%) rename src/{Application => }/Bus/Middleware/LogMessageDispatch.php (69%) rename src/{Application => }/Bus/Middleware/SetupBeforeDispatch.php (72%) rename src/{Application/InboundEventBus => Bus}/Middleware/SetupBeforeEvent.php (79%) rename src/{Application => }/Bus/Middleware/TearDownAfterDispatch.php (65%) rename src/{Application/InboundEventBus => Bus}/Middleware/TearDownAfterEvent.php (73%) rename src/{Application => }/Bus/Middleware/ValidateCommand.php (78%) rename src/{Application => }/Bus/Middleware/ValidateQuery.php (78%) create mode 100644 src/Bus/PsrPipeContainer.php rename src/{Application => }/Bus/QueryDispatcher.php (88%) rename src/{Application => }/Bus/QueryHandler.php (77%) rename src/{Application => }/Bus/QueryHandlerContainer.php (76%) rename src/{Application/InboundEventBus => Bus}/SwallowInboundEvent.php (86%) rename src/{Application/Bus => Bus/Validation}/ValidationProcessor.php (86%) rename src/{Application/Bus => Bus/Validation}/Validator.php (86%) rename src/{Application => }/Bus/WithCommand.php (82%) rename src/{Application/InboundEventBus => Bus}/WithDefault.php (87%) rename src/{Application/InboundEventBus => Bus}/WithEvent.php (80%) rename src/{Application => }/Bus/WithQuery.php (82%) delete mode 100644 src/Contracts/Application/Bus/BusMiddleware.php rename src/Contracts/Application/Ports/{Driven => }/ExceptionReporter.php (84%) rename src/Contracts/Application/Ports/{Driven => }/OutboundEventPublisher.php (73%) rename src/Contracts/Application/Ports/{Driven => }/Queue.php (73%) rename src/Contracts/Application/Ports/{Driven => }/UnitOfWork.php (88%) rename src/Contracts/{Toolkit/Messages => Bus}/Command.php (81%) rename src/Contracts/{Application/Ports/Driving => Bus}/CommandDispatcher.php (77%) rename src/Contracts/{Application => }/Bus/CommandHandler.php (70%) rename src/Contracts/{Application => }/Bus/CommandHandlerContainer.php (78%) rename src/Contracts/{Application/Ports/Driving => Bus}/CommandQueuer.php (73%) rename src/Contracts/{Application/Messages => Bus}/DispatchThroughMiddleware.php (86%) rename src/Contracts/{Application/InboundEventBus => Bus}/EventHandler.php (63%) rename src/Contracts/{Application/InboundEventBus => Bus}/EventHandlerContainer.php (76%) rename src/Contracts/{Application/Ports/Driving => Bus}/InboundEventDispatcher.php (73%) rename src/Contracts/{Toolkit/Messages => Bus}/IntegrationEvent.php (88%) rename src/Contracts/{Toolkit => Bus}/Loggable/ContextFactory.php (81%) rename src/Contracts/{Toolkit => Bus}/Loggable/ContextProvider.php (86%) rename src/Contracts/{Toolkit => Bus}/Loggable/Contextual.php (86%) rename src/Contracts/{Toolkit/Messages => Bus}/Message.php (80%) create mode 100644 src/Contracts/Bus/Middleware/BusMiddleware.php rename src/Contracts/{Application/Bus => Bus/Middleware}/CommandMiddleware.php (81%) rename src/Contracts/{Application/InboundEventBus => Bus/Middleware}/InboundEventMiddleware.php (76%) rename src/Contracts/{Application/Bus => Bus/Middleware}/QueryMiddleware.php (81%) rename src/Contracts/{Toolkit/Messages => Bus}/Query.php (81%) rename src/Contracts/{Application/Ports/Driving => Bus}/QueryDispatcher.php (77%) rename src/Contracts/{Application => }/Bus/QueryHandler.php (70%) rename src/Contracts/{Application => }/Bus/QueryHandlerContainer.php (78%) rename src/Contracts/{Application/Bus => Bus/Validation}/Bail.php (80%) rename src/Contracts/{Application/Bus => Bus/Validation}/Validator.php (81%) rename tests/Integration/{Application => }/Bus/AddCommand.php (73%) rename tests/Integration/{Application => }/Bus/AddCommandHandler.php (89%) rename tests/Integration/{Application/InboundEventBus/DefaultHandler.php => Bus/DefaultEventHandler.php} (70%) rename tests/Integration/{Application => }/Bus/DivideQuery.php (73%) rename tests/Integration/{Application => }/Bus/DivideQueryHandler.php (89%) rename tests/Integration/{Application => }/Bus/FloorCommand.php (73%) rename tests/Integration/{Application => }/Bus/MathCommandBus.php (66%) rename tests/Integration/{Application => }/Bus/MathCommandBusTest.php (90%) rename tests/Integration/{Application/InboundEventBus => Bus}/MathEventBus.php (55%) rename tests/Integration/{Application/InboundEventBus => Bus}/MathEventBusTest.php (76%) rename tests/Integration/{Application => }/Bus/MathQueryBus.php (66%) rename tests/Integration/{Application => }/Bus/MathQueryBusTest.php (90%) rename tests/Integration/{Application => }/Bus/MultiplyCommand.php (73%) rename tests/Integration/{Application => }/Bus/MultiplyCommandHandler.php (91%) rename tests/Integration/{Application/InboundEventBus => Bus}/NumbersAdded.php (86%) rename tests/Integration/{Application/InboundEventBus => Bus}/NumbersAddedHandler.php (84%) rename tests/Integration/{Application/InboundEventBus => Bus}/NumbersDivided.php (86%) rename tests/Integration/{Application/InboundEventBus => Bus}/NumbersSubtracted.php (86%) rename tests/Integration/{Application/InboundEventBus => Bus}/NumbersSubtractedHandler.php (71%) rename tests/Integration/{Application => }/Bus/SubtractQuery.php (73%) rename tests/Integration/{Application => }/Bus/SubtractQueryHandler.php (89%) delete mode 100644 tests/Unit/Application/InboundEventBus/Middleware/FlushDeferredEventsTest.php delete mode 100644 tests/Unit/Application/InboundEventBus/Middleware/HandleInUnitOfWorkTest.php rename tests/Unit/{Toolkit => Bus}/Loggable/ObjectDecoratorTest.php (92%) rename tests/Unit/{Toolkit => Bus}/Loggable/ResultDecoratorTest.php (96%) create mode 100644 tests/Unit/Bus/PsrPipeContainerTest.php diff --git a/deptrac.yaml b/deptrac.yaml index 7ce16fe3..a5935b43 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -2,26 +2,24 @@ deptrac: paths: - ./src layers: - - name: Toolkit + - name: Application collectors: - type: classLike - value: CloudCreativity\\Modules\\Contracts\\Toolkit\\* + value: CloudCreativity\\Modules\\Contracts\\Application\\* - type: classLike - value: CloudCreativity\\Modules\\Toolkit\\* + value: CloudCreativity\\Modules\\Application\\* + - name: Bus + collectors: - type: classLike - value: Ramsey\\Uuid\\* + value: CloudCreativity\\Modules\\Contracts\\Bus\\* + - type: classLike + value: CloudCreativity\\Modules\\Bus\\* - name: Domain collectors: - type: classLike value: CloudCreativity\\Modules\\Contracts\\Domain\\* - type: classLike value: CloudCreativity\\Modules\\Domain\\* - - name: Application - collectors: - - type: classLike - value: CloudCreativity\\Modules\\Contracts\\Application\\* - - type: classLike - value: CloudCreativity\\Modules\\Application\\* - name: Infrastructure collectors: - type: classLike @@ -36,27 +34,33 @@ deptrac: collectors: - type: classLike value: Psr\\Log\\* - - name: Attributes + - name: Toolkit collectors: + - type: classLike + value: CloudCreativity\\Modules\\Contracts\\Toolkit\\* + - type: classLike + value: CloudCreativity\\Modules\\Toolkit\\* + - type: classLike + value: Ramsey\\Uuid\\* - type: classLike value: ^Deprecated$ ruleset: - Toolkit: - - Attributes - - PSR Container - Domain: - - Toolkit - - Attributes Application: - - Toolkit + - Bus - Domain - PSR Container - PSR Log - - Attributes - Infrastructure: - Toolkit - - Domain + Bus: + - PSR Container + - PSR Log + - Toolkit + Domain: + - Toolkit + Infrastructure: + - Bus - Application - PSR Container - PSR Log - - Attributes + - Toolkit + Toolkit: diff --git a/docs/guide/application/asynchronous-processing.md b/docs/guide/application/asynchronous-processing.md index 2a1e9f9d..45b58b51 100644 --- a/docs/guide/application/asynchronous-processing.md +++ b/docs/guide/application/asynchronous-processing.md @@ -197,8 +197,7 @@ And then our port adapter is as follows: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\Ports\Driven\Queue\InternalCommandBus; -use CloudCreativity\Modules\Application\Bus\CommandDispatcher; +use App\Modules\EventManagement\Application\Ports\Driven\Queue\InternalCommandBus;use CloudCreativity\Modules\Bus\CommandDispatcher; final class InternalCommandBusAdapter extends CommandDispatcher implements InternalCommandBus @@ -221,7 +220,7 @@ public commands. I.e.: ```php namespace App\Modules\EventManagement\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue as Port; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue as Port; // injected into the command queuer for queuing public commands interface Queue extends Port @@ -239,4 +238,4 @@ internal bus - to dispatch the command to when it is pulled from the queue. If you prefer, it is acceptable to define a single queue driven port. This simplifies the implementation by having a single queue that deals with both. However, you might find it gets complicated knowing whether to dispatch queued -commands to either the public or internal command bus. \ No newline at end of file +commands to either the public or internal command bus. diff --git a/docs/guide/application/commands.md b/docs/guide/application/commands.md index a413eaa7..dbbfc3d2 100644 --- a/docs/guide/application/commands.md +++ b/docs/guide/application/commands.md @@ -18,9 +18,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\UseCases\Commands\CancelAttendeeTicket; -use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; +use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; final readonly class CancelAttendeeTicketCommand implements Command { @@ -52,10 +50,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\UseCases\Commands\CancelAttendeeTicket; -use App\Modules\EventManagement\Application\Ports\Driven\Persistence\AttendeeRepository; -use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; -use CloudCreativity\Modules\Toolkit\Results\Result; +use App\Modules\EventManagement\Application\Ports\Driven\Persistence\AttendeeRepository;use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork;use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware;use CloudCreativity\Modules\Toolkit\Results\Result; final readonly class CancelAttendeeTicketHandler implements DispatchThroughMiddleware @@ -142,8 +137,7 @@ And then our implementation is as follows: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as Port; -use CloudCreativity\Modules\Application\Bus\CommandDispatcher; +use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as Port;use CloudCreativity\Modules\Bus\CommandDispatcher; final class CommandBus extends CommandDispatcher implements Port { @@ -167,16 +161,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\UsesCases\Commands\{ - CancelAttendeeTicket\CancelAttendeeTicketCommand, - CancelAttendeeTicket\CancelAttendeeTicketHandler, -}; -use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as CommandBusPort; -use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies; -use CloudCreativity\Modules\Application\Bus\CommandHandlerContainer; -use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; +use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies;use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as CommandBusPort;use App\Modules\EventManagement\Application\UsesCases\Commands\{CancelAttendeeTicket\CancelAttendeeTicketCommand,CancelAttendeeTicket\CancelAttendeeTicketHandler,};use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork;use CloudCreativity\Modules\Bus\CommandHandlerContainer;use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; final class CommandBusProvider { @@ -343,9 +328,7 @@ And then our implementation is as follows: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\Ports\Driving\CommandQueuer as Port; -use App\Modules\EventManagement\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Application\Bus\CommandQueuer as Queuer; +use App\Modules\EventManagement\Application\Ports\Driven\Queue;use App\Modules\EventManagement\Application\Ports\Driving\CommandQueuer as Port;use CloudCreativity\Modules\Application\Bus\CommandQueuer as Queuer; final class CommandQueuer extends Queuer implements Port { @@ -466,8 +449,7 @@ singleton instances of dependencies. For example: ```php -use App\Modules\EventManagement\Domain\Services; -use CloudCreativity\Modules\Application\Bus\Middleware\SetupBeforeDispatch; +use App\Modules\EventManagement\Domain\Services;use CloudCreativity\Modules\Bus\Middleware\SetupBeforeDispatch; $middleware->bind( SetupBeforeDispatch::class, @@ -497,7 +479,7 @@ If you only need to do teardown work, use the `TeardownAfterDispatch` middleware closure as its only constructor argument: ```php -use CloudCreativity\Modules\Application\Bus\Middleware\TeardownAfterDispatch; +use CloudCreativity\Modules\Bus\Middleware\TeardownAfterDispatch; $middleware->bind( TeardownAfterDispatch::class, @@ -578,7 +560,7 @@ Use our `LogMessageDispatch` middleware to log the dispatch of a command, and th [PSR Logger](https://php-fig.org/psr/psr-3/). ```php -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; $middleware->bind( LogMessageDispatch::class, @@ -620,9 +602,7 @@ However, there may be scenarios where a property should not be logged, e.g. beca In this scenario, use the `Sensitive` attribute on the property, and it will not be logged: ```php -use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Toolkit\Loggable\Sensitive; +use CloudCreativity\Modules\Bus\Loggable\Sensitive;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class CancelAttendeeTicketCommand implements Command { @@ -638,9 +618,7 @@ final readonly class CancelAttendeeTicketCommand implements Command If you need full control over the log context, implement the `ContextProvider` interface on your command message: ```php -use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class CancelAttendeeTicketCommand implements Command, @@ -670,10 +648,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\CommandMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class MyMiddleware implements CommandMiddleware { @@ -685,7 +660,7 @@ final class MyMiddleware implements CommandMiddleware * @return Result */ public function __invoke( - Command $command, + Command $command, Closure $next, ): Result { @@ -712,11 +687,7 @@ instead: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\BusMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; -use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Bus\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; class MyBusMiddleware implements BusMiddleware { @@ -728,7 +699,7 @@ class MyBusMiddleware implements BusMiddleware * @return Result */ public function __invoke( - Command|Query $message, + Command|Query $message, Closure $next, ): Result { diff --git a/docs/guide/application/domain-events.md b/docs/guide/application/domain-events.md index d847065f..b55aaa8e 100644 --- a/docs/guide/application/domain-events.md +++ b/docs/guide/application/domain-events.md @@ -54,7 +54,7 @@ namespace App\Modules\EventManagement\Application\Internal\DomainEvents; use App\Modules\EventManagement\Domain\Events\DomainEventDispatcher; use CloudCreativity\Modules\Application\DomainEventDispatching\UnitOfWorkAwareDispatcher; -final class DomainEventDispatcherAdapter extends UnitOfWorkAwareDispatcher implements +final class DomainEventDispatcherAdapter extends UnitOfWorkAwareDispatcher implements DomainEventDispatcher { } @@ -87,10 +87,10 @@ use CloudCreativity\Modules\Contracts\Application\UnitOfWork\UnitOfWorkManager; use CloudCreativity\Modules\Contracts\Domain\Events\DomainEvent; use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; -final readonly class DomainEventDispatcherProvider +final readonly class DomainEventDispatcherProvider { /** - * @var array, list> + * @var array, list> */ private array $subscriptions = [ AttendeeTicketWasCancelled::class => [ @@ -104,7 +104,7 @@ final readonly class DomainEventDispatcherProvider private ExternalDependencies $dependencies, ) { } - + public function getEventDispatcher(UnitOfWorkManager $unitOfWorkManager): DomainEventDispatcher { $dispatcher = new DomainEventDispatcherAdapter( @@ -112,7 +112,7 @@ final readonly class DomainEventDispatcherProvider listeners: $listeners = new ListenerContainer(), middleware: $middleware = new PipeContainer(), ); - + /** Bind listener factories */ $listeners->bind( Listeners\UpdateTicketSalesReport::class, @@ -120,19 +120,19 @@ final readonly class DomainEventDispatcherProvider $this->dependencies->getTicketSalesReportRepository(), ), ); - + $listeners->bind( Listeners\QueueTicketCancellationEmail::class, fn () => new Listeners\QueueTicketCancellationEmail( $this->dependencies->getMailer(), ), ); - + /** Subscribe listeners to events */ foreach ($this->subscriptions as $event => $listeners) { $dispatcher->listen($event, $listeners); } - + /** Bind middleware factories */ $middleware->bind( LogDomainEventDispatch::class, @@ -140,12 +140,12 @@ final readonly class DomainEventDispatcherProvider $this->dependencies->getLogger(), ), ); - + /** Attach middleware for all events */ $dispatcher->through([ LogDomainEventDispatch::class, ]); - + return $dispatcher; } } @@ -171,26 +171,17 @@ above: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\Ports\Driving\CommandBus; -use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies; -use App\Modules\EventManagement\Application\Internal\DomainEvents\DomainEventDispatcher; -use App\Modules\EventManagement\Application\Internal\DomainEvents\DomainEventDispatcherProvider; -use App\Modules\EventManagement\Domain\Services as DomainServices; -use CloudCreativity\Modules\Application\Bus\CommandHandlerContainer; -use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; -use CloudCreativity\Modules\Application\Bus\Middleware\SetupBeforeDispatch; -use CloudCreativity\Modules\Application\UnitOfWork\UnitOfWorkManager; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; +use App\Modules\EventManagement\Application\Internal\DomainEvents\DomainEventDispatcher;use App\Modules\EventManagement\Application\Internal\DomainEvents\DomainEventDispatcherProvider;use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies;use App\Modules\EventManagement\Application\Ports\Driving\CommandBus;use App\Modules\EventManagement\Domain\Services as DomainServices;use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork;use CloudCreativity\Modules\Application\UnitOfWork\UnitOfWorkManager;use CloudCreativity\Modules\Bus\CommandHandlerContainer;use CloudCreativity\Modules\Bus\Middleware\SetupBeforeDispatch;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; final class CommandBusProvider { /** - * @var UnitOfWorkManager|null + * @var UnitOfWorkManager|null */ private ?UnitOfWorkManager $unitOfWorkManager = null; - + /** - * @var DomainEventDispatcher|null + * @var DomainEventDispatcher|null */ private ?DomainEventDispatcher $eventDispatcher = null; @@ -208,7 +199,7 @@ final class CommandBusProvider ); // ...handler bindings. - + $middleware->bind( SetupBeforeDispatch::class, fn () => new SetupBeforeDispatch(function (): Closure { @@ -218,45 +209,45 @@ final class CommandBusProvider }; }), ); - + $middleware->bind( ExecuteInUnitOfWork::class, fn () => new ExecuteInUnitOfWork($this->unitOfWorkManager), ); - + $bus->through([ SetupBeforeDispatch::class, ]); return $bus; } - + /** * Set up command handling state. - * - * @return void + * + * @return void */ private function setUp(): void { $this->unitOfWorkManager = new UnitOfWorkManager( $this->dependencies->getUnitOfWork(), ); - + DomainServices::setEvents(function () { if ($this->eventDispatcher) { return $this->eventDispatcher; } - + return $this->eventDispatcher = $this->eventDispatcherProvider->getEventDispatcher( $this->unitOfWorkManager ); }); } - + /** * Tear down command handling state. - * - * @return void + * + * @return void */ private function tearDown(): void { @@ -312,7 +303,7 @@ namespace App\Modules\EventManagement\Application\Internal\DomainEvents; use CloudCreativity\Modules\Application\DomainEventDispatching\DeferredDispatcher; -final class DomainEventDispatcherAdapter extends DeferredDispatcher implements +final class DomainEventDispatcherAdapter extends DeferredDispatcher implements DeferredDomainEventDispatcher { } @@ -335,10 +326,10 @@ use CloudCreativity\Modules\Application\DomainEventDispatching\Middleware\LogDom use CloudCreativity\Modules\Contracts\Domain\Events\DomainEvent; use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; -final readonly class DomainEventDispatcherProvider +final readonly class DomainEventDispatcherProvider { /** - * @var array, list> + * @var array, list> */ private array $subscriptions = [ AttendeeTicketWasCancelled::class => [ @@ -352,14 +343,14 @@ final readonly class DomainEventDispatcherProvider private ExternalDependencies $dependencies, ) { } - + public function getEventDispatcher(): DeferredDomainEventDispatcher { $dispatcher = new DomainEventDispatcherAdapter( listeners: $listeners = new ListenerContainer(), middleware: $middleware = new PipeContainer(), ); - + /** Bind listener factories */ $listeners->bind( Listeners\UpdateTicketSalesReport::class, @@ -367,19 +358,19 @@ final readonly class DomainEventDispatcherProvider $this->dependencies->getTicketSalesReportRepository(), ), ); - + $listeners->bind( Listeners\QueueTicketCancellationEmail::class, fn () => new Listeners\QueueTicketCancellationEmail( $this->dependencies->getMailer(), ), ); - + /** Subscribe listeners to events */ foreach ($this->subscriptions as $event => $listeners) { $dispatcher->listen($event, $listeners); } - + /** Bind middleware factories */ $middleware->bind( LogDomainEventDispatch::class, @@ -387,12 +378,12 @@ final readonly class DomainEventDispatcherProvider $this->dependencies->getLogger(), ), ); - + /** Attach middleware for all events */ $dispatcher->through([ LogDomainEventDispatch::class, ]); - + return $dispatcher; } } @@ -409,20 +400,12 @@ Here's an example: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as CommandBusPort; -use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies; -use App\Modules\EventManagement\Application\Internal\DomainEvents\DomainEventDispatcher; -use App\Modules\EventManagement\Application\Internal\DomainEvents\DomainEventDispatcherProvider; -use App\Modules\EventManagement\Domain\Services as DomainServices; -use CloudCreativity\Modules\Application\Bus\CommandHandlerContainer; -use CloudCreativity\Modules\Application\Bus\Middleware\FlushDeferredEvents; -use CloudCreativity\Modules\Application\Bus\Middleware\SetupBeforeDispatch; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; +use App\Modules\EventManagement\Application\Internal\DomainEvents\DomainEventDispatcher;use App\Modules\EventManagement\Application\Internal\DomainEvents\DomainEventDispatcherProvider;use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies;use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as CommandBusPort;use App\Modules\EventManagement\Domain\Services as DomainServices;use CloudCreativity\Modules\Application\Bus\Middleware\FlushDeferredEvents;use CloudCreativity\Modules\Bus\CommandHandlerContainer;use CloudCreativity\Modules\Bus\Middleware\SetupBeforeDispatch;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; final class CommandBusProvider { /** - * @var DomainEventDispatcher|null + * @var DomainEventDispatcher|null */ private ?DomainEventDispatcher $eventDispatcher = null; @@ -445,7 +428,7 @@ final class CommandBusProvider FlushDeferredEvents::class, fn () => new ExecuteInUnitOfWork($this->eventDispatcher), ); - + $middleware->bind( SetupBeforeDispatch::class, fn () => new SetupBeforeDispatch(function (): Closure { @@ -455,31 +438,31 @@ final class CommandBusProvider }; }), ); - + $bus->through([ SetupBeforeDispatch::class, ]); return $bus; } - + /** * Set up command handling state. - * - * @return void + * + * @return void */ private function setUp(): void { $this->eventDispatcher = $this->eventDispatcherProvider ->getEventDispatcher(); - + DomainServices::setEvents(fn () => $this->eventDispatcher); } - + /** * Tear down command handling state. - * - * @return void + * + * @return void */ private function tearDown(): void { @@ -679,7 +662,7 @@ final class MyMiddleware implements DomainEventMiddleware * @return void */ public function __invoke( - DomainEvent $event, + DomainEvent $event, Closure $next, ): Result { @@ -693,4 +676,4 @@ final class MyMiddleware implements DomainEventMiddleware ``` It is worth noting that here we are wrapping the event being emitted by the domain layer, which is the point at which it -may be deferred by the dispatcher. \ No newline at end of file +may be deferred by the dispatcher. diff --git a/docs/guide/application/integration-events.md b/docs/guide/application/integration-events.md index 3cff6bb4..6cb3257d 100644 --- a/docs/guide/application/integration-events.md +++ b/docs/guide/application/integration-events.md @@ -36,12 +36,9 @@ For example: ```php namespace VendorName\EventManagement\Shared\IntegrationEvents\V1; -use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; -use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; -use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use CloudCreativity\Modules\Toolkit\Identifiers\Uuid;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; -final readonly class AttendeeTicketWasCancelled implements +final readonly class AttendeeTicketWasCancelled implements IntegrationEvent { public function __construct( @@ -97,7 +94,7 @@ This can be expressed via an interface. To illustrate the point, a JSON serializ ```php namespace VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface JsonSerializer { @@ -151,7 +148,7 @@ Your application layer should define the driven port: ```php namespace App\Modules\EventManagement\Application\Ports\Driven\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\OutboundEventPublisher; +use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; interface OutboundEventBus extends OutboundEventPublisher { @@ -356,11 +353,7 @@ side effects are triggered. ```php namespace App\Modules\EventManagement\Application\UseCases\InboundEvents; -use App\Modules\EventManagement\Domain\Events\DomainEventDispatcher; -use App\Modules\EventManagement\Domain\Events\SalesAtEventDidChange; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\HandleInUnitOfWork; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; -use VendorName\Ordering\Shared\IntegrationEvents\V1\OrderWasFulfilled; +use App\Modules\EventManagement\Domain\Events\DomainEventDispatcher;use App\Modules\EventManagement\Domain\Events\SalesAtEventDidChange;use CloudCreativity\Modules\Application\InboundEventBus\Middleware\HandleInUnitOfWork;use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware;use VendorName\Ordering\Shared\IntegrationEvents\V1\OrderWasFulfilled; final readonly class OrderWasFulfilledHandler implements DispatchThroughMiddleware @@ -403,7 +396,7 @@ We do this by defining an interface in our application's driving ports: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Application\Ports\Driving\InboundEventDispatcher; +use CloudCreativity\Modules\Contracts\Bus\InboundEventDispatcher; interface InboundEventBus extends InboundEventDispatcher { @@ -415,8 +408,7 @@ And then our implementation is as follows: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus as Port; -use CloudCreativity\Modules\Application\InboundEventBus\InboundEventDispatcher; +use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus as Port;use CloudCreativity\Modules\Bus\InboundEventDispatcher; final class InboundEventBus extends InboundEventDispatcher implements Port { @@ -440,15 +432,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\Bus\CommandBusProvider; -use App\Modules\EventManagement\Application\UsesCases\InboundEvents\OrderWasFulfilledHandler; -use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus as InboundEventBusPort; -use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies; -use CloudCreativity\Modules\Application\InboundEventBus\EventHandlerContainer; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\HandleInUnitOfWork; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\LogInboundEvent; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; -use VendorName\Ordering\Shared\IntegrationEvents\V1\OrderWasFulfilled; +use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies;use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus as InboundEventBusPort;use App\Modules\EventManagement\Application\UsesCases\InboundEvents\OrderWasFulfilledHandler;use CloudCreativity\Modules\Application\InboundEventBus\Middleware\HandleInUnitOfWork;use CloudCreativity\Modules\Bus\EventHandlerContainer;use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;use VendorName\Ordering\Shared\IntegrationEvents\V1\OrderWasFulfilled; final class InboundEventBusProvider { @@ -539,9 +523,7 @@ Here is an example controller from a Laravel application to demonstrate the patt ```php namespace App\Http\Controllers\Api\PubSub; -use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; -use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; +use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; class InboundEventController extends Controller { @@ -590,8 +572,7 @@ To do this, we configure a default handler on the handler container that is give the `SwallowInboundEvent` handler for this purpose: ```php -use CloudCreativity\Modules\Application\InboundEventBus\EventHandlerContainer; -use CloudCreativity\Modules\Application\InboundEventBus\SwallowInboundEvent; +use CloudCreativity\Modules\Bus\EventHandlerContainer;use CloudCreativity\Modules\Bus\SwallowInboundEvent; $bus = new InboundEventBus( handlers: $handlers = new EventHandlerContainer( @@ -605,9 +586,7 @@ the `SwallowInboundEvent` handler will do nothing with the event. You can also p the `SwallowInboundEvent` handler, so that it logs that the event was swallowed: ```php -use CloudCreativity\Modules\Application\InboundEventBus\EventHandlerContainer; -use CloudCreativity\Modules\Application\InboundEventBus\SwallowInboundEvent; -use Psr\Log\LogLevel; +use CloudCreativity\Modules\Bus\EventHandlerContainer;use CloudCreativity\Modules\Bus\SwallowInboundEvent;use Psr\Log\LogLevel; $bus = new InboundEventBus( handlers: $handlers = new EventHandlerContainer( @@ -648,7 +627,7 @@ example: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface Inbox { @@ -663,12 +642,12 @@ might look like this: ```php namespace App\Modules\EventManagement\Application\Ports\Driven\Inbox; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface InboxRepository { public function exists(IntegrationEvent $event): bool; - + public function store(IntegrationEvent $event): void; } ``` @@ -682,9 +661,7 @@ This means we can now update the previous controller example to use the inbox in ```php namespace App\Http\Controllers\Api\PubSub; -use App\Modules\EventManagement\Application\Ports\Driving\InboundEvents\Inbox; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; -use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; +use App\Modules\EventManagement\Application\Ports\Driving\InboundEvents\Inbox;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; class InboundEventController extends Controller { @@ -753,7 +730,7 @@ whether the notifying or publishing completes or throws an exception. For example: ```php -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\SetupBeforeEvent; +use CloudCreativity\Modules\Bus\Middleware\SetupBeforeEvent; $middleware->bind( SetupBeforeEvent::class, @@ -780,7 +757,7 @@ If you only need to do any teardown work, use the `TeardownAfterEvent` middlewar closure as its only constructor argument: ```php -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\TearDownAfterEvent; +use CloudCreativity\Modules\Bus\Middleware\TearDownAfterEvent; $middleware->bind( TearDownAfterEvent::class, @@ -863,7 +840,7 @@ Use our `LogInboundEvent` middleware to log when an integration event is consume a [PSR Logger](https://php-fig.org/psr/psr-3/). ```php -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\LogInboundEvent; +use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent; $middleware->bind( LogInboundEvent::class, @@ -888,9 +865,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\InboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use Closure;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; final class MyMiddleware implements InboundEventMiddleware { diff --git a/docs/guide/application/queries.md b/docs/guide/application/queries.md index 80d39b2c..6a5bbc11 100644 --- a/docs/guide/application/queries.md +++ b/docs/guide/application/queries.md @@ -18,8 +18,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\UseCases\Queries\GetAttendeeTickets; -use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class GetAttendeeTicketsQuery implements Query { @@ -54,7 +53,7 @@ final readonly class GetAttendeeTicketsHandler /** * Execute the query. - * + * * @param GetAttendeeTicketsQuery $query * @return Result> */ @@ -106,7 +105,7 @@ We do this by defining an interface in our application's driving ports: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Application\Ports\Driving\QueryDispatcher; +use CloudCreativity\Modules\Contracts\Bus\QueryDispatcher; interface QueryBus extends QueryDispatcher { @@ -118,8 +117,7 @@ And then our implementation is as follows: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\Ports\Driving\QueryBus as Port; -use CloudCreativity\Modules\Application\Bus\QueryDispatcher; +use App\Modules\EventManagement\Application\Ports\Driving\QueryBus as Port;use CloudCreativity\Modules\Bus\QueryDispatcher; final class QueryBus extends QueryDispatcher implements Port { @@ -143,15 +141,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\UseCases\Queries\{ - GetAttendeeTickets\GetAttendeeTicketsQuery, - GetAttendeeTickets\GetAttendeeTicketsHandler, -}; -use App\Modules\EventManagement\Application\Ports\Driving\QueryBus as QueryBusPort; -use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies; -use CloudCreativity\Modules\Application\Bus\QueryHandlerContainer; -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; +use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies;use App\Modules\EventManagement\Application\Ports\Driving\QueryBus as QueryBusPort;use App\Modules\EventManagement\Application\UseCases\Queries\{GetAttendeeTickets\GetAttendeeTicketsHandler,GetAttendeeTickets\GetAttendeeTicketsQuery,};use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch;use CloudCreativity\Modules\Bus\QueryHandlerContainer;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; final class QueryBusProvider { @@ -376,7 +366,7 @@ Use our `LogMessageDispatch` middleware to log the dispatch of a query, and the [PSR Logger](https://php-fig.org/psr/psr-3/). ```php -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; $middleware->bind( LogMessageDispatch::class, @@ -401,10 +391,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\QueryMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; -use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\QueryMiddleware;use CloudCreativity\Modules\Contracts\Bus\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class MyMiddleware implements QueryMiddleware { @@ -443,11 +430,7 @@ instead: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\BusMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; -use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Bus\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; class MyBusMiddleware implements BusMiddleware { @@ -459,7 +442,7 @@ class MyBusMiddleware implements BusMiddleware * @return Result */ public function __invoke( - Command|Query $message, + Command|Query $message, Closure $next, ): Result { diff --git a/docs/guide/application/units-of-work.md b/docs/guide/application/units-of-work.md index 2aa4c5b5..4f08346c 100644 --- a/docs/guide/application/units-of-work.md +++ b/docs/guide/application/units-of-work.md @@ -125,10 +125,7 @@ Our previous example can be updated to add a unit of work that wraps the command ```php namespace App\Modules\EventManagement\Application\UseCases\Commands\CancelAttendeeTicket; -use App\Modules\EventManagement\Application\Ports\Driven\Persistence\AttendeeRepository; -use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; -use CloudCreativity\Modules\Toolkit\Results\Result; +use App\Modules\EventManagement\Application\Ports\Driven\Persistence\AttendeeRepository;use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork;use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware;use CloudCreativity\Modules\Toolkit\Results\Result; final readonly class CancelAttendeeTicketHandler implements DispatchThroughMiddleware @@ -151,7 +148,7 @@ final readonly class CancelAttendeeTicketHandler implements return Result::ok(); } - + public function middleware(): array { return [ @@ -176,7 +173,7 @@ interface UnitOfWork * * @param \Closure $callback * @param int $attempts - * @return mixed + * @return mixed */ public function execute(Closure $callback, int $attempts = 1): mixed; } @@ -188,9 +185,7 @@ implementation for Laravel could look like this: ```php namespace App\Modules\Shared\Infrastructure; -use Closure; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\UnitOfWork; -use Illuminate\Database\ConnectionInterface; +use Closure;use CloudCreativity\Modules\Contracts\Application\Ports\UnitOfWork;use Illuminate\Database\ConnectionInterface; final readonly class IlluminateUnitOfWork implements UnitOfWork { @@ -201,7 +196,7 @@ final readonly class IlluminateUnitOfWork implements UnitOfWork public function execute(Closure $callback, int $attempts = 1): mixed { return $this->db->transaction( - static fn () => $callback(), + static fn () => $callback(), $attempts, ); } @@ -245,7 +240,7 @@ allows you to setup and tear down the unit of work manager for each operation. For example, we can use the setup before dispatch middleware on our command bus: ```php -use CloudCreativity\Modules\Application\Bus\Middleware\SetupBeforeDispatch; +use CloudCreativity\Modules\Bus\Middleware\SetupBeforeDispatch; $middleware->bind( SetupBeforeDispatch::class, @@ -405,10 +400,7 @@ Use the `ExecuteInUnitOfWork` middleware to wrap command handlers in a unit of w ```php namespace App\Modules\EventManagement\Application\UseCases\Commands\CancelAttendeeTicket; -use App\Modules\EventManagement\Application\Ports\Driven\Persistence\AttendeeRepository; -use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; -use CloudCreativity\Modules\Toolkit\Results\Result; +use App\Modules\EventManagement\Application\Ports\Driven\Persistence\AttendeeRepository;use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork;use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware;use CloudCreativity\Modules\Toolkit\Results\Result; final readonly class CancelAttendeeTicketHandler implements DispatchThroughMiddleware @@ -431,7 +423,7 @@ final readonly class CancelAttendeeTicketHandler implements return Result::ok(); } - + public function middleware(): array { return [ @@ -460,11 +452,7 @@ This can be achieved via the `HandleInUnitOfWork` middleware on the inbound even ```php namespace App\Modules\EventManagement\Application\UseCases\InboundEvents; -use App\Modules\EventManagement\Domain\Events\DomainEventDispatcher; -use App\Modules\EventManagement\Domain\Events\SalesAtEventDidChange; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\HandleInUnitOfWork; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; -use VendorName\Ordering\Shared\IntegrationEvents\V1\OrderWasFulfilled; +use App\Modules\EventManagement\Domain\Events\DomainEventDispatcher;use App\Modules\EventManagement\Domain\Events\SalesAtEventDidChange;use CloudCreativity\Modules\Application\InboundEventBus\Middleware\HandleInUnitOfWork;use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware;use VendorName\Ordering\Shared\IntegrationEvents\V1\OrderWasFulfilled; final readonly class OrderWasFulfilledHandler implements DispatchThroughMiddleware @@ -511,7 +499,7 @@ $unitOfWork = new FakeUnitOfWork(); // execute work that uses the unit of work $this->assertSame( - ['attempt:1', 'rollback:1', 'attempt:2', 'commit:2'], + ['attempt:1', 'rollback:1', 'attempt:2', 'commit:2'], $unitOfWork->sequence, ); -``` \ No newline at end of file +``` diff --git a/docs/guide/infrastructure/dependency-injection.md b/docs/guide/infrastructure/dependency-injection.md index 24919355..e173ee16 100644 --- a/docs/guide/infrastructure/dependency-injection.md +++ b/docs/guide/infrastructure/dependency-injection.md @@ -53,11 +53,11 @@ use Psr\Log\LoggerInterface; interface ExternalDependencies { public function getLogger(): LoggerInterface; - + public function getQueue(): Queue; - + public function getAttendeeRepository(): AttendeeRepository; - + // ...other methods } ``` @@ -68,16 +68,7 @@ creating a command bus: ```php namespace App\Modules\EventManagement\Application\Bus; -use App\Modules\EventManagement\Application\UsesCases\Commands\{ - CancelAttendeeTicket\CancelAttendeeTicketCommand, - CancelAttendeeTicket\CancelAttendeeTicketHandler, -}; -use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as CommandBusPort; -use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies; -use CloudCreativity\Modules\Application\Bus\CommandHandlerContainer; -use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; +use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies;use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as CommandBusPort;use App\Modules\EventManagement\Application\UsesCases\Commands\{CancelAttendeeTicket\CancelAttendeeTicketCommand,CancelAttendeeTicket\CancelAttendeeTicketHandler,};use CloudCreativity\Modules\Bus\CommandHandlerContainer;use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; final class CommandBusProvider { @@ -137,9 +128,9 @@ use Psr\Log\LoggerInterface; interface ExternalDependencies { public function getLogger(): LoggerInterface; - + public function getQueue(): Queue; - + public function getRepositories(): RepositoryProvider; } ``` @@ -152,9 +143,9 @@ namespace App\Modules\EventManagement\Application\Ports\Driven\Persistence; interface RepositoryProvider { public function getAttendees(): AttendeeRepository; - + public function getSalesReports(): SalesReportRepository; - + // ...other repositories } ``` @@ -174,4 +165,4 @@ lifetime of that instance - allowing it to set it up and tear it down as needed. This also helps make the external dependencies port _predictable_. If some methods returned singletons and others did not, how does the application layer know what it has been given - a singleton, or a new instance? Also, the application layer would then not be able to tear down any singletons when it knew that they were no longer required, e.g. after -dispatching a command. \ No newline at end of file +dispatching a command. diff --git a/docs/guide/infrastructure/exception-reporting.md b/docs/guide/infrastructure/exception-reporting.md index 0a0f364c..982ade9f 100644 --- a/docs/guide/infrastructure/exception-reporting.md +++ b/docs/guide/infrastructure/exception-reporting.md @@ -93,11 +93,9 @@ implementation looks like this: ```php namespace App\Modules\Shared\Infrastructure\Exceptions; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\ExceptionReporter; -use Illuminate\Contracts\Debug\ExceptionHandler; -use Throwable; +use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter;use Illuminate\Contracts\Debug\ExceptionHandler;use Throwable; -final readonly class ExceptionReporterAdapter implements +final readonly class ExceptionReporterAdapter implements ExceptionReporter { public function __construct(private ExceptionHandler $handler) @@ -136,4 +134,4 @@ $expected = new \LogicException('Boom!'); // do work $this->assertSame($expected, $reporter->sole()); -``` \ No newline at end of file +``` diff --git a/docs/guide/infrastructure/outbox.md b/docs/guide/infrastructure/outbox.md index bf865ce8..d6d9ac49 100644 --- a/docs/guide/infrastructure/outbox.md +++ b/docs/guide/infrastructure/outbox.md @@ -62,7 +62,7 @@ Our recommended approach is to first place these events into an outbox. This mea ```php namespace App\Modules\EventManagement\Application\Ports\Driven\OutboundEvents; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface Outbox { @@ -70,7 +70,7 @@ interface Outbox * Push the event into the outbox. * * @param IntegrationEvent $event - * @return void + * @return void */ public function push(IntegrationEvent $event): void; } @@ -126,7 +126,7 @@ port `Queue` - as suggested by the [Queues chapter](./queues) - call it `Outbox` ```php namespace App\Modules\EventManagement\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue; interface Outbox extends Queue { @@ -152,4 +152,4 @@ What about microservices in your own architecture? Prefer loose coupling over di integration events published via an outbox. Alternatively, if you want to directly call the microservice, ask yourself whether this definitely needs to be -immediate? If not immediate, push the work to a queued command and leverage the queuing outbox approach described above. \ No newline at end of file +immediate? If not immediate, push the work to a queued command and leverage the queuing outbox approach described above. diff --git a/docs/guide/infrastructure/publishing-events.md b/docs/guide/infrastructure/publishing-events.md index 7be9d734..363f7469 100644 --- a/docs/guide/infrastructure/publishing-events.md +++ b/docs/guide/infrastructure/publishing-events.md @@ -16,7 +16,7 @@ The following is an example port: ```php namespace App\Modules\EventManagement\Application\Ports\Driven\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\OutboundEventPublisher; +use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; interface OutboundEventBus extends OutboundEventPublisher { @@ -61,14 +61,7 @@ specific closures to specific events, and add middleware to the publisher. Here' ```php namespace App\Modules\EventManagement\Infrastructure\OutboundEventBus; -use App\Modules\EventManagement\Application\Ports\Driven\OutboundEventBus\OutboundEventBus; -use App\Modules\EventManagement\Infrastructure\GooglePubSub\EventSerializer; -use App\Modules\EventManagement\Infrastructure\GooglePubSub\SecureTopicFactory; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; -use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; -use Psr\Log\LoggerInterface; -use VendorName\EventManagement\Shared\IntegrationEvents\V1\AttendeeTicketWasCancelled; +use App\Modules\EventManagement\Application\Ports\Driven\OutboundEventBus\OutboundEventBus;use App\Modules\EventManagement\Infrastructure\GooglePubSub\EventSerializer;use App\Modules\EventManagement\Infrastructure\GooglePubSub\SecureTopicFactory;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;use Psr\Log\LoggerInterface;use VendorName\EventManagement\Shared\IntegrationEvents\V1\AttendeeTicketWasCancelled; final readonly class OutboundEventBusAdapterProvider { @@ -90,7 +83,7 @@ final readonly class OutboundEventBusAdapterProvider }, middleware: $middleware = new PipeContainer(), ); - + /** Bind handlers for specific events (if needed) */ $publisher->bind( AttendeeTicketWasCancelled::class, @@ -226,7 +219,7 @@ final readonly class OutboundEventBusAdapterProvider ), middleware: $middleware = new PipeContainer(), ); - + /** Bind handlers for specific events (if needed) */ $handlers->bind( AttendeeTicketWasCancelled::class, @@ -262,7 +255,7 @@ implement the following interface that was extended by the driven port: ```php namespace CloudCreativity\Modules\Application\Ports\Driven\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface EventPublisher { @@ -320,9 +313,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Adapters\Middleware; -use Closure; -use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use Closure;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware; final class MyMiddleware implements OutboundEventMiddleware { @@ -376,4 +367,4 @@ If you expect exactly one integration event to be published, use the `sole()` he $expected = new SomeIntegrationEvent(); $this->assertEquals($expected, $publisher->sole()); -``` \ No newline at end of file +``` diff --git a/docs/guide/infrastructure/queues.md b/docs/guide/infrastructure/queues.md index 4624fc52..1f1580b4 100644 --- a/docs/guide/infrastructure/queues.md +++ b/docs/guide/infrastructure/queues.md @@ -2,7 +2,7 @@ As described in the [Asynchronous Processing chapter](../application/asynchronous-processing), your application layer can allow commands to be queued via a command queuer driving port. Additionally, it may also choose to implement some -internal processes as internal commands that are executed asynchronously. +internal processes as internal commands that are executed asynchronously. To do either (or both!), you need to define a queue driven port. The adapter implementation then handles pushing commands onto a queue, and dispatching the command when it is pulled from the queue. @@ -19,14 +19,14 @@ We do this by defining an interface in our application's driven ports: ```php namespace App\Modules\EventManagement\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue as Port; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue as Port; interface Queue extends Port { } ``` -If you have a command queuer driving port, you will need to inject your queue adapter into the command queuer. See the [command queuer documentation](../application/commands.md#command-queuer) for examples. +If you have a command queuer driving port, you will need to inject your queue adapter into the command queuer. See the [command queuer documentation](../application/commands.md#command-queuer) for examples. This allows the presentation and delivery layer to asynchronously dispatch commands. When pulling commands from the queue, your queue adapter will need to dispatch the command to the command bus. @@ -46,7 +46,7 @@ In this scenario, define another driven port: ```php namespace App\Modules\EventManagement\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue as Port; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue as Port; interface InternalQueue extends Port { @@ -79,10 +79,7 @@ Then you can create the adapter by providing it with the default closure for que ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use App\Modules\EventManagement\Application\Ports\Driven\Queue\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; +use App\Modules\EventManagement\Application\Ports\Driven\Queue\Queue;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; final class QueueAdapterProvider { @@ -95,7 +92,7 @@ final class QueueAdapterProvider { $adapter = new QueueAdapter( fn: function (Command $command): void { - DispatchCommandJob::dispatch($command); + DispatchCommandJob::dispatch($command); }, middleware: $middleware = new PipeContainer(), ); @@ -104,9 +101,9 @@ final class QueueAdapterProvider LogPushedToQueue::class, fn () => new LogPushedToQueue($this->logger), ); - + $queue->through([LogPushedToQueue::class]); - + return $adapter; } } @@ -121,7 +118,7 @@ This default closure will be used for all commands, unless you register closures ```php $queue = new QueueAdapter( fn: function (Command $command): void { - DispatchCommandJob::dispatch($command); + DispatchCommandJob::dispatch($command); }, ); @@ -129,7 +126,7 @@ $queue->bind( RecalculateSalesAtEventCommand::class, function (RecalculateSalesAtEventCommand $command): void { DispatchCommandJob::dispatch($command) - ->onQueue('reporting'); + ->onQueue('reporting'); }, ); ``` @@ -186,9 +183,9 @@ final class QueueAdapterProvider LogPushedToQueue::class, fn () => new LogPushedToQueue($this->logger), ); - + $queue->through([LogPushedToQueue::class]); - + return $adapter; } } @@ -220,7 +217,7 @@ example: ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; final class DefaultEnqueuer { @@ -247,7 +244,7 @@ implements the port interface that is extended in your application layer: ```php namespace CloudCreativity\Modules\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; interface Queue { @@ -282,29 +279,23 @@ For example, a default Laravel job for queuing and dispatching commands would be ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use App\Modules\EventManagement\Application\Ports\Driving\CommandBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Toolkit\Result\FailedResultException; -use Illuminate\Bus\Queueable; -use Illuminate\Contracts\Queue\ShouldQueue; -use Illuminate\Foundation\Bus\Dispatchable; -use Illuminate\Queue\InteractsWithQueue; +use App\Modules\EventManagement\Application\Ports\Driving\CommandBus;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Toolkit\Result\FailedResultException;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue; class DispatchCommandJob implements ShouldQueue { use Dispatchable; use InteractsWithQueue; use Queueable; - + public function __construct( public readonly Command $command ) { } - + public function handle(CommandBus $bus): void { $result = $bus->dispatch($this->command); - + if ($result->didFail()) { throw new FailedResultException($result); } @@ -340,27 +331,27 @@ class QueueRecalculateSalesAtEventJob implements ShouldQueue use Dispatchable; use InteractsWithQueue; use Queueable; - + public function __construct( public readonly RecalculateSalesAtEventCommand $command ) { } - + public function handle(CommandBus $bus): void { $result = $bus->dispatch($this->command); $errors = $result->errors(); - + if ($errors->contains(ErrorCodeEnum::TemporaryFailure)) { $this->release(now()->addSeconds(30)); return; } - + if ($result->didFail()) { throw new FailedResultException($result); } } - + public function middleware(): array { return [ @@ -390,7 +381,7 @@ example, to create the queue that is injected into our command bus: // default command queuing $queue = new QueueAdapter( fn: function (Command $command): void { - DispatchCommandJob::dispatch($command); + DispatchCommandJob::dispatch($command); }, ); @@ -463,9 +454,7 @@ following signature: ```php namespace App\Modules\Shared\Infrastructure\Queue\Middleware; -use Closure; -use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware; final class MyQueueMiddleware implements QueueMiddleware { @@ -477,7 +466,7 @@ final class MyQueueMiddleware implements QueueMiddleware * @return void */ public function __invoke( - Command $command, + Command $command, Closure $next, ): void { @@ -519,4 +508,4 @@ If you expect exactly one command to be queued, use the `sole()` helper: $expected = new SomeCommand(); $this->assertEquals($expected, $queue->sole()); -``` \ No newline at end of file +``` diff --git a/src/Application/Bus/Exceptions/AbortOnFailureException.php b/src/Application/Bus/AbortOnFailureException.php similarity index 85% rename from src/Application/Bus/Exceptions/AbortOnFailureException.php rename to src/Application/Bus/AbortOnFailureException.php index 78f0bdcd..9e8d89db 100644 --- a/src/Application/Bus/Exceptions/AbortOnFailureException.php +++ b/src/Application/Bus/AbortOnFailureException.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus\Exceptions; +namespace CloudCreativity\Modules\Application\Bus; use CloudCreativity\Modules\Toolkit\Result\FailedResultException; diff --git a/src/Application/Bus/CommandQueuer.php b/src/Application/Bus/CommandQueuer.php index ad439118..2fed242c 100644 --- a/src/Application/Bus/CommandQueuer.php +++ b/src/Application/Bus/CommandQueuer.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Application\Bus; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Application\Ports\Driving\CommandQueuer as ICommandQueuer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\CommandQueuer as ICommandQueuer; class CommandQueuer implements ICommandQueuer { diff --git a/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php b/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php index eed9ee94..acaf17cf 100644 --- a/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php +++ b/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php @@ -13,13 +13,13 @@ namespace CloudCreativity\Modules\Application\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Application\Bus\Exceptions\AbortOnFailureException; -use CloudCreativity\Modules\Contracts\Application\Bus\CommandMiddleware; +use CloudCreativity\Modules\Application\Bus\AbortOnFailureException; use CloudCreativity\Modules\Contracts\Application\UnitOfWork\UnitOfWorkManager; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; -final readonly class ExecuteInUnitOfWork implements CommandMiddleware +final readonly class ExecuteInUnitOfWork implements BusMiddleware { /** * @param int<1, max> $attempts @@ -30,13 +30,16 @@ public function __construct( ) { } - public function __invoke(Command $command, Closure $next): Result + public function __invoke(Message $message, Closure $next): ?Result { try { return $this->unitOfWorkManager->execute( - static function () use ($command, $next): Result { - $res = $next($command); - return $res->didSucceed() ? $res : throw new AbortOnFailureException($res); + static function () use ($message, $next): ?Result { + $res = $next($message); + if ($res?->didFail()) { + throw new AbortOnFailureException($res); + } + return $res; }, $this->attempts, ); diff --git a/src/Application/Bus/Middleware/FlushDeferredEvents.php b/src/Application/Bus/Middleware/FlushDeferredEvents.php index f63ae9b9..a32ecd62 100644 --- a/src/Application/Bus/Middleware/FlushDeferredEvents.php +++ b/src/Application/Bus/Middleware/FlushDeferredEvents.php @@ -13,31 +13,31 @@ namespace CloudCreativity\Modules\Application\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\CommandMiddleware; use CloudCreativity\Modules\Contracts\Application\DomainEventDispatching\DeferredDispatcher; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use Throwable; -final readonly class FlushDeferredEvents implements CommandMiddleware +final readonly class FlushDeferredEvents implements BusMiddleware { public function __construct(private DeferredDispatcher $dispatcher) { } - public function __invoke(Command $command, Closure $next): Result + public function __invoke(Message $message, Closure $next): ?Result { try { - $result = $next($command); + $result = $next($message); } catch (Throwable $ex) { $this->dispatcher->forget(); throw $ex; } - if ($result->didSucceed()) { - $this->dispatcher->flush(); - } else { + if ($result?->didFail()) { $this->dispatcher->forget(); + } else { + $this->dispatcher->flush(); } return $result; diff --git a/src/Application/InboundEventBus/Middleware/FlushDeferredEvents.php b/src/Application/InboundEventBus/Middleware/FlushDeferredEvents.php deleted file mode 100644 index f2bb526a..00000000 --- a/src/Application/InboundEventBus/Middleware/FlushDeferredEvents.php +++ /dev/null @@ -1,38 +0,0 @@ -dispatcher->forget(); - throw $ex; - } - - $this->dispatcher->flush(); - } -} diff --git a/src/Application/InboundEventBus/Middleware/HandleInUnitOfWork.php b/src/Application/InboundEventBus/Middleware/HandleInUnitOfWork.php deleted file mode 100644 index ecd455c8..00000000 --- a/src/Application/InboundEventBus/Middleware/HandleInUnitOfWork.php +++ /dev/null @@ -1,40 +0,0 @@ - $attempts - */ - public function __construct( - private UnitOfWorkManager $unitOfWorkManager, - private int $attempts = 1, - ) { - } - - public function __invoke(IntegrationEvent $event, Closure $next): void - { - $this->unitOfWorkManager->execute( - static function () use ($event, $next): void { - $next($event); - }, - $this->attempts, - ); - } -} diff --git a/src/Application/UnitOfWork/UnitOfWorkManager.php b/src/Application/UnitOfWork/UnitOfWorkManager.php index 0e02207d..69e6a784 100644 --- a/src/Application/UnitOfWork/UnitOfWorkManager.php +++ b/src/Application/UnitOfWork/UnitOfWorkManager.php @@ -14,8 +14,8 @@ use Closure; use CloudCreativity\Modules\Application\ApplicationException; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\ExceptionReporter; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\UnitOfWork; +use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter; +use CloudCreativity\Modules\Contracts\Application\Ports\UnitOfWork; use CloudCreativity\Modules\Contracts\Application\UnitOfWork\UnitOfWorkManager as IUnitOfWorkManager; use Throwable; diff --git a/src/Bus/BusException.php b/src/Bus/BusException.php new file mode 100644 index 00000000..b991db6d --- /dev/null +++ b/src/Bus/BusException.php @@ -0,0 +1,19 @@ +middleware = $middleware === null && $handlers instanceof ContainerInterface - ? new PipeContainer($handlers) + ? new PsrPipeContainer($handlers) : $middleware; $this->autowire(); diff --git a/src/Application/Bus/CommandHandler.php b/src/Bus/CommandHandler.php similarity index 77% rename from src/Application/Bus/CommandHandler.php rename to src/Bus/CommandHandler.php index a3304f8d..6f2f6e5c 100644 --- a/src/Application/Bus/CommandHandler.php +++ b/src/Bus/CommandHandler.php @@ -10,11 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Application\Messages\HandlesMessages; -use CloudCreativity\Modules\Contracts\Application\Bus\CommandHandler as ICommandHandler; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\CommandHandler as ICommandHandler; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class CommandHandler implements ICommandHandler diff --git a/src/Application/Bus/CommandHandlerContainer.php b/src/Bus/CommandHandlerContainer.php similarity index 76% rename from src/Application/Bus/CommandHandlerContainer.php rename to src/Bus/CommandHandlerContainer.php index 5092eaa7..eff9a3fa 100644 --- a/src/Application/Bus/CommandHandlerContainer.php +++ b/src/Bus/CommandHandlerContainer.php @@ -10,12 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus; use Closure; -use CloudCreativity\Modules\Application\ApplicationException; -use CloudCreativity\Modules\Contracts\Application\Bus\CommandHandlerContainer as ICommandHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\CommandHandlerContainer as ICommandHandlerContainer; use Psr\Container\ContainerInterface; final class CommandHandlerContainer implements ICommandHandlerContainer @@ -38,7 +37,7 @@ public function __construct(private readonly ?ContainerInterface $container = nu public function bind(string $commandClass, Closure|string $binding): void { if (is_string($binding) && $this->container === null) { - throw new ApplicationException('Cannot use a string command handler binding without a PSR container.'); + throw new BusException('Cannot use a string command handler binding without a PSR container.'); } $this->bindings[$commandClass] = $binding; @@ -60,6 +59,6 @@ public function get(string $commandClass): CommandHandler return new CommandHandler($instance); } - throw new ApplicationException('No command handler bound for command class: ' . $commandClass); + throw new BusException('No command handler bound for command class: ' . $commandClass); } } diff --git a/src/Application/InboundEventBus/EventHandler.php b/src/Bus/EventHandler.php similarity index 70% rename from src/Application/InboundEventBus/EventHandler.php rename to src/Bus/EventHandler.php index 631599eb..9ec57363 100644 --- a/src/Application/InboundEventBus/EventHandler.php +++ b/src/Bus/EventHandler.php @@ -10,11 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus; +namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Application\Messages\HandlesMessages; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\EventHandler as IEventHandler; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\EventHandler as IEventHandler; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; final readonly class EventHandler implements IEventHandler { diff --git a/src/Application/InboundEventBus/EventHandlerContainer.php b/src/Bus/EventHandlerContainer.php similarity index 77% rename from src/Application/InboundEventBus/EventHandlerContainer.php rename to src/Bus/EventHandlerContainer.php index 1e42276e..94a47713 100644 --- a/src/Application/InboundEventBus/EventHandlerContainer.php +++ b/src/Bus/EventHandlerContainer.php @@ -10,12 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus; +namespace CloudCreativity\Modules\Bus; use Closure; -use CloudCreativity\Modules\Application\ApplicationException; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\EventHandlerContainer as IEventHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer as IEventHandlerContainer; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use Psr\Container\ContainerInterface; final class EventHandlerContainer implements IEventHandlerContainer @@ -43,7 +42,7 @@ public function __construct( public function bind(string $eventName, Closure|string $binding): void { if (is_string($binding) && $this->container === null) { - throw new ApplicationException('Cannot use a string event handler binding without a PSR container.'); + throw new BusException('Cannot use a string event handler binding without a PSR container.'); } $this->bindings[$eventName] = $binding; @@ -61,7 +60,7 @@ public function withDefault(Closure|string $binding): void return; } - throw new ApplicationException('Default event handler binding is already set.'); + throw new BusException('Default event handler binding is already set.'); } public function get(string $eventName): EventHandler @@ -80,6 +79,6 @@ public function get(string $eventName): EventHandler return new EventHandler($instance); } - throw new ApplicationException('No handler bound for integration event: ' . $eventName); + throw new BusException('No handler bound for integration event: ' . $eventName); } } diff --git a/src/Application/Messages/HandlesMessages.php b/src/Bus/HandlesMessages.php similarity index 84% rename from src/Application/Messages/HandlesMessages.php rename to src/Bus/HandlesMessages.php index 67b3b728..bb12f7c5 100644 --- a/src/Application/Messages/HandlesMessages.php +++ b/src/Bus/HandlesMessages.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Messages; +namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; +use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware; use CloudCreativity\Modules\Toolkit\Pipeline\Through; use ReflectionClass; diff --git a/src/Application/InboundEventBus/InboundEventDispatcher.php b/src/Bus/InboundEventDispatcher.php similarity index 86% rename from src/Application/InboundEventBus/InboundEventDispatcher.php rename to src/Bus/InboundEventDispatcher.php index 6ea4a825..892a2f2b 100644 --- a/src/Application/InboundEventBus/InboundEventDispatcher.php +++ b/src/Bus/InboundEventDispatcher.php @@ -10,14 +10,13 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus; +namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\EventHandlerContainer as IEventHandlerContainer; -use CloudCreativity\Modules\Contracts\Application\Ports\Driving\InboundEventDispatcher as IInboundEventDispatcher; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer as IEventHandlerContainer; +use CloudCreativity\Modules\Contracts\Bus\InboundEventDispatcher as IInboundEventDispatcher; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; use CloudCreativity\Modules\Toolkit\Pipeline\Through; use Psr\Container\ContainerInterface; @@ -42,7 +41,7 @@ public function __construct( $handlers; $this->middleware = $middleware === null && $handlers instanceof ContainerInterface ? - new PipeContainer(container: $handlers) : + new PsrPipeContainer(container: $handlers) : $middleware; $this->autowire(); diff --git a/src/Toolkit/Loggable/ObjectDecorator.php b/src/Bus/Loggable/ObjectDecorator.php similarity index 92% rename from src/Toolkit/Loggable/ObjectDecorator.php rename to src/Bus/Loggable/ObjectDecorator.php index a31d62f1..4c6e897d 100644 --- a/src/Toolkit/Loggable/ObjectDecorator.php +++ b/src/Bus/Loggable/ObjectDecorator.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Toolkit\Loggable; +namespace CloudCreativity\Modules\Bus\Loggable; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\Contextual; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; +use CloudCreativity\Modules\Contracts\Bus\Loggable\Contextual; use DateTimeInterface; use DateTimeZone; use Generator; diff --git a/src/Toolkit/Loggable/ResultDecorator.php b/src/Bus/Loggable/ResultDecorator.php similarity index 92% rename from src/Toolkit/Loggable/ResultDecorator.php rename to src/Bus/Loggable/ResultDecorator.php index 17b1351f..656cf837 100644 --- a/src/Toolkit/Loggable/ResultDecorator.php +++ b/src/Bus/Loggable/ResultDecorator.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Toolkit\Loggable; +namespace CloudCreativity\Modules\Bus\Loggable; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\Contextual; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; +use CloudCreativity\Modules\Contracts\Bus\Loggable\Contextual; use CloudCreativity\Modules\Contracts\Toolkit\Result\Error; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; diff --git a/src/Toolkit/Loggable/Sensitive.php b/src/Bus/Loggable/Sensitive.php similarity index 86% rename from src/Toolkit/Loggable/Sensitive.php rename to src/Bus/Loggable/Sensitive.php index 01c71ecc..28aae522 100644 --- a/src/Toolkit/Loggable/Sensitive.php +++ b/src/Bus/Loggable/Sensitive.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Toolkit\Loggable; +namespace CloudCreativity\Modules\Bus\Loggable; use Attribute; diff --git a/src/Toolkit/Loggable/SimpleContextFactory.php b/src/Bus/Loggable/SimpleContextFactory.php similarity index 73% rename from src/Toolkit/Loggable/SimpleContextFactory.php rename to src/Bus/Loggable/SimpleContextFactory.php index e0fd9433..144997f6 100644 --- a/src/Toolkit/Loggable/SimpleContextFactory.php +++ b/src/Bus/Loggable/SimpleContextFactory.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Toolkit\Loggable; +namespace CloudCreativity\Modules\Bus\Loggable; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Message; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; +use CloudCreativity\Modules\Contracts\Bus\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class SimpleContextFactory implements ContextFactory diff --git a/src/Application/InboundEventBus/Middleware/LogInboundEvent.php b/src/Bus/Middleware/LogInboundEvent.php similarity index 76% rename from src/Application/InboundEventBus/Middleware/LogInboundEvent.php rename to src/Bus/Middleware/LogInboundEvent.php index fbf7b210..0b4528b6 100644 --- a/src/Application/InboundEventBus/Middleware/LogInboundEvent.php +++ b/src/Bus/Middleware/LogInboundEvent.php @@ -10,13 +10,13 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus\Middleware; +namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\InboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; -use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory; +use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; +use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Application/Bus/Middleware/LogMessageDispatch.php b/src/Bus/Middleware/LogMessageDispatch.php similarity index 69% rename from src/Application/Bus/Middleware/LogMessageDispatch.php rename to src/Bus/Middleware/LogMessageDispatch.php index 75c34996..0815fe92 100644 --- a/src/Application/Bus/Middleware/LogMessageDispatch.php +++ b/src/Bus/Middleware/LogMessageDispatch.php @@ -10,15 +10,15 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus\Middleware; +namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\BusMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; +use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; -use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; @@ -33,7 +33,7 @@ public function __construct( ) { } - public function __invoke(Command|Query $message, Closure $next): Result + public function __invoke(Message $message, Closure $next): ?Result { $name = ModuleBasename::tryFrom($message)?->toString() ?? $message::class; $key = ($message instanceof Command) ? 'command' : 'query'; @@ -44,13 +44,12 @@ public function __invoke(Command|Query $message, Closure $next): Result [$key => $this->context->make($message)], ); - /** @var Result $result */ $result = $next($message); $this->logger->log( $this->dispatchedLevel, "Bus dispatched {$name}.", - ['result' => $this->context->make($result)], + $result ? ['result' => $this->context->make($result)] : [], ); return $result; diff --git a/src/Application/Bus/Middleware/SetupBeforeDispatch.php b/src/Bus/Middleware/SetupBeforeDispatch.php similarity index 72% rename from src/Application/Bus/Middleware/SetupBeforeDispatch.php rename to src/Bus/Middleware/SetupBeforeDispatch.php index fd45c2fd..199c4165 100644 --- a/src/Application/Bus/Middleware/SetupBeforeDispatch.php +++ b/src/Bus/Middleware/SetupBeforeDispatch.php @@ -10,12 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus\Middleware; +namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\BusMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class SetupBeforeDispatch implements BusMiddleware @@ -27,7 +26,7 @@ public function __construct(private Closure $callback) { } - public function __invoke(Command|Query $message, Closure $next): Result + public function __invoke(Message $message, Closure $next): ?Result { $tearDown = ($this->callback)(); diff --git a/src/Application/InboundEventBus/Middleware/SetupBeforeEvent.php b/src/Bus/Middleware/SetupBeforeEvent.php similarity index 79% rename from src/Application/InboundEventBus/Middleware/SetupBeforeEvent.php rename to src/Bus/Middleware/SetupBeforeEvent.php index 98ffad83..7bec6ebc 100644 --- a/src/Application/InboundEventBus/Middleware/SetupBeforeEvent.php +++ b/src/Bus/Middleware/SetupBeforeEvent.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus\Middleware; +namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\InboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; final readonly class SetupBeforeEvent implements InboundEventMiddleware { diff --git a/src/Application/Bus/Middleware/TearDownAfterDispatch.php b/src/Bus/Middleware/TearDownAfterDispatch.php similarity index 65% rename from src/Application/Bus/Middleware/TearDownAfterDispatch.php rename to src/Bus/Middleware/TearDownAfterDispatch.php index 21322773..3a4f271a 100644 --- a/src/Application/Bus/Middleware/TearDownAfterDispatch.php +++ b/src/Bus/Middleware/TearDownAfterDispatch.php @@ -10,12 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus\Middleware; +namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\BusMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class TearDownAfterDispatch implements BusMiddleware @@ -27,7 +26,7 @@ public function __construct(private Closure $callback) { } - public function __invoke(Command|Query $message, Closure $next): Result + public function __invoke(Message $message, Closure $next): ?Result { try { return $next($message); diff --git a/src/Application/InboundEventBus/Middleware/TearDownAfterEvent.php b/src/Bus/Middleware/TearDownAfterEvent.php similarity index 73% rename from src/Application/InboundEventBus/Middleware/TearDownAfterEvent.php rename to src/Bus/Middleware/TearDownAfterEvent.php index b93a22af..4e74b922 100644 --- a/src/Application/InboundEventBus/Middleware/TearDownAfterEvent.php +++ b/src/Bus/Middleware/TearDownAfterEvent.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus\Middleware; +namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\InboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; final readonly class TearDownAfterEvent implements InboundEventMiddleware { diff --git a/src/Application/Bus/Middleware/ValidateCommand.php b/src/Bus/Middleware/ValidateCommand.php similarity index 78% rename from src/Application/Bus/Middleware/ValidateCommand.php rename to src/Bus/Middleware/ValidateCommand.php index 08187877..5c122d23 100644 --- a/src/Application/Bus/Middleware/ValidateCommand.php +++ b/src/Bus/Middleware/ValidateCommand.php @@ -10,13 +10,13 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus\Middleware; +namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\Bail; -use CloudCreativity\Modules\Contracts\Application\Bus\CommandMiddleware; -use CloudCreativity\Modules\Contracts\Application\Bus\Validator; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware; +use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; +use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/src/Application/Bus/Middleware/ValidateQuery.php b/src/Bus/Middleware/ValidateQuery.php similarity index 78% rename from src/Application/Bus/Middleware/ValidateQuery.php rename to src/Bus/Middleware/ValidateQuery.php index 1b3d3bd3..88776d1f 100644 --- a/src/Application/Bus/Middleware/ValidateQuery.php +++ b/src/Bus/Middleware/ValidateQuery.php @@ -10,13 +10,13 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus\Middleware; +namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Application\Bus\Bail; -use CloudCreativity\Modules\Contracts\Application\Bus\QueryMiddleware; -use CloudCreativity\Modules\Contracts\Application\Bus\Validator; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Middleware\QueryMiddleware; +use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; +use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/src/Bus/PsrPipeContainer.php b/src/Bus/PsrPipeContainer.php new file mode 100644 index 00000000..72d0b961 --- /dev/null +++ b/src/Bus/PsrPipeContainer.php @@ -0,0 +1,56 @@ + + */ + private array $pipes = []; + + public function __construct(private readonly ?ContainerInterface $container = null) + { + } + + /** + * Bind a pipe into the container. + */ + public function bind(string $pipeName, Closure $factory): void + { + $this->pipes[$pipeName] = $factory; + } + + public function get(string $pipeName): callable + { + $factory = $this->pipes[$pipeName] ?? null; + + if (is_callable($factory)) { + $pipe = $factory(); + assert(is_callable($pipe), "Expecting pipe {$pipeName} from factory to be callable."); + return $pipe; + } + + if ($this->container) { + $pipe = $this->container->get($pipeName); + assert(is_callable($pipe), "Expecting pipe {$pipeName} from PSR container to be callable."); + return $pipe; + } + + throw new BusException('Unrecognised pipe name: ' . $pipeName); + } +} diff --git a/src/Application/Bus/QueryDispatcher.php b/src/Bus/QueryDispatcher.php similarity index 88% rename from src/Application/Bus/QueryDispatcher.php rename to src/Bus/QueryDispatcher.php index bdaced40..a4a1d1b3 100644 --- a/src/Application/Bus/QueryDispatcher.php +++ b/src/Bus/QueryDispatcher.php @@ -10,15 +10,14 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Application\Bus\QueryHandlerContainer as IQueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Application\Ports\Driving\QueryDispatcher as IQueryDispatcher; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Bus\QueryDispatcher as IQueryDispatcher; +use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer as IQueryHandlerContainer; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; use CloudCreativity\Modules\Toolkit\Pipeline\Through; use Psr\Container\ContainerInterface; @@ -44,7 +43,7 @@ public function __construct( $handlers; $this->middleware = $middleware === null && $handlers instanceof ContainerInterface - ? new PipeContainer($handlers) + ? new PsrPipeContainer($handlers) : $middleware; $this->autowire(); diff --git a/src/Application/Bus/QueryHandler.php b/src/Bus/QueryHandler.php similarity index 77% rename from src/Application/Bus/QueryHandler.php rename to src/Bus/QueryHandler.php index 1b41fe56..3fbe4c32 100644 --- a/src/Application/Bus/QueryHandler.php +++ b/src/Bus/QueryHandler.php @@ -10,11 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Application\Messages\HandlesMessages; -use CloudCreativity\Modules\Contracts\Application\Bus\QueryHandler as IQueryHandler; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Bus\QueryHandler as IQueryHandler; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class QueryHandler implements IQueryHandler diff --git a/src/Application/Bus/QueryHandlerContainer.php b/src/Bus/QueryHandlerContainer.php similarity index 76% rename from src/Application/Bus/QueryHandlerContainer.php rename to src/Bus/QueryHandlerContainer.php index 36231f7f..39615140 100644 --- a/src/Application/Bus/QueryHandlerContainer.php +++ b/src/Bus/QueryHandlerContainer.php @@ -10,12 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus; use Closure; -use CloudCreativity\Modules\Application\ApplicationException; -use CloudCreativity\Modules\Contracts\Application\Bus\QueryHandlerContainer as IQueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer as IQueryHandlerContainer; use Psr\Container\ContainerInterface; final class QueryHandlerContainer implements IQueryHandlerContainer @@ -38,7 +37,7 @@ public function __construct(private readonly ?ContainerInterface $container = nu public function bind(string $queryClass, Closure|string $binding): void { if (is_string($binding) && !$this->container) { - throw new ApplicationException('Cannot use a string query handler binding without a PSR container.'); + throw new BusException('Cannot use a string query handler binding without a PSR container.'); } $this->bindings[$queryClass] = $binding; @@ -60,6 +59,6 @@ public function get(string $queryClass): QueryHandler return new QueryHandler($instance); } - throw new ApplicationException('No query handler bound for query class: ' . $queryClass); + throw new BusException('No query handler bound for query class: ' . $queryClass); } } diff --git a/src/Application/InboundEventBus/SwallowInboundEvent.php b/src/Bus/SwallowInboundEvent.php similarity index 86% rename from src/Application/InboundEventBus/SwallowInboundEvent.php rename to src/Bus/SwallowInboundEvent.php index 7e171207..694ff507 100644 --- a/src/Application/InboundEventBus/SwallowInboundEvent.php +++ b/src/Bus/SwallowInboundEvent.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus; +namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Application/Bus/ValidationProcessor.php b/src/Bus/Validation/ValidationProcessor.php similarity index 86% rename from src/Application/Bus/ValidationProcessor.php rename to src/Bus/Validation/ValidationProcessor.php index 2cbbac3e..ad7c1c14 100644 --- a/src/Application/Bus/ValidationProcessor.php +++ b/src/Bus/Validation/ValidationProcessor.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus\Validation; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Processor; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/src/Application/Bus/Validator.php b/src/Bus/Validation/Validator.php similarity index 86% rename from src/Application/Bus/Validator.php rename to src/Bus/Validation/Validator.php index ee61b566..356ebf2e 100644 --- a/src/Application/Bus/Validator.php +++ b/src/Bus/Validation/Validator.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus\Validation; -use CloudCreativity\Modules\Contracts\Application\Bus\Validator as IValidator; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Bus\Validation\Validator as IValidator; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Pipeline; use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors as IListOfErrors; diff --git a/src/Application/Bus/WithCommand.php b/src/Bus/WithCommand.php similarity index 82% rename from src/Application/Bus/WithCommand.php rename to src/Bus/WithCommand.php index d689ce49..e30b4d7a 100644 --- a/src/Application/Bus/WithCommand.php +++ b/src/Bus/WithCommand.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithCommand diff --git a/src/Application/InboundEventBus/WithDefault.php b/src/Bus/WithDefault.php similarity index 87% rename from src/Application/InboundEventBus/WithDefault.php rename to src/Bus/WithDefault.php index 2b919754..55d03819 100644 --- a/src/Application/InboundEventBus/WithDefault.php +++ b/src/Bus/WithDefault.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus; +namespace CloudCreativity\Modules\Bus; use Attribute; diff --git a/src/Application/InboundEventBus/WithEvent.php b/src/Bus/WithEvent.php similarity index 80% rename from src/Application/InboundEventBus/WithEvent.php rename to src/Bus/WithEvent.php index 76f810b9..2fc08930 100644 --- a/src/Application/InboundEventBus/WithEvent.php +++ b/src/Bus/WithEvent.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\InboundEventBus; +namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithEvent diff --git a/src/Application/Bus/WithQuery.php b/src/Bus/WithQuery.php similarity index 82% rename from src/Application/Bus/WithQuery.php rename to src/Bus/WithQuery.php index 4dafba1a..2220adc3 100644 --- a/src/Application/Bus/WithQuery.php +++ b/src/Bus/WithQuery.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Application\Bus; +namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithQuery diff --git a/src/Contracts/Application/Bus/BusMiddleware.php b/src/Contracts/Application/Bus/BusMiddleware.php deleted file mode 100644 index 9daa1e4c..00000000 --- a/src/Contracts/Application/Bus/BusMiddleware.php +++ /dev/null @@ -1,29 +0,0 @@ - $next - * @return Result - */ - public function __invoke(Command|Query $message, Closure $next): Result; -} diff --git a/src/Contracts/Application/Ports/Driven/ExceptionReporter.php b/src/Contracts/Application/Ports/ExceptionReporter.php similarity index 84% rename from src/Contracts/Application/Ports/Driven/ExceptionReporter.php rename to src/Contracts/Application/Ports/ExceptionReporter.php index ade46806..dc623678 100644 --- a/src/Contracts/Application/Ports/Driven/ExceptionReporter.php +++ b/src/Contracts/Application/Ports/ExceptionReporter.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Ports\Driven; +namespace CloudCreativity\Modules\Contracts\Application\Ports; use Throwable; diff --git a/src/Contracts/Application/Ports/Driven/OutboundEventPublisher.php b/src/Contracts/Application/Ports/OutboundEventPublisher.php similarity index 73% rename from src/Contracts/Application/Ports/Driven/OutboundEventPublisher.php rename to src/Contracts/Application/Ports/OutboundEventPublisher.php index e7b62c80..a8011495 100644 --- a/src/Contracts/Application/Ports/Driven/OutboundEventPublisher.php +++ b/src/Contracts/Application/Ports/OutboundEventPublisher.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Ports\Driven; +namespace CloudCreativity\Modules\Contracts\Application\Ports; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface OutboundEventPublisher { diff --git a/src/Contracts/Application/Ports/Driven/Queue.php b/src/Contracts/Application/Ports/Queue.php similarity index 73% rename from src/Contracts/Application/Ports/Driven/Queue.php rename to src/Contracts/Application/Ports/Queue.php index 9ab19040..bbace628 100644 --- a/src/Contracts/Application/Ports/Driven/Queue.php +++ b/src/Contracts/Application/Ports/Queue.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Ports\Driven; +namespace CloudCreativity\Modules\Contracts\Application\Ports; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; interface Queue { diff --git a/src/Contracts/Application/Ports/Driven/UnitOfWork.php b/src/Contracts/Application/Ports/UnitOfWork.php similarity index 88% rename from src/Contracts/Application/Ports/Driven/UnitOfWork.php rename to src/Contracts/Application/Ports/UnitOfWork.php index 7fde9968..df30afe4 100644 --- a/src/Contracts/Application/Ports/Driven/UnitOfWork.php +++ b/src/Contracts/Application/Ports/UnitOfWork.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Ports\Driven; +namespace CloudCreativity\Modules\Contracts\Application\Ports; use Closure; diff --git a/src/Contracts/Toolkit/Messages/Command.php b/src/Contracts/Bus/Command.php similarity index 81% rename from src/Contracts/Toolkit/Messages/Command.php rename to src/Contracts/Bus/Command.php index 408f5181..dfce39b4 100644 --- a/src/Contracts/Toolkit/Messages/Command.php +++ b/src/Contracts/Bus/Command.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Toolkit\Messages; +namespace CloudCreativity\Modules\Contracts\Bus; interface Command extends Message { diff --git a/src/Contracts/Application/Ports/Driving/CommandDispatcher.php b/src/Contracts/Bus/CommandDispatcher.php similarity index 77% rename from src/Contracts/Application/Ports/Driving/CommandDispatcher.php rename to src/Contracts/Bus/CommandDispatcher.php index 4eccff10..50aa0e10 100644 --- a/src/Contracts/Application/Ports/Driving/CommandDispatcher.php +++ b/src/Contracts/Bus/CommandDispatcher.php @@ -10,9 +10,8 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Ports\Driving; +namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface CommandDispatcher diff --git a/src/Contracts/Application/Bus/CommandHandler.php b/src/Contracts/Bus/CommandHandler.php similarity index 70% rename from src/Contracts/Application/Bus/CommandHandler.php rename to src/Contracts/Bus/CommandHandler.php index 79d68732..ea5ff9c1 100644 --- a/src/Contracts/Application/Bus/CommandHandler.php +++ b/src/Contracts/Bus/CommandHandler.php @@ -10,10 +10,8 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Bus; +namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface CommandHandler extends DispatchThroughMiddleware diff --git a/src/Contracts/Application/Bus/CommandHandlerContainer.php b/src/Contracts/Bus/CommandHandlerContainer.php similarity index 78% rename from src/Contracts/Application/Bus/CommandHandlerContainer.php rename to src/Contracts/Bus/CommandHandlerContainer.php index a4a4eef2..5d0d149a 100644 --- a/src/Contracts/Application/Bus/CommandHandlerContainer.php +++ b/src/Contracts/Bus/CommandHandlerContainer.php @@ -10,9 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Bus; - -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +namespace CloudCreativity\Modules\Contracts\Bus; interface CommandHandlerContainer { diff --git a/src/Contracts/Application/Ports/Driving/CommandQueuer.php b/src/Contracts/Bus/CommandQueuer.php similarity index 73% rename from src/Contracts/Application/Ports/Driving/CommandQueuer.php rename to src/Contracts/Bus/CommandQueuer.php index 0ab06b79..d2e5bb6a 100644 --- a/src/Contracts/Application/Ports/Driving/CommandQueuer.php +++ b/src/Contracts/Bus/CommandQueuer.php @@ -10,9 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Ports\Driving; - -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +namespace CloudCreativity\Modules\Contracts\Bus; interface CommandQueuer { diff --git a/src/Contracts/Application/Messages/DispatchThroughMiddleware.php b/src/Contracts/Bus/DispatchThroughMiddleware.php similarity index 86% rename from src/Contracts/Application/Messages/DispatchThroughMiddleware.php rename to src/Contracts/Bus/DispatchThroughMiddleware.php index 1fa9962d..17f6a0b5 100644 --- a/src/Contracts/Application/Messages/DispatchThroughMiddleware.php +++ b/src/Contracts/Bus/DispatchThroughMiddleware.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Messages; +namespace CloudCreativity\Modules\Contracts\Bus; interface DispatchThroughMiddleware { diff --git a/src/Contracts/Application/InboundEventBus/EventHandler.php b/src/Contracts/Bus/EventHandler.php similarity index 63% rename from src/Contracts/Application/InboundEventBus/EventHandler.php rename to src/Contracts/Bus/EventHandler.php index c4f4c041..65ce9cee 100644 --- a/src/Contracts/Application/InboundEventBus/EventHandler.php +++ b/src/Contracts/Bus/EventHandler.php @@ -10,10 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\InboundEventBus; - -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +namespace CloudCreativity\Modules\Contracts\Bus; interface EventHandler extends DispatchThroughMiddleware { diff --git a/src/Contracts/Application/InboundEventBus/EventHandlerContainer.php b/src/Contracts/Bus/EventHandlerContainer.php similarity index 76% rename from src/Contracts/Application/InboundEventBus/EventHandlerContainer.php rename to src/Contracts/Bus/EventHandlerContainer.php index c551cf03..9f5bb9d6 100644 --- a/src/Contracts/Application/InboundEventBus/EventHandlerContainer.php +++ b/src/Contracts/Bus/EventHandlerContainer.php @@ -10,9 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\InboundEventBus; - -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +namespace CloudCreativity\Modules\Contracts\Bus; interface EventHandlerContainer { diff --git a/src/Contracts/Application/Ports/Driving/InboundEventDispatcher.php b/src/Contracts/Bus/InboundEventDispatcher.php similarity index 73% rename from src/Contracts/Application/Ports/Driving/InboundEventDispatcher.php rename to src/Contracts/Bus/InboundEventDispatcher.php index c6af5c2b..143bf3ae 100644 --- a/src/Contracts/Application/Ports/Driving/InboundEventDispatcher.php +++ b/src/Contracts/Bus/InboundEventDispatcher.php @@ -10,9 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Ports\Driving; - -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +namespace CloudCreativity\Modules\Contracts\Bus; interface InboundEventDispatcher { diff --git a/src/Contracts/Toolkit/Messages/IntegrationEvent.php b/src/Contracts/Bus/IntegrationEvent.php similarity index 88% rename from src/Contracts/Toolkit/Messages/IntegrationEvent.php rename to src/Contracts/Bus/IntegrationEvent.php index a6a1c5a2..2f38a84e 100644 --- a/src/Contracts/Toolkit/Messages/IntegrationEvent.php +++ b/src/Contracts/Bus/IntegrationEvent.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Toolkit\Messages; +namespace CloudCreativity\Modules\Contracts\Bus; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/src/Contracts/Toolkit/Loggable/ContextFactory.php b/src/Contracts/Bus/Loggable/ContextFactory.php similarity index 81% rename from src/Contracts/Toolkit/Loggable/ContextFactory.php rename to src/Contracts/Bus/Loggable/ContextFactory.php index 17420715..7085c04f 100644 --- a/src/Contracts/Toolkit/Loggable/ContextFactory.php +++ b/src/Contracts/Bus/Loggable/ContextFactory.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Toolkit\Loggable; +namespace CloudCreativity\Modules\Contracts\Bus\Loggable; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Message; +use CloudCreativity\Modules\Contracts\Bus\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface ContextFactory diff --git a/src/Contracts/Toolkit/Loggable/ContextProvider.php b/src/Contracts/Bus/Loggable/ContextProvider.php similarity index 86% rename from src/Contracts/Toolkit/Loggable/ContextProvider.php rename to src/Contracts/Bus/Loggable/ContextProvider.php index b7e680ca..fee132c9 100644 --- a/src/Contracts/Toolkit/Loggable/ContextProvider.php +++ b/src/Contracts/Bus/Loggable/ContextProvider.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Toolkit\Loggable; +namespace CloudCreativity\Modules\Contracts\Bus\Loggable; interface ContextProvider { diff --git a/src/Contracts/Toolkit/Loggable/Contextual.php b/src/Contracts/Bus/Loggable/Contextual.php similarity index 86% rename from src/Contracts/Toolkit/Loggable/Contextual.php rename to src/Contracts/Bus/Loggable/Contextual.php index 8c949ff7..d434b9d0 100644 --- a/src/Contracts/Toolkit/Loggable/Contextual.php +++ b/src/Contracts/Bus/Loggable/Contextual.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Toolkit\Loggable; +namespace CloudCreativity\Modules\Contracts\Bus\Loggable; interface Contextual { diff --git a/src/Contracts/Toolkit/Messages/Message.php b/src/Contracts/Bus/Message.php similarity index 80% rename from src/Contracts/Toolkit/Messages/Message.php rename to src/Contracts/Bus/Message.php index b9035e5b..b71da774 100644 --- a/src/Contracts/Toolkit/Messages/Message.php +++ b/src/Contracts/Bus/Message.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Toolkit\Messages; +namespace CloudCreativity\Modules\Contracts\Bus; interface Message { diff --git a/src/Contracts/Bus/Middleware/BusMiddleware.php b/src/Contracts/Bus/Middleware/BusMiddleware.php new file mode 100644 index 00000000..513c555b --- /dev/null +++ b/src/Contracts/Bus/Middleware/BusMiddleware.php @@ -0,0 +1,28 @@ +) $next + * @return Result|null + */ + public function __invoke(Message $message, Closure $next): ?Result; +} diff --git a/src/Contracts/Application/Bus/CommandMiddleware.php b/src/Contracts/Bus/Middleware/CommandMiddleware.php similarity index 81% rename from src/Contracts/Application/Bus/CommandMiddleware.php rename to src/Contracts/Bus/Middleware/CommandMiddleware.php index fe6bb0b7..8c654793 100644 --- a/src/Contracts/Application/Bus/CommandMiddleware.php +++ b/src/Contracts/Bus/Middleware/CommandMiddleware.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Bus; +namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface CommandMiddleware diff --git a/src/Contracts/Application/InboundEventBus/InboundEventMiddleware.php b/src/Contracts/Bus/Middleware/InboundEventMiddleware.php similarity index 76% rename from src/Contracts/Application/InboundEventBus/InboundEventMiddleware.php rename to src/Contracts/Bus/Middleware/InboundEventMiddleware.php index d5141d8b..2a2421f2 100644 --- a/src/Contracts/Application/InboundEventBus/InboundEventMiddleware.php +++ b/src/Contracts/Bus/Middleware/InboundEventMiddleware.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\InboundEventBus; +namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface InboundEventMiddleware { diff --git a/src/Contracts/Application/Bus/QueryMiddleware.php b/src/Contracts/Bus/Middleware/QueryMiddleware.php similarity index 81% rename from src/Contracts/Application/Bus/QueryMiddleware.php rename to src/Contracts/Bus/Middleware/QueryMiddleware.php index fe76b2d4..4fd58985 100644 --- a/src/Contracts/Application/Bus/QueryMiddleware.php +++ b/src/Contracts/Bus/Middleware/QueryMiddleware.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Bus; +namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface QueryMiddleware diff --git a/src/Contracts/Toolkit/Messages/Query.php b/src/Contracts/Bus/Query.php similarity index 81% rename from src/Contracts/Toolkit/Messages/Query.php rename to src/Contracts/Bus/Query.php index 4510099e..cadff8fc 100644 --- a/src/Contracts/Toolkit/Messages/Query.php +++ b/src/Contracts/Bus/Query.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Toolkit\Messages; +namespace CloudCreativity\Modules\Contracts\Bus; interface Query extends Message { diff --git a/src/Contracts/Application/Ports/Driving/QueryDispatcher.php b/src/Contracts/Bus/QueryDispatcher.php similarity index 77% rename from src/Contracts/Application/Ports/Driving/QueryDispatcher.php rename to src/Contracts/Bus/QueryDispatcher.php index 9bf4a403..281ac3d5 100644 --- a/src/Contracts/Application/Ports/Driving/QueryDispatcher.php +++ b/src/Contracts/Bus/QueryDispatcher.php @@ -10,9 +10,8 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Ports\Driving; +namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface QueryDispatcher diff --git a/src/Contracts/Application/Bus/QueryHandler.php b/src/Contracts/Bus/QueryHandler.php similarity index 70% rename from src/Contracts/Application/Bus/QueryHandler.php rename to src/Contracts/Bus/QueryHandler.php index a7f62533..faf0d2b9 100644 --- a/src/Contracts/Application/Bus/QueryHandler.php +++ b/src/Contracts/Bus/QueryHandler.php @@ -10,10 +10,8 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Bus; +namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface QueryHandler extends DispatchThroughMiddleware diff --git a/src/Contracts/Application/Bus/QueryHandlerContainer.php b/src/Contracts/Bus/QueryHandlerContainer.php similarity index 78% rename from src/Contracts/Application/Bus/QueryHandlerContainer.php rename to src/Contracts/Bus/QueryHandlerContainer.php index 76be3b9a..b5193b73 100644 --- a/src/Contracts/Application/Bus/QueryHandlerContainer.php +++ b/src/Contracts/Bus/QueryHandlerContainer.php @@ -10,9 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Bus; - -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +namespace CloudCreativity\Modules\Contracts\Bus; interface QueryHandlerContainer { diff --git a/src/Contracts/Application/Bus/Bail.php b/src/Contracts/Bus/Validation/Bail.php similarity index 80% rename from src/Contracts/Application/Bus/Bail.php rename to src/Contracts/Bus/Validation/Bail.php index b77a81a4..65baf358 100644 --- a/src/Contracts/Application/Bus/Bail.php +++ b/src/Contracts/Bus/Validation/Bail.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Bus; +namespace CloudCreativity\Modules\Contracts\Bus\Validation; interface Bail { diff --git a/src/Contracts/Application/Bus/Validator.php b/src/Contracts/Bus/Validation/Validator.php similarity index 81% rename from src/Contracts/Application/Bus/Validator.php rename to src/Contracts/Bus/Validation/Validator.php index f6bf9c66..0d126202 100644 --- a/src/Contracts/Application/Bus/Validator.php +++ b/src/Contracts/Bus/Validation/Validator.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Application\Bus; +namespace CloudCreativity\Modules\Contracts\Bus\Validation; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors; interface Validator diff --git a/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php b/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php index 829514d9..89c0b335 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; use Closure; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface OutboundEventMiddleware { diff --git a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php index 30a1bb9b..71fda2f7 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface PublisherHandler { diff --git a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php index e5891a95..b8e1c0a1 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; interface PublisherHandlerContainer { diff --git a/src/Contracts/Infrastructure/Queue/Enqueuer.php b/src/Contracts/Infrastructure/Queue/Enqueuer.php index 2fb92890..e1892f7b 100644 --- a/src/Contracts/Infrastructure/Queue/Enqueuer.php +++ b/src/Contracts/Infrastructure/Queue/Enqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; interface Enqueuer { diff --git a/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php b/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php index ca7e130d..25821f14 100644 --- a/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php +++ b/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; interface EnqueuerContainer { diff --git a/src/Contracts/Infrastructure/Queue/QueueMiddleware.php b/src/Contracts/Infrastructure/Queue/QueueMiddleware.php index 0cb96118..007d1657 100644 --- a/src/Contracts/Infrastructure/Queue/QueueMiddleware.php +++ b/src/Contracts/Infrastructure/Queue/QueueMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; use Closure; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; interface QueueMiddleware { diff --git a/src/Contracts/Toolkit/Identifiers/Identifier.php b/src/Contracts/Toolkit/Identifiers/Identifier.php index 0dbb559c..cdb1d3bc 100644 --- a/src/Contracts/Toolkit/Identifiers/Identifier.php +++ b/src/Contracts/Toolkit/Identifiers/Identifier.php @@ -12,10 +12,9 @@ namespace CloudCreativity\Modules\Contracts\Toolkit\Identifiers; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\Contextual; use Stringable; -interface Identifier extends Stringable, Contextual +interface Identifier extends Stringable { /** * Is the identifier the same as the provided identifier? @@ -38,4 +37,9 @@ public function toString(): string; * @return array-key */ public function key(): int|string; + + /** + * Get the value to use when adding the value to log context. + */ + public function context(): mixed; } diff --git a/src/Infrastructure/ExceptionReporter/PsrLogExceptionReporter.php b/src/Infrastructure/ExceptionReporter/PsrLogExceptionReporter.php index 39baa2c7..67ae9de5 100644 --- a/src/Infrastructure/ExceptionReporter/PsrLogExceptionReporter.php +++ b/src/Infrastructure/ExceptionReporter/PsrLogExceptionReporter.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Infrastructure\ExceptionReporter; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\ExceptionReporter; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; +use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; use Psr\Log\LoggerInterface; use Throwable; diff --git a/src/Infrastructure/OutboundEventBus/ClosurePublisher.php b/src/Infrastructure/OutboundEventBus/ClosurePublisher.php index b5b90446..d70ec27a 100644 --- a/src/Infrastructure/OutboundEventBus/ClosurePublisher.php +++ b/src/Infrastructure/OutboundEventBus/ClosurePublisher.php @@ -13,9 +13,10 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus; use Closure; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\OutboundEventPublisher; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; -use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; +use CloudCreativity\Modules\Bus\PsrPipeContainer; +use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; use CloudCreativity\Modules\Toolkit\Pipeline\Through; @@ -24,6 +25,8 @@ class ClosurePublisher implements OutboundEventPublisher { + private readonly ?IPipeContainer $middleware; + /** * @var array, Closure> */ @@ -36,8 +39,11 @@ class ClosurePublisher implements OutboundEventPublisher public function __construct( private readonly Closure $fn, - private readonly ContainerInterface|PipeContainer|null $middleware = null, + ContainerInterface|IPipeContainer|null $middleware = null, ) { + $this->middleware = $middleware instanceof ContainerInterface ? + new PsrPipeContainer($middleware) : $middleware; + $this->autowire(); } diff --git a/src/Infrastructure/OutboundEventBus/ComponentPublisher.php b/src/Infrastructure/OutboundEventBus/ComponentPublisher.php index 4a1d3f2d..bb6f7e2a 100644 --- a/src/Infrastructure/OutboundEventBus/ComponentPublisher.php +++ b/src/Infrastructure/OutboundEventBus/ComponentPublisher.php @@ -12,12 +12,12 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\OutboundEventPublisher; +use CloudCreativity\Modules\Bus\PsrPipeContainer; +use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\PublisherHandlerContainer as IPublisherHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; use CloudCreativity\Modules\Toolkit\Pipeline\Through; use Psr\Container\ContainerInterface; @@ -43,7 +43,7 @@ public function __construct( $handlers; $this->middleware = $middleware === null && $handlers instanceof ContainerInterface ? - new PipeContainer(container: $handlers) : + new PsrPipeContainer(container: $handlers) : $middleware; $this->autowire(); diff --git a/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php b/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php index 8aedfbe1..556bf181 100644 --- a/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php +++ b/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php @@ -13,10 +13,10 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware; use Closure; +use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; -use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Infrastructure/OutboundEventBus/PublisherHandler.php b/src/Infrastructure/OutboundEventBus/PublisherHandler.php index 47559a2c..b7a9cf00 100644 --- a/src/Infrastructure/OutboundEventBus/PublisherHandler.php +++ b/src/Infrastructure/OutboundEventBus/PublisherHandler.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\PublisherHandler as IPublisherHandler; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; final readonly class PublisherHandler implements IPublisherHandler { diff --git a/src/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php b/src/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php index e04b1604..2ba24d5f 100644 --- a/src/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php +++ b/src/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php @@ -13,11 +13,11 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus; use Closure; -use Psr\Container\ContainerInterface; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\{ PublisherHandlerContainer as IPublisherHandlerContainer}; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; use CloudCreativity\Modules\Infrastructure\InfrastructureException; +use Psr\Container\ContainerInterface; final class PublisherHandlerContainer implements IPublisherHandlerContainer { diff --git a/src/Infrastructure/OutboundEventBus/Publishes.php b/src/Infrastructure/OutboundEventBus/Publishes.php index 77d68c0e..d27bc429 100644 --- a/src/Infrastructure/OutboundEventBus/Publishes.php +++ b/src/Infrastructure/OutboundEventBus/Publishes.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus; use Attribute; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class Publishes diff --git a/src/Infrastructure/Queue/ClosureQueue.php b/src/Infrastructure/Queue/ClosureQueue.php index 45aafff9..e9c8da82 100644 --- a/src/Infrastructure/Queue/ClosureQueue.php +++ b/src/Infrastructure/Queue/ClosureQueue.php @@ -13,9 +13,10 @@ namespace CloudCreativity\Modules\Infrastructure\Queue; use Closure; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; +use CloudCreativity\Modules\Bus\PsrPipeContainer; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; use CloudCreativity\Modules\Toolkit\Pipeline\Through; @@ -24,6 +25,8 @@ class ClosureQueue implements Queue { + private readonly ?IPipeContainer $middleware; + /** * @var array, Closure> */ @@ -36,8 +39,11 @@ class ClosureQueue implements Queue public function __construct( private readonly Closure $fn, - private readonly ContainerInterface|PipeContainer|null $middleware = null, + ContainerInterface|IPipeContainer|null $middleware = null, ) { + $this->middleware = $middleware instanceof ContainerInterface ? + new PsrPipeContainer($middleware) : $middleware; + $this->autowire(); } diff --git a/src/Infrastructure/Queue/ComponentQueue.php b/src/Infrastructure/Queue/ComponentQueue.php index 8496f20d..098656f6 100644 --- a/src/Infrastructure/Queue/ComponentQueue.php +++ b/src/Infrastructure/Queue/ComponentQueue.php @@ -12,12 +12,12 @@ namespace CloudCreativity\Modules\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue; +use CloudCreativity\Modules\Bus\PsrPipeContainer; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\EnqueuerContainer as IEnqueuerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; use CloudCreativity\Modules\Toolkit\Pipeline\Through; use Psr\Container\ContainerInterface; @@ -43,7 +43,7 @@ public function __construct( $enqueuers; $this->middleware = $middleware === null && $enqueuers instanceof ContainerInterface - ? new PipeContainer($enqueuers) + ? new PsrPipeContainer($enqueuers) : $middleware; $this->autowire(); diff --git a/src/Infrastructure/Queue/Enqueuer.php b/src/Infrastructure/Queue/Enqueuer.php index eadb40be..f7005162 100644 --- a/src/Infrastructure/Queue/Enqueuer.php +++ b/src/Infrastructure/Queue/Enqueuer.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Infrastructure\Queue; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\Enqueuer as IEnqueuer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; final readonly class Enqueuer implements IEnqueuer { diff --git a/src/Infrastructure/Queue/EnqueuerContainer.php b/src/Infrastructure/Queue/EnqueuerContainer.php index 6113e128..4dbff20b 100644 --- a/src/Infrastructure/Queue/EnqueuerContainer.php +++ b/src/Infrastructure/Queue/EnqueuerContainer.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Infrastructure\Queue; use Closure; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\EnqueuerContainer as IEnqueuerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; use CloudCreativity\Modules\Infrastructure\InfrastructureException; use Psr\Container\ContainerInterface; diff --git a/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php b/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php index 91616cc5..3b81e9be 100644 --- a/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php +++ b/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php @@ -13,10 +13,10 @@ namespace CloudCreativity\Modules\Infrastructure\Queue\Middleware; use Closure; +use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Infrastructure/Queue/Queues.php b/src/Infrastructure/Queue/Queues.php index 6977fa69..875a5ec5 100644 --- a/src/Infrastructure/Queue/Queues.php +++ b/src/Infrastructure/Queue/Queues.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Infrastructure\Queue; use Attribute; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class Queues diff --git a/src/Testing/FakeContainer.php b/src/Testing/FakeContainer.php index c6af06ff..5cf545e7 100644 --- a/src/Testing/FakeContainer.php +++ b/src/Testing/FakeContainer.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Testing; use Closure; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\ExceptionReporter; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\UnitOfWork; +use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter; +use CloudCreativity\Modules\Contracts\Application\Ports\UnitOfWork; use Exception; use Psr\Container\ContainerInterface; use Psr\Container\NotFoundExceptionInterface; diff --git a/src/Testing/FakeExceptionReporter.php b/src/Testing/FakeExceptionReporter.php index 3ec11516..c04c82f5 100644 --- a/src/Testing/FakeExceptionReporter.php +++ b/src/Testing/FakeExceptionReporter.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Testing; use ArrayAccess; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\ExceptionReporter; +use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter; use Countable; use Generator; use IteratorAggregate; diff --git a/src/Testing/FakeOutboundEventPublisher.php b/src/Testing/FakeOutboundEventPublisher.php index 85f2e164..8de56a78 100644 --- a/src/Testing/FakeOutboundEventPublisher.php +++ b/src/Testing/FakeOutboundEventPublisher.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Testing; use ArrayAccess; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\OutboundEventPublisher; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use Countable; use Generator; use IteratorAggregate; diff --git a/src/Testing/FakeQueue.php b/src/Testing/FakeQueue.php index ff24839a..25391640 100644 --- a/src/Testing/FakeQueue.php +++ b/src/Testing/FakeQueue.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Testing; use ArrayAccess; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue; +use CloudCreativity\Modules\Contracts\Bus\Command; use Countable; use Generator; use IteratorAggregate; diff --git a/src/Testing/FakeUnitOfWork.php b/src/Testing/FakeUnitOfWork.php index f3a6ceb9..b4ac9a4e 100644 --- a/src/Testing/FakeUnitOfWork.php +++ b/src/Testing/FakeUnitOfWork.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Testing; use Closure; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\UnitOfWork; +use CloudCreativity\Modules\Contracts\Application\Ports\UnitOfWork; use InvalidArgumentException; use RuntimeException; use Throwable; diff --git a/src/Toolkit/Pipeline/PipeContainer.php b/src/Toolkit/Pipeline/PipeContainer.php index 3e63da29..f94709a2 100644 --- a/src/Toolkit/Pipeline/PipeContainer.php +++ b/src/Toolkit/Pipeline/PipeContainer.php @@ -14,7 +14,6 @@ use Closure; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; -use Psr\Container\ContainerInterface; use RuntimeException; final class PipeContainer implements IPipeContainer @@ -24,10 +23,6 @@ final class PipeContainer implements IPipeContainer */ private array $pipes = []; - public function __construct(private readonly ?ContainerInterface $container = null) - { - } - /** * Bind a pipe into the container. */ @@ -46,12 +41,6 @@ public function get(string $pipeName): callable return $pipe; } - if ($this->container) { - $pipe = $this->container->get($pipeName); - assert(is_callable($pipe), "Expecting pipe {$pipeName} from PSR container to be callable."); - return $pipe; - } - throw new RuntimeException('Unrecognised pipe name: ' . $pipeName); } } diff --git a/src/Toolkit/Pipeline/PipelineBuilder.php b/src/Toolkit/Pipeline/PipelineBuilder.php index 88175b8e..eee983a4 100644 --- a/src/Toolkit/Pipeline/PipelineBuilder.php +++ b/src/Toolkit/Pipeline/PipelineBuilder.php @@ -15,7 +15,6 @@ use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipelineBuilder as IPipelineBuilder; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Processor; -use Psr\Container\ContainerInterface; use RuntimeException; final class PipelineBuilder implements IPipelineBuilder @@ -25,12 +24,8 @@ final class PipelineBuilder implements IPipelineBuilder */ private array $stages = []; - public static function make(ContainerInterface|IPipeContainer|null $container = null): self + public static function make(?IPipeContainer $container = null): self { - if ($container instanceof ContainerInterface) { - return new self(new PipeContainer($container)); - } - return new self($container); } diff --git a/src/Toolkit/Result/FailedResultException.php b/src/Toolkit/Result/FailedResultException.php index 237905ad..b78a8d7a 100644 --- a/src/Toolkit/Result/FailedResultException.php +++ b/src/Toolkit/Result/FailedResultException.php @@ -12,15 +12,13 @@ namespace CloudCreativity\Modules\Toolkit\Result; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; -use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory; use RuntimeException; use Throwable; use function CloudCreativity\Modules\Toolkit\enum_string; -class FailedResultException extends RuntimeException implements ContextProvider +class FailedResultException extends RuntimeException { /** * @param Result $result @@ -48,9 +46,4 @@ public function getResult(): Result { return $this->result; } - - public function context(): array - { - return (new SimpleContextFactory())->make($this->result); - } } diff --git a/tests/Integration/Application/Bus/AddCommand.php b/tests/Integration/Bus/AddCommand.php similarity index 73% rename from tests/Integration/Application/Bus/AddCommand.php rename to tests/Integration/Bus/AddCommand.php index 2596e234..dbf21a71 100644 --- a/tests/Integration/Application/Bus/AddCommand.php +++ b/tests/Integration/Bus/AddCommand.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; final readonly class AddCommand implements Command { diff --git a/tests/Integration/Application/Bus/AddCommandHandler.php b/tests/Integration/Bus/AddCommandHandler.php similarity index 89% rename from tests/Integration/Application/Bus/AddCommandHandler.php rename to tests/Integration/Bus/AddCommandHandler.php index b0aa53c9..0304c34e 100644 --- a/tests/Integration/Application/Bus/AddCommandHandler.php +++ b/tests/Integration/Bus/AddCommandHandler.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/tests/Integration/Application/InboundEventBus/DefaultHandler.php b/tests/Integration/Bus/DefaultEventHandler.php similarity index 70% rename from tests/Integration/Application/InboundEventBus/DefaultHandler.php rename to tests/Integration/Bus/DefaultEventHandler.php index 73f6f21a..0828886e 100644 --- a/tests/Integration/Application/InboundEventBus/DefaultHandler.php +++ b/tests/Integration/Bus/DefaultEventHandler.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; -final class DefaultHandler +final class DefaultEventHandler { /** * @var array diff --git a/tests/Integration/Application/Bus/DivideQuery.php b/tests/Integration/Bus/DivideQuery.php similarity index 73% rename from tests/Integration/Application/Bus/DivideQuery.php rename to tests/Integration/Bus/DivideQuery.php index e439eba3..39d1c0a5 100644 --- a/tests/Integration/Application/Bus/DivideQuery.php +++ b/tests/Integration/Bus/DivideQuery.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query; final readonly class DivideQuery implements Query { diff --git a/tests/Integration/Application/Bus/DivideQueryHandler.php b/tests/Integration/Bus/DivideQueryHandler.php similarity index 89% rename from tests/Integration/Application/Bus/DivideQueryHandler.php rename to tests/Integration/Bus/DivideQueryHandler.php index d32520be..d23a880e 100644 --- a/tests/Integration/Application/Bus/DivideQueryHandler.php +++ b/tests/Integration/Bus/DivideQueryHandler.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; use CloudCreativity\Modules\Toolkit\Pipeline\Through; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/tests/Integration/Application/Bus/FloorCommand.php b/tests/Integration/Bus/FloorCommand.php similarity index 73% rename from tests/Integration/Application/Bus/FloorCommand.php rename to tests/Integration/Bus/FloorCommand.php index fc79999d..e5dadd49 100644 --- a/tests/Integration/Application/Bus/FloorCommand.php +++ b/tests/Integration/Bus/FloorCommand.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; final readonly class FloorCommand implements Command { diff --git a/tests/Integration/Application/Bus/MathCommandBus.php b/tests/Integration/Bus/MathCommandBus.php similarity index 66% rename from tests/Integration/Application/Bus/MathCommandBus.php rename to tests/Integration/Bus/MathCommandBus.php index dfad23f6..19f146c9 100644 --- a/tests/Integration/Application/Bus/MathCommandBus.php +++ b/tests/Integration/Bus/MathCommandBus.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Application\Bus\CommandDispatcher; -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; -use CloudCreativity\Modules\Application\Bus\WithCommand; +use CloudCreativity\Modules\Bus\CommandDispatcher; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; +use CloudCreativity\Modules\Bus\WithCommand; use CloudCreativity\Modules\Toolkit\Pipeline\Through; #[Through(LogMessageDispatch::class)] diff --git a/tests/Integration/Application/Bus/MathCommandBusTest.php b/tests/Integration/Bus/MathCommandBusTest.php similarity index 90% rename from tests/Integration/Application/Bus/MathCommandBusTest.php rename to tests/Integration/Bus/MathCommandBusTest.php index 6c0d46e3..805b2bde 100644 --- a/tests/Integration/Application/Bus/MathCommandBusTest.php +++ b/tests/Integration/Bus/MathCommandBusTest.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; use CloudCreativity\Modules\Application\UnitOfWork\UnitOfWorkManager; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; use CloudCreativity\Modules\Testing\FakeContainer; use PHPUnit\Framework\TestCase; diff --git a/tests/Integration/Application/InboundEventBus/MathEventBus.php b/tests/Integration/Bus/MathEventBus.php similarity index 55% rename from tests/Integration/Application/InboundEventBus/MathEventBus.php rename to tests/Integration/Bus/MathEventBus.php index cd56b7d2..30f3a259 100644 --- a/tests/Integration/Application/InboundEventBus/MathEventBus.php +++ b/tests/Integration/Bus/MathEventBus.php @@ -10,16 +10,16 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Application\InboundEventBus\InboundEventDispatcher; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\LogInboundEvent; -use CloudCreativity\Modules\Application\InboundEventBus\WithDefault; -use CloudCreativity\Modules\Application\InboundEventBus\WithEvent; +use CloudCreativity\Modules\Bus\InboundEventDispatcher; +use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent; +use CloudCreativity\Modules\Bus\WithDefault; +use CloudCreativity\Modules\Bus\WithEvent; use CloudCreativity\Modules\Toolkit\Pipeline\Through; #[Through(LogInboundEvent::class)] -#[WithDefault(DefaultHandler::class)] +#[WithDefault(DefaultEventHandler::class)] #[WithEvent(NumbersAdded::class, NumbersAddedHandler::class)] #[WithEvent(NumbersSubtracted::class, NumbersSubtractedHandler::class)] final class MathEventBus extends InboundEventDispatcher diff --git a/tests/Integration/Application/InboundEventBus/MathEventBusTest.php b/tests/Integration/Bus/MathEventBusTest.php similarity index 76% rename from tests/Integration/Application/InboundEventBus/MathEventBusTest.php rename to tests/Integration/Bus/MathEventBusTest.php index 7f73a901..4d2423e6 100644 --- a/tests/Integration/Application/InboundEventBus/MathEventBusTest.php +++ b/tests/Integration/Bus/MathEventBusTest.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\HandleInUnitOfWork; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\LogInboundEvent; +use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; use CloudCreativity\Modules\Application\UnitOfWork\UnitOfWorkManager; +use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent; use CloudCreativity\Modules\Testing\FakeContainer; use PHPUnit\Framework\TestCase; @@ -24,14 +24,14 @@ public function test(): void { $a = new NumbersAddedHandler(); $b = new NumbersSubtractedHandler(); - $c = new DefaultHandler(); + $c = new DefaultEventHandler(); $container = new FakeContainer(); $container->bind(NumbersAddedHandler::class, fn () => $a); $container->bind(NumbersSubtractedHandler::class, fn () => $b); - $container->bind(DefaultHandler::class, fn () => $c); + $container->bind(DefaultEventHandler::class, fn () => $c); $container->bind(LogInboundEvent::class, fn () => new LogInboundEvent($container->logger)); - $container->bind(HandleInUnitOfWork::class, fn () => new HandleInUnitOfWork( + $container->bind(ExecuteInUnitOfWork::class, fn () => new ExecuteInUnitOfWork( new UnitOfWorkManager($container->unitOfWork), )); diff --git a/tests/Integration/Application/Bus/MathQueryBus.php b/tests/Integration/Bus/MathQueryBus.php similarity index 66% rename from tests/Integration/Application/Bus/MathQueryBus.php rename to tests/Integration/Bus/MathQueryBus.php index 0cf831cf..6c913a32 100644 --- a/tests/Integration/Application/Bus/MathQueryBus.php +++ b/tests/Integration/Bus/MathQueryBus.php @@ -10,11 +10,11 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; -use CloudCreativity\Modules\Application\Bus\QueryDispatcher; -use CloudCreativity\Modules\Application\Bus\WithQuery; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; +use CloudCreativity\Modules\Bus\QueryDispatcher; +use CloudCreativity\Modules\Bus\WithQuery; use CloudCreativity\Modules\Toolkit\Pipeline\Through; #[Through(LogMessageDispatch::class)] diff --git a/tests/Integration/Application/Bus/MathQueryBusTest.php b/tests/Integration/Bus/MathQueryBusTest.php similarity index 90% rename from tests/Integration/Application/Bus/MathQueryBusTest.php rename to tests/Integration/Bus/MathQueryBusTest.php index ab44250c..d07e0277 100644 --- a/tests/Integration/Application/Bus/MathQueryBusTest.php +++ b/tests/Integration/Bus/MathQueryBusTest.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; use Closure; -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; use CloudCreativity\Modules\Testing\FakeContainer; use PHPUnit\Framework\TestCase; diff --git a/tests/Integration/Application/Bus/MultiplyCommand.php b/tests/Integration/Bus/MultiplyCommand.php similarity index 73% rename from tests/Integration/Application/Bus/MultiplyCommand.php rename to tests/Integration/Bus/MultiplyCommand.php index fe637476..e121e74b 100644 --- a/tests/Integration/Application/Bus/MultiplyCommand.php +++ b/tests/Integration/Bus/MultiplyCommand.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; final readonly class MultiplyCommand implements Command { diff --git a/tests/Integration/Application/Bus/MultiplyCommandHandler.php b/tests/Integration/Bus/MultiplyCommandHandler.php similarity index 91% rename from tests/Integration/Application/Bus/MultiplyCommandHandler.php rename to tests/Integration/Bus/MultiplyCommandHandler.php index a76e4e85..3db406ac 100644 --- a/tests/Integration/Application/Bus/MultiplyCommandHandler.php +++ b/tests/Integration/Bus/MultiplyCommandHandler.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; use CloudCreativity\Modules\Toolkit\Pipeline\Through; diff --git a/tests/Integration/Application/InboundEventBus/NumbersAdded.php b/tests/Integration/Bus/NumbersAdded.php similarity index 86% rename from tests/Integration/Application/InboundEventBus/NumbersAdded.php rename to tests/Integration/Bus/NumbersAdded.php index 271af6d6..92bd6620 100644 --- a/tests/Integration/Application/InboundEventBus/NumbersAdded.php +++ b/tests/Integration/Bus/NumbersAdded.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Integration/Application/InboundEventBus/NumbersAddedHandler.php b/tests/Integration/Bus/NumbersAddedHandler.php similarity index 84% rename from tests/Integration/Application/InboundEventBus/NumbersAddedHandler.php rename to tests/Integration/Bus/NumbersAddedHandler.php index 686dd946..b7961cbf 100644 --- a/tests/Integration/Application/InboundEventBus/NumbersAddedHandler.php +++ b/tests/Integration/Bus/NumbersAddedHandler.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; final class NumbersAddedHandler { diff --git a/tests/Integration/Application/InboundEventBus/NumbersDivided.php b/tests/Integration/Bus/NumbersDivided.php similarity index 86% rename from tests/Integration/Application/InboundEventBus/NumbersDivided.php rename to tests/Integration/Bus/NumbersDivided.php index 020aae95..1bc6dc1f 100644 --- a/tests/Integration/Application/InboundEventBus/NumbersDivided.php +++ b/tests/Integration/Bus/NumbersDivided.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Integration/Application/InboundEventBus/NumbersSubtracted.php b/tests/Integration/Bus/NumbersSubtracted.php similarity index 86% rename from tests/Integration/Application/InboundEventBus/NumbersSubtracted.php rename to tests/Integration/Bus/NumbersSubtracted.php index 112fd561..f4d7ada1 100644 --- a/tests/Integration/Application/InboundEventBus/NumbersSubtracted.php +++ b/tests/Integration/Bus/NumbersSubtracted.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Integration/Application/InboundEventBus/NumbersSubtractedHandler.php b/tests/Integration/Bus/NumbersSubtractedHandler.php similarity index 71% rename from tests/Integration/Application/InboundEventBus/NumbersSubtractedHandler.php rename to tests/Integration/Bus/NumbersSubtractedHandler.php index e2987680..db605af2 100644 --- a/tests/Integration/Application/InboundEventBus/NumbersSubtractedHandler.php +++ b/tests/Integration/Bus/NumbersSubtractedHandler.php @@ -10,12 +10,12 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\HandleInUnitOfWork; +use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; use CloudCreativity\Modules\Toolkit\Pipeline\Through; -#[Through(HandleInUnitOfWork::class)] +#[Through(ExecuteInUnitOfWork::class)] final class NumbersSubtractedHandler { /** diff --git a/tests/Integration/Application/Bus/SubtractQuery.php b/tests/Integration/Bus/SubtractQuery.php similarity index 73% rename from tests/Integration/Application/Bus/SubtractQuery.php rename to tests/Integration/Bus/SubtractQuery.php index 9983742c..c76b4f39 100644 --- a/tests/Integration/Application/Bus/SubtractQuery.php +++ b/tests/Integration/Bus/SubtractQuery.php @@ -10,9 +10,9 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query; final readonly class SubtractQuery implements Query { diff --git a/tests/Integration/Application/Bus/SubtractQueryHandler.php b/tests/Integration/Bus/SubtractQueryHandler.php similarity index 89% rename from tests/Integration/Application/Bus/SubtractQueryHandler.php rename to tests/Integration/Bus/SubtractQueryHandler.php index 138b37a8..fe4ce8fe 100644 --- a/tests/Integration/Application/Bus/SubtractQueryHandler.php +++ b/tests/Integration/Bus/SubtractQueryHandler.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Integration\Application\Bus; +namespace CloudCreativity\Modules\Tests\Integration\Bus; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/tests/Integration/Infrastructure/OutboundEventBus/MathEventPublisher.php b/tests/Integration/Infrastructure/OutboundEventBus/MathEventPublisher.php index 7fa6d566..c2ff62eb 100644 --- a/tests/Integration/Infrastructure/OutboundEventBus/MathEventPublisher.php +++ b/tests/Integration/Infrastructure/OutboundEventBus/MathEventPublisher.php @@ -13,11 +13,11 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\OutboundEventBus; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\ComponentPublisher; +use CloudCreativity\Modules\Infrastructure\OutboundEventBus\DefaultPublisher; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Publishes; -use CloudCreativity\Modules\Infrastructure\OutboundEventBus\DefaultPublisher; -use CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus\NumbersAdded; -use CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus\NumbersSubtracted; +use CloudCreativity\Modules\Tests\Integration\Bus\NumbersAdded; +use CloudCreativity\Modules\Tests\Integration\Bus\NumbersSubtracted; use CloudCreativity\Modules\Toolkit\Pipeline\Through; #[DefaultPublisher(TestDefaultPublisher::class)] diff --git a/tests/Integration/Infrastructure/OutboundEventBus/MathEventPublisherTest.php b/tests/Integration/Infrastructure/OutboundEventBus/MathEventPublisherTest.php index 4c7a045a..48793468 100644 --- a/tests/Integration/Infrastructure/OutboundEventBus/MathEventPublisherTest.php +++ b/tests/Integration/Infrastructure/OutboundEventBus/MathEventPublisherTest.php @@ -14,9 +14,9 @@ use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent; use CloudCreativity\Modules\Testing\FakeContainer; -use CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus\NumbersAdded; -use CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus\NumbersDivided; -use CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus\NumbersSubtracted; +use CloudCreativity\Modules\Tests\Integration\Bus\NumbersAdded; +use CloudCreativity\Modules\Tests\Integration\Bus\NumbersDivided; +use CloudCreativity\Modules\Tests\Integration\Bus\NumbersSubtracted; use PHPUnit\Framework\TestCase; class MathEventPublisherTest extends TestCase diff --git a/tests/Integration/Infrastructure/OutboundEventBus/NumbersAddedPublisher.php b/tests/Integration/Infrastructure/OutboundEventBus/NumbersAddedPublisher.php index c3f97a8e..86090d6f 100644 --- a/tests/Integration/Infrastructure/OutboundEventBus/NumbersAddedPublisher.php +++ b/tests/Integration/Infrastructure/OutboundEventBus/NumbersAddedPublisher.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus\NumbersAdded; +use CloudCreativity\Modules\Tests\Integration\Bus\NumbersAdded; final class NumbersAddedPublisher { diff --git a/tests/Integration/Infrastructure/OutboundEventBus/NumbersSubtractedPublisher.php b/tests/Integration/Infrastructure/OutboundEventBus/NumbersSubtractedPublisher.php index f9379a7b..9d86f21c 100644 --- a/tests/Integration/Infrastructure/OutboundEventBus/NumbersSubtractedPublisher.php +++ b/tests/Integration/Infrastructure/OutboundEventBus/NumbersSubtractedPublisher.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus\NumbersSubtracted; +use CloudCreativity\Modules\Tests\Integration\Bus\NumbersSubtracted; final class NumbersSubtractedPublisher { diff --git a/tests/Integration/Infrastructure/OutboundEventBus/TestClosurePublisherTest.php b/tests/Integration/Infrastructure/OutboundEventBus/TestClosurePublisherTest.php index 8d22c9ce..c363dc0b 100644 --- a/tests/Integration/Infrastructure/OutboundEventBus/TestClosurePublisherTest.php +++ b/tests/Integration/Infrastructure/OutboundEventBus/TestClosurePublisherTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent; use CloudCreativity\Modules\Testing\FakeContainer; -use CloudCreativity\Modules\Tests\Integration\Application\InboundEventBus\NumbersAdded; +use CloudCreativity\Modules\Tests\Integration\Bus\NumbersAdded; use PHPUnit\Framework\TestCase; class TestClosurePublisherTest extends TestCase diff --git a/tests/Integration/Infrastructure/OutboundEventBus/TestDefaultPublisher.php b/tests/Integration/Infrastructure/OutboundEventBus/TestDefaultPublisher.php index 36b1a214..2252d2a4 100644 --- a/tests/Integration/Infrastructure/OutboundEventBus/TestDefaultPublisher.php +++ b/tests/Integration/Infrastructure/OutboundEventBus/TestDefaultPublisher.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; final class TestDefaultPublisher { diff --git a/tests/Integration/Infrastructure/Queue/AddCommandEnqueuer.php b/tests/Integration/Infrastructure/Queue/AddCommandEnqueuer.php index 5bb7646b..345db5f1 100644 --- a/tests/Integration/Infrastructure/Queue/AddCommandEnqueuer.php +++ b/tests/Integration/Infrastructure/Queue/AddCommandEnqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\Queue; -use CloudCreativity\Modules\Tests\Integration\Application\Bus\AddCommand; +use CloudCreativity\Modules\Tests\Integration\Bus\AddCommand; final class AddCommandEnqueuer { diff --git a/tests/Integration/Infrastructure/Queue/MathQueue.php b/tests/Integration/Infrastructure/Queue/MathQueue.php index 4cd8fb00..4f59c246 100644 --- a/tests/Integration/Infrastructure/Queue/MathQueue.php +++ b/tests/Integration/Infrastructure/Queue/MathQueue.php @@ -16,8 +16,8 @@ use CloudCreativity\Modules\Infrastructure\Queue\DefaultEnqueuer; use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue; use CloudCreativity\Modules\Infrastructure\Queue\Queues; -use CloudCreativity\Modules\Tests\Integration\Application\Bus\AddCommand; -use CloudCreativity\Modules\Tests\Integration\Application\Bus\MultiplyCommand; +use CloudCreativity\Modules\Tests\Integration\Bus\AddCommand; +use CloudCreativity\Modules\Tests\Integration\Bus\MultiplyCommand; use CloudCreativity\Modules\Toolkit\Pipeline\Through; #[DefaultEnqueuer(TestDefaultEnqueuer::class)] diff --git a/tests/Integration/Infrastructure/Queue/MathQueueTest.php b/tests/Integration/Infrastructure/Queue/MathQueueTest.php index 8b74c466..a8d8b3df 100644 --- a/tests/Integration/Infrastructure/Queue/MathQueueTest.php +++ b/tests/Integration/Infrastructure/Queue/MathQueueTest.php @@ -14,9 +14,9 @@ use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue; use CloudCreativity\Modules\Testing\FakeContainer; -use CloudCreativity\Modules\Tests\Integration\Application\Bus\AddCommand; -use CloudCreativity\Modules\Tests\Integration\Application\Bus\FloorCommand; -use CloudCreativity\Modules\Tests\Integration\Application\Bus\MultiplyCommand; +use CloudCreativity\Modules\Tests\Integration\Bus\AddCommand; +use CloudCreativity\Modules\Tests\Integration\Bus\FloorCommand; +use CloudCreativity\Modules\Tests\Integration\Bus\MultiplyCommand; use PHPUnit\Framework\TestCase; class MathQueueTest extends TestCase diff --git a/tests/Integration/Infrastructure/Queue/MultiplyCommandEnqueuer.php b/tests/Integration/Infrastructure/Queue/MultiplyCommandEnqueuer.php index d2f9ee9d..670ec524 100644 --- a/tests/Integration/Infrastructure/Queue/MultiplyCommandEnqueuer.php +++ b/tests/Integration/Infrastructure/Queue/MultiplyCommandEnqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\Queue; -use CloudCreativity\Modules\Tests\Integration\Application\Bus\MultiplyCommand; +use CloudCreativity\Modules\Tests\Integration\Bus\MultiplyCommand; final class MultiplyCommandEnqueuer { diff --git a/tests/Integration/Infrastructure/Queue/TestClosureQueueTest.php b/tests/Integration/Infrastructure/Queue/TestClosureQueueTest.php index febdcef5..21daf3e4 100644 --- a/tests/Integration/Infrastructure/Queue/TestClosureQueueTest.php +++ b/tests/Integration/Infrastructure/Queue/TestClosureQueueTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue; use CloudCreativity\Modules\Testing\FakeContainer; -use CloudCreativity\Modules\Tests\Integration\Application\Bus\AddCommand; +use CloudCreativity\Modules\Tests\Integration\Bus\AddCommand; use PHPUnit\Framework\TestCase; class TestClosureQueueTest extends TestCase diff --git a/tests/Integration/Infrastructure/Queue/TestDefaultEnqueuer.php b/tests/Integration/Infrastructure/Queue/TestDefaultEnqueuer.php index 6bec9c33..b73ba980 100644 --- a/tests/Integration/Infrastructure/Queue/TestDefaultEnqueuer.php +++ b/tests/Integration/Infrastructure/Queue/TestDefaultEnqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; final class TestDefaultEnqueuer { diff --git a/tests/Unit/Application/Bus/CommandDispatcherTest.php b/tests/Unit/Application/Bus/CommandDispatcherTest.php index 6a0eb804..4e473faa 100644 --- a/tests/Unit/Application/Bus/CommandDispatcherTest.php +++ b/tests/Unit/Application/Bus/CommandDispatcherTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Application\Bus\CommandDispatcher; -use CloudCreativity\Modules\Contracts\Application\Bus\CommandHandler; -use CloudCreativity\Modules\Contracts\Application\Bus\CommandHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Bus\CommandDispatcher; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\CommandHandler; +use CloudCreativity\Modules\Contracts\Bus\CommandHandlerContainer; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Application/Bus/CommandHandlerContainerTest.php b/tests/Unit/Application/Bus/CommandHandlerContainerTest.php index ea99149d..c8ef5f74 100644 --- a/tests/Unit/Application/Bus/CommandHandlerContainerTest.php +++ b/tests/Unit/Application/Bus/CommandHandlerContainerTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Application\ApplicationException; -use CloudCreativity\Modules\Application\Bus\CommandHandler; -use CloudCreativity\Modules\Application\Bus\CommandHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Bus\BusException; +use CloudCreativity\Modules\Bus\CommandHandler; +use CloudCreativity\Modules\Bus\CommandHandlerContainer; +use CloudCreativity\Modules\Contracts\Bus\Command; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -37,7 +37,7 @@ public function testItResolvesUsingClosureBindings(): void $this->assertEquals(new CommandHandler($a), $container->get($command1::class)); $this->assertEquals(new CommandHandler($b), $container->get($command2::class)); - $this->expectException(ApplicationException::class); + $this->expectException(BusException::class); $this->expectExceptionMessage('No command handler bound for command class: ' . $command3::class); $container->get($command3::class); @@ -69,7 +69,7 @@ public function testItResolvesViaPsrContainer(): void $this->assertEquals(new CommandHandler($a), $container->get($command1::class)); $this->assertEquals(new CommandHandler($b), $container->get($command2::class)); - $this->expectException(ApplicationException::class); + $this->expectException(BusException::class); $this->expectExceptionMessage('No command handler bound for command class: ' . $command3::class); $container->get($command3::class); diff --git a/tests/Unit/Application/Bus/CommandHandlerTest.php b/tests/Unit/Application/Bus/CommandHandlerTest.php index 63f9a8c6..cd283093 100644 --- a/tests/Unit/Application/Bus/CommandHandlerTest.php +++ b/tests/Unit/Application/Bus/CommandHandlerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Application\Bus\CommandHandler; +use CloudCreativity\Modules\Bus\CommandHandler; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Application/Bus/CommandQueuerTest.php b/tests/Unit/Application/Bus/CommandQueuerTest.php index 02bc1b8f..06ee712b 100644 --- a/tests/Unit/Application/Bus/CommandQueuerTest.php +++ b/tests/Unit/Application/Bus/CommandQueuerTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; use CloudCreativity\Modules\Application\Bus\CommandQueuer; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Application/Bus/Middleware/ExecuteInUnitOfWorkTest.php b/tests/Unit/Application/Bus/Middleware/ExecuteInUnitOfWorkTest.php index a5ba7c6c..2b578ee8 100644 --- a/tests/Unit/Application/Bus/Middleware/ExecuteInUnitOfWorkTest.php +++ b/tests/Unit/Application/Bus/Middleware/ExecuteInUnitOfWorkTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; use CloudCreativity\Modules\Contracts\Application\UnitOfWork\UnitOfWorkManager; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use Throwable; diff --git a/tests/Unit/Application/Bus/Middleware/FlushDeferredEventsTest.php b/tests/Unit/Application/Bus/Middleware/FlushDeferredEventsTest.php index 4c5c76a3..33c45940 100644 --- a/tests/Unit/Application/Bus/Middleware/FlushDeferredEventsTest.php +++ b/tests/Unit/Application/Bus/Middleware/FlushDeferredEventsTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Application\Bus\Middleware\FlushDeferredEvents; use CloudCreativity\Modules\Contracts\Application\DomainEventDispatching\DeferredDispatcher; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php b/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php index dee1e2f2..5c5ebb4c 100644 --- a/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php @@ -12,11 +12,11 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; -use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Message; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; +use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Toolkit\Result\Result; use LogicException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php b/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php index 6aaf319e..1ed0048e 100644 --- a/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php @@ -13,9 +13,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Application\Bus\Middleware\SetupBeforeDispatch; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Bus\Middleware\SetupBeforeDispatch; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php b/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php index 8e9c6e44..45c428e3 100644 --- a/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; -use CloudCreativity\Modules\Application\Bus\Middleware\TearDownAfterDispatch; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Bus\Middleware\TearDownAfterDispatch; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php b/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php index f22c1357..e0abf7a3 100644 --- a/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php +++ b/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; -use CloudCreativity\Modules\Application\Bus\Middleware\ValidateCommand; -use CloudCreativity\Modules\Contracts\Application\Bus\Bail; -use CloudCreativity\Modules\Contracts\Application\Bus\Validator; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Bus\Middleware\ValidateCommand; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; +use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php b/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php index 36ecb45c..fffc0cdc 100644 --- a/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php +++ b/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; -use CloudCreativity\Modules\Application\Bus\Middleware\ValidateQuery; -use CloudCreativity\Modules\Contracts\Application\Bus\Bail; -use CloudCreativity\Modules\Contracts\Application\Bus\Validator; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Bus\Middleware\ValidateQuery; +use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; +use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/Bus/QueryDispatcherTest.php b/tests/Unit/Application/Bus/QueryDispatcherTest.php index 88a093bd..f908e102 100644 --- a/tests/Unit/Application/Bus/QueryDispatcherTest.php +++ b/tests/Unit/Application/Bus/QueryDispatcherTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Application\Bus\QueryDispatcher; -use CloudCreativity\Modules\Contracts\Application\Bus\QueryHandler; -use CloudCreativity\Modules\Contracts\Application\Bus\QueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Bus\QueryDispatcher; +use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Bus\QueryHandler; +use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Application/Bus/QueryHandlerContainerTest.php b/tests/Unit/Application/Bus/QueryHandlerContainerTest.php index 45ad402a..b79f26ad 100644 --- a/tests/Unit/Application/Bus/QueryHandlerContainerTest.php +++ b/tests/Unit/Application/Bus/QueryHandlerContainerTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Application\ApplicationException; -use CloudCreativity\Modules\Application\Bus\QueryHandler; -use CloudCreativity\Modules\Application\Bus\QueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Bus\BusException; +use CloudCreativity\Modules\Bus\QueryHandler; +use CloudCreativity\Modules\Bus\QueryHandlerContainer; +use CloudCreativity\Modules\Contracts\Bus\Query; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -37,7 +37,7 @@ public function testItResolvesClosureBindings(): void $this->assertEquals(new QueryHandler($a), $container->get($query1::class)); $this->assertEquals(new QueryHandler($b), $container->get($query2::class)); - $this->expectException(ApplicationException::class); + $this->expectException(BusException::class); $this->expectExceptionMessage('No query handler bound for query class: ' . $query3::class); $container->get($query3::class); @@ -69,7 +69,7 @@ public function testItResolvesViaPsrContainer(): void $this->assertEquals(new QueryHandler($a), $container->get($query1::class)); $this->assertEquals(new QueryHandler($b), $container->get($query2::class)); - $this->expectException(ApplicationException::class); + $this->expectException(BusException::class); $this->expectExceptionMessage('No query handler bound for query class: ' . $query3::class); $container->get($query3::class); diff --git a/tests/Unit/Application/Bus/QueryHandlerTest.php b/tests/Unit/Application/Bus/QueryHandlerTest.php index 1c189ab4..d7fdb820 100644 --- a/tests/Unit/Application/Bus/QueryHandlerTest.php +++ b/tests/Unit/Application/Bus/QueryHandlerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Application\Bus\QueryHandler; +use CloudCreativity\Modules\Bus\QueryHandler; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Application/Bus/TestCommand.php b/tests/Unit/Application/Bus/TestCommand.php index 845d514f..90470023 100644 --- a/tests/Unit/Application/Bus/TestCommand.php +++ b/tests/Unit/Application/Bus/TestCommand.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; class TestCommand implements Command { diff --git a/tests/Unit/Application/Bus/TestCommandHandler.php b/tests/Unit/Application/Bus/TestCommandHandler.php index ab6cefbe..f5bc76c2 100644 --- a/tests/Unit/Application/Bus/TestCommandHandler.php +++ b/tests/Unit/Application/Bus/TestCommandHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; +use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware; use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/tests/Unit/Application/Bus/TestQuery.php b/tests/Unit/Application/Bus/TestQuery.php index 72fc40c2..7c0e6f50 100644 --- a/tests/Unit/Application/Bus/TestQuery.php +++ b/tests/Unit/Application/Bus/TestQuery.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Contracts\Bus\Query; class TestQuery implements Query { diff --git a/tests/Unit/Application/Bus/TestQueryHandler.php b/tests/Unit/Application/Bus/TestQueryHandler.php index c11ab681..8a7e98ee 100644 --- a/tests/Unit/Application/Bus/TestQueryHandler.php +++ b/tests/Unit/Application/Bus/TestQueryHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; +use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware; use CloudCreativity\Modules\Toolkit\Result\Result; class TestQueryHandler implements DispatchThroughMiddleware diff --git a/tests/Unit/Application/Bus/ValidatorTest.php b/tests/Unit/Application/Bus/ValidatorTest.php index e8d8c1d8..7eefcf0d 100644 --- a/tests/Unit/Application/Bus/ValidatorTest.php +++ b/tests/Unit/Application/Bus/ValidatorTest.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Application\Bus\Validator; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query; +use CloudCreativity\Modules\Bus\Validation\Validator; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/InboundEventBus/EventHandlerContainerTest.php b/tests/Unit/Application/InboundEventBus/EventHandlerContainerTest.php index b2ed74d5..1971d13a 100644 --- a/tests/Unit/Application/InboundEventBus/EventHandlerContainerTest.php +++ b/tests/Unit/Application/InboundEventBus/EventHandlerContainerTest.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; -use CloudCreativity\Modules\Application\ApplicationException; -use CloudCreativity\Modules\Application\InboundEventBus\EventHandler; -use CloudCreativity\Modules\Application\InboundEventBus\EventHandlerContainer; +use CloudCreativity\Modules\Bus\BusException; +use CloudCreativity\Modules\Bus\EventHandler; +use CloudCreativity\Modules\Bus\EventHandlerContainer; use CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\TestOutboundEvent; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -94,7 +94,7 @@ public function testItDoesNotHaveHandler(): void $container = new EventHandlerContainer(); $container->bind(TestInboundEvent::class, fn () => new TestEventHandler()); - $this->expectException(ApplicationException::class); + $this->expectException(BusException::class); $this->expectExceptionMessage( 'No handler bound for integration event: ' . TestOutboundEvent::class, ); diff --git a/tests/Unit/Application/InboundEventBus/EventHandlerTest.php b/tests/Unit/Application/InboundEventBus/EventHandlerTest.php index 073d9b5a..3de0d4a0 100644 --- a/tests/Unit/Application/InboundEventBus/EventHandlerTest.php +++ b/tests/Unit/Application/InboundEventBus/EventHandlerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; -use CloudCreativity\Modules\Application\InboundEventBus\EventHandler; +use CloudCreativity\Modules\Bus\EventHandler; use PHPUnit\Framework\TestCase; class EventHandlerTest extends TestCase diff --git a/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php b/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php index d75b8921..df7513e4 100644 --- a/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php +++ b/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; -use CloudCreativity\Modules\Application\InboundEventBus\InboundEventDispatcher; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\EventHandler; -use CloudCreativity\Modules\Contracts\Application\InboundEventBus\EventHandlerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Bus\InboundEventDispatcher; +use CloudCreativity\Modules\Contracts\Bus\EventHandler; +use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/FlushDeferredEventsTest.php b/tests/Unit/Application/InboundEventBus/Middleware/FlushDeferredEventsTest.php deleted file mode 100644 index 9c5e6c53..00000000 --- a/tests/Unit/Application/InboundEventBus/Middleware/FlushDeferredEventsTest.php +++ /dev/null @@ -1,94 +0,0 @@ - - */ - private array $sequence = []; - - protected function setUp(): void - { - parent::setUp(); - - $this->middleware = new FlushDeferredEvents( - $this->dispatcher = $this->createMock(DeferredDispatcher::class), - ); - } - - public function testItFlushesDeferredEvents(): void - { - $event = $this->createMock(IntegrationEvent::class); - - $this->dispatcher - ->expects($this->once()) - ->method('flush') - ->willReturnCallback(function () { - $this->sequence[] = 'flush'; - }); - - $this->dispatcher - ->expects($this->never()) - ->method('forget'); - - ($this->middleware)($event, function ($in) use ($event): void { - $this->assertSame($event, $in); - $this->sequence[] = 'next'; - }); - - $this->assertSame(['next', 'flush'], $this->sequence); - } - - - public function testItForgetsDeferredEventsOnException(): void - { - $event = $this->createMock(IntegrationEvent::class); - $expected = new \LogicException('Boom!'); - - $this->dispatcher - ->expects($this->once()) - ->method('forget') - ->willReturnCallback(function () { - $this->sequence[] = 'forget'; - }); - - $this->dispatcher - ->expects($this->never()) - ->method('flush'); - - try { - ($this->middleware)($event, function ($in) use ($event, $expected): never { - $this->assertSame($event, $in); - $this->sequence[] = 'next'; - throw $expected; - }); - $this->fail('No exception thrown.'); - } catch (\LogicException $ex) { - $this->assertSame($expected, $ex); - } - - $this->assertSame(['next', 'forget'], $this->sequence); - } -} diff --git a/tests/Unit/Application/InboundEventBus/Middleware/HandleInUnitOfWorkTest.php b/tests/Unit/Application/InboundEventBus/Middleware/HandleInUnitOfWorkTest.php deleted file mode 100644 index ededbd52..00000000 --- a/tests/Unit/Application/InboundEventBus/Middleware/HandleInUnitOfWorkTest.php +++ /dev/null @@ -1,91 +0,0 @@ - - */ - private array $sequence = []; - - public function testItCommitsUnitOfWork(): void - { - $event = $this->createMock(IntegrationEvent::class); - - $middleware = new HandleInUnitOfWork( - $transactions = $this->createMock(UnitOfWorkManager::class), - 2, - ); - - $transactions - ->expects($this->once()) - ->method('execute') - ->willReturnCallback(function (\Closure $callback, int $attempts) { - $this->assertSame(2, $attempts); - $this->sequence[] = 'begin'; - $result = $callback(); - $this->sequence[] = 'commit'; - return $result; - }); - - $middleware($event, function ($cmd) use ($event) { - $this->assertSame($event, $cmd); - $this->sequence[] = 'handler'; - }); - - $this->assertSame(['begin', 'handler', 'commit'], $this->sequence); - } - - public function testItDoesNotCatchExceptions(): void - { - $event = $this->createMock(IntegrationEvent::class); - $expected = new \RuntimeException('Boom! Something went wrong.'); - - $middleware = new HandleInUnitOfWork( - $transactions = $this->createMock(UnitOfWorkManager::class), - 2, - ); - - $transactions - ->expects($this->once()) - ->method('execute') - ->willReturnCallback(function (\Closure $callback, int $attempts) { - $this->assertSame(2, $attempts); - $this->sequence[] = 'begin'; - $callback(); - $this->sequence[] = 'commit'; - }); - - $actual = null; - - try { - $middleware($event, function ($cmd) use ($event, $expected): never { - $this->assertSame($event, $cmd); - $this->sequence[] = 'handler'; - throw $expected; - }); - } catch (Throwable $ex) { - $actual = $ex; - } - - $this->assertSame(['begin', 'handler'], $this->sequence); - $this->assertSame($expected, $actual); - } -} diff --git a/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php index a9212bc5..92933593 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus\Middleware; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\LogInboundEvent; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Bus\Loggable\ObjectDecorator; +use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\TestOutboundEvent; -use CloudCreativity\Modules\Toolkit\Loggable\ObjectDecorator; use CloudCreativity\Modules\Toolkit\ModuleBasename; use LogicException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php index ab1b1090..aef9b3c4 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus\Middleware; use Closure; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\SetupBeforeEvent; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Bus\Middleware\SetupBeforeEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php index 84feabec..eb32c9f9 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus\Middleware; -use CloudCreativity\Modules\Application\InboundEventBus\Middleware\TearDownAfterEvent; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Bus\Middleware\TearDownAfterEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/InboundEventBus/SwallowInboundEventTest.php b/tests/Unit/Application/InboundEventBus/SwallowInboundEventTest.php index 56a20193..bb12bdef 100644 --- a/tests/Unit/Application/InboundEventBus/SwallowInboundEventTest.php +++ b/tests/Unit/Application/InboundEventBus/SwallowInboundEventTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; -use CloudCreativity\Modules\Application\InboundEventBus\SwallowInboundEvent; +use CloudCreativity\Modules\Bus\SwallowInboundEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use PHPUnit\Framework\TestCase; use Psr\Log\LoggerInterface; diff --git a/tests/Unit/Application/InboundEventBus/TestEventHandler.php b/tests/Unit/Application/InboundEventBus/TestEventHandler.php index 7e84fa99..0bbbc845 100644 --- a/tests/Unit/Application/InboundEventBus/TestEventHandler.php +++ b/tests/Unit/Application/InboundEventBus/TestEventHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; -use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware; +use CloudCreativity\Modules\Contracts\Bus\DispatchThroughMiddleware; class TestEventHandler implements DispatchThroughMiddleware { diff --git a/tests/Unit/Application/InboundEventBus/TestInboundEvent.php b/tests/Unit/Application/InboundEventBus/TestInboundEvent.php index 4f94cce6..4940f9ab 100644 --- a/tests/Unit/Application/InboundEventBus/TestInboundEvent.php +++ b/tests/Unit/Application/InboundEventBus/TestInboundEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Unit/Application/UnitOfWork/UnitOfWorkManagerTest.php b/tests/Unit/Application/UnitOfWork/UnitOfWorkManagerTest.php index 1d0faf74..401a46bc 100644 --- a/tests/Unit/Application/UnitOfWork/UnitOfWorkManagerTest.php +++ b/tests/Unit/Application/UnitOfWork/UnitOfWorkManagerTest.php @@ -14,8 +14,8 @@ use Closure; use CloudCreativity\Modules\Application\UnitOfWork\UnitOfWorkManager; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\ExceptionReporter; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\UnitOfWork; +use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter; +use CloudCreativity\Modules\Contracts\Application\Ports\UnitOfWork; use LogicException; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Toolkit/Loggable/ObjectDecoratorTest.php b/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php similarity index 92% rename from tests/Unit/Toolkit/Loggable/ObjectDecoratorTest.php rename to tests/Unit/Bus/Loggable/ObjectDecoratorTest.php index e5116aa7..ec429ca5 100644 --- a/tests/Unit/Toolkit/Loggable/ObjectDecoratorTest.php +++ b/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php @@ -10,16 +10,16 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Unit\Toolkit\Loggable; +namespace CloudCreativity\Modules\Tests\Unit\Bus\Loggable; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Message; +use CloudCreativity\Modules\Bus\Loggable\ObjectDecorator; +use CloudCreativity\Modules\Bus\Loggable\Sensitive; +use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; +use CloudCreativity\Modules\Contracts\Bus\Message; use CloudCreativity\Modules\Tests\TestBackedEnum; use CloudCreativity\Modules\Tests\TestBackedIntEnum; use CloudCreativity\Modules\Tests\TestUnitEnum; -use CloudCreativity\Modules\Toolkit\Loggable\ObjectDecorator; -use CloudCreativity\Modules\Toolkit\Loggable\Sensitive; -use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory; use DateTimeImmutable; use DateTimeInterface; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Toolkit/Loggable/ResultDecoratorTest.php b/tests/Unit/Bus/Loggable/ResultDecoratorTest.php similarity index 96% rename from tests/Unit/Toolkit/Loggable/ResultDecoratorTest.php rename to tests/Unit/Bus/Loggable/ResultDecoratorTest.php index 59dcd866..d7b0b498 100644 --- a/tests/Unit/Toolkit/Loggable/ResultDecoratorTest.php +++ b/tests/Unit/Bus/Loggable/ResultDecoratorTest.php @@ -10,18 +10,18 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Tests\Unit\Toolkit\Loggable; +namespace CloudCreativity\Modules\Tests\Unit\Bus\Loggable; use BackedEnum; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\Contextual; +use CloudCreativity\Modules\Bus\Loggable\ResultDecorator; +use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; +use CloudCreativity\Modules\Contracts\Bus\Loggable\Contextual; use CloudCreativity\Modules\Contracts\Toolkit\Result\Error as IError; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Tests\TestBackedEnum; use CloudCreativity\Modules\Tests\TestBackedIntEnum; use CloudCreativity\Modules\Tests\TestUnitEnum; -use CloudCreativity\Modules\Toolkit\Loggable\ResultDecorator; -use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\Attributes\DataProvider; diff --git a/tests/Unit/Bus/PsrPipeContainerTest.php b/tests/Unit/Bus/PsrPipeContainerTest.php new file mode 100644 index 00000000..89cc2108 --- /dev/null +++ b/tests/Unit/Bus/PsrPipeContainerTest.php @@ -0,0 +1,61 @@ + 1; + $b = fn () => 2; + + $container = new PsrPipeContainer(); + $container->bind('PipeA', fn () => $a); + $container->bind('PipeB', fn () => $b); + + $this->assertSame($a, $container->get('PipeA')); + $this->assertSame($b, $container->get('PipeB')); + + $this->expectException(\RuntimeException::class); + $this->expectExceptionMessage('Unrecognised pipe name: PipeC'); + + $container->get('PipeC'); + } + + public function testItFallsBackToPsrContainer(): void + { + $psrContainer = $this->createMock(ContainerInterface::class); + + $a = fn () => 1; + $b = fn () => 2; + $c = fn () => 3; + + $container = new PsrPipeContainer($psrContainer); + $container->bind('PipeA', fn () => $a); + $container->bind('PipeB', fn () => $b); + + $psrContainer + ->expects($this->once()) + ->method('get') + ->with('PipeC') + ->willReturn($c); + + $this->assertSame($a, $container->get('PipeA')); + $this->assertSame($b, $container->get('PipeB')); + $this->assertSame($c, $container->get('PipeC')); + } +} diff --git a/tests/Unit/Infrastructure/ExceptionReporter/PsrLogExceptionReporterTest.php b/tests/Unit/Infrastructure/ExceptionReporter/PsrLogExceptionReporterTest.php index af3506fa..179b29e7 100644 --- a/tests/Unit/Infrastructure/ExceptionReporter/PsrLogExceptionReporterTest.php +++ b/tests/Unit/Infrastructure/ExceptionReporter/PsrLogExceptionReporterTest.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\ExceptionReporter; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\ExceptionReporter; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; +use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; use CloudCreativity\Modules\Infrastructure\ExceptionReporter\PsrLogExceptionReporter; use LogicException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php b/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php index 5973fab0..1045292e 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\ClosurePublisher; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php b/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php index 5021e512..45a7bb01 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php @@ -12,10 +12,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\Middleware; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Bus\Loggable\ObjectDecorator; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent; use CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\TestOutboundEvent; -use CloudCreativity\Modules\Toolkit\Loggable\ObjectDecorator; use CloudCreativity\Modules\Toolkit\ModuleBasename; use LogicException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php b/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php index ca8ad198..48e2bd20 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php b/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php index ca6a7eb2..92fd286e 100644 --- a/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Infrastructure\Queue\ClosureQueue; use CloudCreativity\Modules\Tests\Unit\Application\Bus\TestCommand; diff --git a/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php b/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php index 35de6222..f960e4aa 100644 --- a/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\Enqueuer; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\EnqueuerContainer; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Infrastructure\Queue\ComponentQueue; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php b/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php index 0b67a36c..dcf6db20 100644 --- a/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php +++ b/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Infrastructure\Queue\Enqueuer; use CloudCreativity\Modules\Infrastructure\Queue\EnqueuerContainer; use CloudCreativity\Modules\Tests\Unit\Application\Bus\TestCommand; diff --git a/tests/Unit/Infrastructure/Queue/EnqueuerTest.php b/tests/Unit/Infrastructure/Queue/EnqueuerTest.php index 3768cee6..78f25f9d 100644 --- a/tests/Unit/Infrastructure/Queue/EnqueuerTest.php +++ b/tests/Unit/Infrastructure/Queue/EnqueuerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Infrastructure\Queue\Enqueuer; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php b/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php index b4f864a1..752336a1 100644 --- a/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue\Middleware; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue; use LogicException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Infrastructure/Queue/TestEnqueuer.php b/tests/Unit/Infrastructure/Queue/TestEnqueuer.php index 3a172302..3ad676c2 100644 --- a/tests/Unit/Infrastructure/Queue/TestEnqueuer.php +++ b/tests/Unit/Infrastructure/Queue/TestEnqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Bus\Command; class TestEnqueuer { diff --git a/tests/Unit/Testing/FakeExceptionReporterTest.php b/tests/Unit/Testing/FakeExceptionReporterTest.php index 69c6fd96..3848d88a 100644 --- a/tests/Unit/Testing/FakeExceptionReporterTest.php +++ b/tests/Unit/Testing/FakeExceptionReporterTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Testing; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\ExceptionReporter; +use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter; use CloudCreativity\Modules\Testing\FakeExceptionReporter; use LogicException; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Testing/FakeOutboundEventPublisherTest.php b/tests/Unit/Testing/FakeOutboundEventPublisherTest.php index beaf2cd7..1f28f697 100644 --- a/tests/Unit/Testing/FakeOutboundEventPublisherTest.php +++ b/tests/Unit/Testing/FakeOutboundEventPublisherTest.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Testing; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\OutboundEventPublisher; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; +use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Testing\FakeOutboundEventPublisher; use LogicException; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Testing/FakeQueueTest.php b/tests/Unit/Testing/FakeQueueTest.php index 8d876c7b..71e04259 100644 --- a/tests/Unit/Testing/FakeQueueTest.php +++ b/tests/Unit/Testing/FakeQueueTest.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Testing; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command; +use CloudCreativity\Modules\Contracts\Application\Ports\Queue; +use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Testing\FakeQueue; use LogicException; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Testing/FakeUnitOfWorkTest.php b/tests/Unit/Testing/FakeUnitOfWorkTest.php index e291ccdf..e09c1cef 100644 --- a/tests/Unit/Testing/FakeUnitOfWorkTest.php +++ b/tests/Unit/Testing/FakeUnitOfWorkTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Testing; -use CloudCreativity\Modules\Contracts\Application\Ports\Driven\UnitOfWork; +use CloudCreativity\Modules\Contracts\Application\Ports\UnitOfWork; use CloudCreativity\Modules\Testing\FakeUnitOfWork; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Toolkit/Pipeline/PipeContainerTest.php b/tests/Unit/Toolkit/Pipeline/PipeContainerTest.php index 85fc054d..2ff58ec3 100644 --- a/tests/Unit/Toolkit/Pipeline/PipeContainerTest.php +++ b/tests/Unit/Toolkit/Pipeline/PipeContainerTest.php @@ -14,7 +14,6 @@ use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; use PHPUnit\Framework\TestCase; -use Psr\Container\ContainerInterface; class PipeContainerTest extends TestCase { @@ -35,27 +34,4 @@ public function testItResolvesBoundPipes(): void $container->get('PipeC'); } - - public function testItFallsBackToPsrContainer(): void - { - $psrContainer = $this->createMock(ContainerInterface::class); - - $a = fn () => 1; - $b = fn () => 2; - $c = fn () => 3; - - $container = new PipeContainer($psrContainer); - $container->bind('PipeA', fn () => $a); - $container->bind('PipeB', fn () => $b); - - $psrContainer - ->expects($this->once()) - ->method('get') - ->with('PipeC') - ->willReturn($c); - - $this->assertSame($a, $container->get('PipeA')); - $this->assertSame($b, $container->get('PipeB')); - $this->assertSame($c, $container->get('PipeC')); - } } diff --git a/tests/Unit/Toolkit/Result/FailedResultExceptionTest.php b/tests/Unit/Toolkit/Result/FailedResultExceptionTest.php index 41cdf4c5..8e03049d 100644 --- a/tests/Unit/Toolkit/Result/FailedResultExceptionTest.php +++ b/tests/Unit/Toolkit/Result/FailedResultExceptionTest.php @@ -12,9 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Toolkit\Result; -use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider; use CloudCreativity\Modules\Tests\TestUnitEnum; -use CloudCreativity\Modules\Toolkit\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Toolkit\Result\FailedResultException; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; @@ -30,8 +28,6 @@ public function testItFailsWithMessage(): void $this->assertSame($result, $exception->getResult()); $this->assertSame('Something went wrong.', $exception->getMessage()); - $this->assertInstanceOf(ContextProvider::class, $exception); - $this->assertSame((new SimpleContextFactory())->make($result), $exception->context()); } public function testItFailsWithErrorCode(): void From f9dcc102d8e3b7d29934020c2f7faad8c5c0f282 Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Thu, 1 Jan 2026 22:07:40 +0000 Subject: [PATCH 2/8] wip: move messages to specific contract namespace --- deptrac.yaml | 11 ++++++++++- docs/guide/application/commands.md | 10 +++++----- docs/guide/application/integration-events.md | 16 ++++++++-------- docs/guide/application/queries.md | 8 ++++---- docs/guide/infrastructure/outbox.md | 2 +- docs/guide/infrastructure/publishing-events.md | 6 +++--- docs/guide/infrastructure/queues.md | 10 +++++----- src/Application/Bus/CommandQueuer.php | 2 +- .../Bus/Middleware/ExecuteInUnitOfWork.php | 2 +- .../Bus/Middleware/FlushDeferredEvents.php | 2 +- src/Bus/CommandDispatcher.php | 4 ++-- src/Bus/CommandHandler.php | 2 +- src/Bus/CommandHandlerContainer.php | 2 +- src/Bus/EventHandler.php | 2 +- src/Bus/EventHandlerContainer.php | 2 +- src/Bus/InboundEventDispatcher.php | 4 ++-- src/Bus/Loggable/SimpleContextFactory.php | 2 +- src/Bus/Middleware/LogInboundEvent.php | 2 +- src/Bus/Middleware/LogMessageDispatch.php | 4 ++-- src/Bus/Middleware/SetupBeforeDispatch.php | 2 +- src/Bus/Middleware/SetupBeforeEvent.php | 2 +- src/Bus/Middleware/TearDownAfterDispatch.php | 2 +- src/Bus/Middleware/TearDownAfterEvent.php | 2 +- src/Bus/Middleware/ValidateCommand.php | 2 +- src/Bus/Middleware/ValidateQuery.php | 2 +- src/Bus/QueryDispatcher.php | 4 ++-- src/Bus/QueryHandler.php | 2 +- src/Bus/QueryHandlerContainer.php | 2 +- src/Bus/SwallowInboundEvent.php | 2 +- src/Bus/Validation/ValidationProcessor.php | 4 ++-- src/Bus/Validation/Validator.php | 4 ++-- src/Bus/WithCommand.php | 2 +- src/Bus/WithEvent.php | 2 +- src/Bus/WithQuery.php | 2 +- .../Application/Ports/OutboundEventPublisher.php | 2 +- src/Contracts/Application/Ports/Queue.php | 2 +- src/Contracts/Bus/CommandHandler.php | 1 + src/Contracts/Bus/CommandHandlerContainer.php | 2 ++ src/Contracts/Bus/CommandQueuer.php | 2 ++ src/Contracts/Bus/EventHandler.php | 2 ++ src/Contracts/Bus/EventHandlerContainer.php | 2 ++ src/Contracts/Bus/Loggable/ContextFactory.php | 2 +- src/Contracts/Bus/Middleware/BusMiddleware.php | 2 +- .../Bus/Middleware/CommandMiddleware.php | 2 +- .../Bus/Middleware/InboundEventMiddleware.php | 2 +- src/Contracts/Bus/Middleware/QueryMiddleware.php | 2 +- src/Contracts/Bus/QueryHandler.php | 1 + src/Contracts/Bus/QueryHandlerContainer.php | 2 ++ src/Contracts/Bus/Validation/Validator.php | 4 ++-- .../OutboundEventBus/OutboundEventMiddleware.php | 2 +- .../OutboundEventBus/PublisherHandler.php | 2 +- .../PublisherHandlerContainer.php | 2 +- src/Contracts/Infrastructure/Queue/Enqueuer.php | 2 +- .../Infrastructure/Queue/EnqueuerContainer.php | 2 +- .../Infrastructure/Queue/QueueMiddleware.php | 2 +- src/Contracts/{Bus => Messages}/Command.php | 2 +- .../{Bus => Messages}/CommandDispatcher.php | 2 +- .../{Bus => Messages}/InboundEventDispatcher.php | 2 +- .../{Bus => Messages}/IntegrationEvent.php | 2 +- src/Contracts/{Bus => Messages}/Message.php | 2 +- src/Contracts/{Bus => Messages}/Query.php | 2 +- .../{Bus => Messages}/QueryDispatcher.php | 2 +- .../OutboundEventBus/ClosurePublisher.php | 2 +- .../OutboundEventBus/ComponentPublisher.php | 2 +- .../Middleware/LogOutboundEvent.php | 2 +- .../OutboundEventBus/PublisherHandler.php | 2 +- .../PublisherHandlerContainer.php | 2 +- .../OutboundEventBus/Publishes.php | 2 +- src/Infrastructure/Queue/ClosureQueue.php | 2 +- src/Infrastructure/Queue/ComponentQueue.php | 2 +- src/Infrastructure/Queue/Enqueuer.php | 2 +- src/Infrastructure/Queue/EnqueuerContainer.php | 2 +- .../Queue/Middleware/LogPushedToQueue.php | 2 +- src/Infrastructure/Queue/Queues.php | 2 +- src/Testing/FakeOutboundEventPublisher.php | 2 +- src/Testing/FakeQueue.php | 2 +- tests/Integration/Bus/AddCommand.php | 2 +- tests/Integration/Bus/DefaultEventHandler.php | 2 +- tests/Integration/Bus/DivideQuery.php | 2 +- tests/Integration/Bus/FloorCommand.php | 2 +- tests/Integration/Bus/MultiplyCommand.php | 2 +- tests/Integration/Bus/NumbersAdded.php | 2 +- tests/Integration/Bus/NumbersDivided.php | 2 +- tests/Integration/Bus/NumbersSubtracted.php | 2 +- tests/Integration/Bus/SubtractQuery.php | 2 +- .../OutboundEventBus/TestDefaultPublisher.php | 2 +- .../Infrastructure/Queue/TestDefaultEnqueuer.php | 2 +- .../Application/Bus/CommandDispatcherTest.php | 2 +- .../Bus/CommandHandlerContainerTest.php | 2 +- .../Bus/Middleware/ExecuteInUnitOfWorkTest.php | 2 +- .../Bus/Middleware/FlushDeferredEventsTest.php | 2 +- .../Bus/Middleware/LogMessageDispatchTest.php | 6 +++--- .../Bus/Middleware/SetupBeforeDispatchTest.php | 4 ++-- .../Bus/Middleware/TearDownAfterDispatchTest.php | 4 ++-- .../Bus/Middleware/ValidateCommandTest.php | 2 +- .../Bus/Middleware/ValidateQueryTest.php | 2 +- .../Unit/Application/Bus/QueryDispatcherTest.php | 2 +- .../Bus/QueryHandlerContainerTest.php | 2 +- tests/Unit/Application/Bus/TestCommand.php | 2 +- tests/Unit/Application/Bus/TestQuery.php | 2 +- tests/Unit/Application/Bus/ValidatorTest.php | 4 ++-- .../InboundEventDispatcherTest.php | 2 +- .../Middleware/LogInboundEventTest.php | 2 +- .../Middleware/SetupBeforeEventTest.php | 2 +- .../Middleware/TearDownAfterEventTest.php | 2 +- .../InboundEventBus/TestInboundEvent.php | 2 +- tests/Unit/Bus/Loggable/ObjectDecoratorTest.php | 2 +- .../OutboundEventBus/ClosurePublisherTest.php | 2 +- .../Middleware/LogOutboundEventTest.php | 2 +- .../OutboundEventBus/TestOutboundEvent.php | 2 +- .../Infrastructure/Queue/ClosureQueueTest.php | 2 +- .../Infrastructure/Queue/ComponentQueueTest.php | 2 +- .../Queue/EnqueuerContainerTest.php | 2 +- tests/Unit/Infrastructure/Queue/EnqueuerTest.php | 2 +- .../Queue/Middleware/LogPushedToQueueTest.php | 2 +- tests/Unit/Infrastructure/Queue/TestEnqueuer.php | 2 +- .../Testing/FakeOutboundEventPublisherTest.php | 2 +- tests/Unit/Testing/FakeQueueTest.php | 2 +- 118 files changed, 164 insertions(+), 143 deletions(-) rename src/Contracts/{Bus => Messages}/Command.php (83%) rename src/Contracts/{Bus => Messages}/CommandDispatcher.php (89%) rename src/Contracts/{Bus => Messages}/InboundEventDispatcher.php (88%) rename src/Contracts/{Bus => Messages}/IntegrationEvent.php (89%) rename src/Contracts/{Bus => Messages}/Message.php (82%) rename src/Contracts/{Bus => Messages}/Query.php (83%) rename src/Contracts/{Bus => Messages}/QueryDispatcher.php (89%) diff --git a/deptrac.yaml b/deptrac.yaml index a5935b43..f6034981 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -26,6 +26,10 @@ deptrac: value: CloudCreativity\\Modules\\Contracts\\Infrastructure\\* - type: classLike value: CloudCreativity\\Modules\\Infrastructure\\* + - name: Messages + collectors: + - type: classLike + value: CloudCreativity\\Modules\\Contracts\\Messages\\* - name: PSR Container collectors: - type: classLike @@ -48,19 +52,24 @@ deptrac: Application: - Bus - Domain + - Messages - PSR Container - PSR Log - Toolkit Bus: + - Messages - PSR Container - PSR Log - Toolkit Domain: - Toolkit Infrastructure: - - Bus - Application + - Bus + - Messages - PSR Container - PSR Log - Toolkit + Messages: + - Toolkit Toolkit: diff --git a/docs/guide/application/commands.md b/docs/guide/application/commands.md index dbbfc3d2..6118ffa5 100644 --- a/docs/guide/application/commands.md +++ b/docs/guide/application/commands.md @@ -18,7 +18,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\UseCases\Commands\CancelAttendeeTicket; -use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; +use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; final readonly class CancelAttendeeTicketCommand implements Command { @@ -602,7 +602,7 @@ However, there may be scenarios where a property should not be logged, e.g. beca In this scenario, use the `Sensitive` attribute on the property, and it will not be logged: ```php -use CloudCreativity\Modules\Bus\Loggable\Sensitive;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Bus\Loggable\Sensitive;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class CancelAttendeeTicketCommand implements Command { @@ -618,7 +618,7 @@ final readonly class CancelAttendeeTicketCommand implements Command If you need full control over the log context, implement the `ContextProvider` interface on your command message: ```php -use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class CancelAttendeeTicketCommand implements Command, @@ -648,7 +648,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class MyMiddleware implements CommandMiddleware { @@ -687,7 +687,7 @@ instead: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Bus\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Messages\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; class MyBusMiddleware implements BusMiddleware { diff --git a/docs/guide/application/integration-events.md b/docs/guide/application/integration-events.md index 6cb3257d..19a3d458 100644 --- a/docs/guide/application/integration-events.md +++ b/docs/guide/application/integration-events.md @@ -36,7 +36,7 @@ For example: ```php namespace VendorName\EventManagement\Shared\IntegrationEvents\V1; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use CloudCreativity\Modules\Toolkit\Identifiers\Uuid;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use CloudCreativity\Modules\Toolkit\Identifiers\Uuid;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; final readonly class AttendeeTicketWasCancelled implements IntegrationEvent @@ -94,7 +94,7 @@ This can be expressed via an interface. To illustrate the point, a JSON serializ ```php namespace VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface JsonSerializer { @@ -396,7 +396,7 @@ We do this by defining an interface in our application's driving ports: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Bus\InboundEventDispatcher; +use CloudCreativity\Modules\Contracts\Messages\InboundEventDispatcher; interface InboundEventBus extends InboundEventDispatcher { @@ -523,7 +523,7 @@ Here is an example controller from a Laravel application to demonstrate the patt ```php namespace App\Http\Controllers\Api\PubSub; -use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; +use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; class InboundEventController extends Controller { @@ -627,7 +627,7 @@ example: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface Inbox { @@ -642,7 +642,7 @@ might look like this: ```php namespace App\Modules\EventManagement\Application\Ports\Driven\Inbox; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface InboxRepository { @@ -661,7 +661,7 @@ This means we can now update the previous controller example to use the inbox in ```php namespace App\Http\Controllers\Api\PubSub; -use App\Modules\EventManagement\Application\Ports\Driving\InboundEvents\Inbox;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; +use App\Modules\EventManagement\Application\Ports\Driving\InboundEvents\Inbox;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; class InboundEventController extends Controller { @@ -865,7 +865,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; final class MyMiddleware implements InboundEventMiddleware { diff --git a/docs/guide/application/queries.md b/docs/guide/application/queries.md index 6a5bbc11..527a7cd1 100644 --- a/docs/guide/application/queries.md +++ b/docs/guide/application/queries.md @@ -18,7 +18,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\UseCases\Queries\GetAttendeeTickets; -use CloudCreativity\Modules\Contracts\Bus\Query;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Messages\Query;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class GetAttendeeTicketsQuery implements Query { @@ -105,7 +105,7 @@ We do this by defining an interface in our application's driving ports: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Bus\QueryDispatcher; +use CloudCreativity\Modules\Contracts\Messages\QueryDispatcher; interface QueryBus extends QueryDispatcher { @@ -391,7 +391,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\QueryMiddleware;use CloudCreativity\Modules\Contracts\Bus\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\QueryMiddleware;use CloudCreativity\Modules\Contracts\Messages\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class MyMiddleware implements QueryMiddleware { @@ -430,7 +430,7 @@ instead: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Bus\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Messages\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; class MyBusMiddleware implements BusMiddleware { diff --git a/docs/guide/infrastructure/outbox.md b/docs/guide/infrastructure/outbox.md index d6d9ac49..019091da 100644 --- a/docs/guide/infrastructure/outbox.md +++ b/docs/guide/infrastructure/outbox.md @@ -62,7 +62,7 @@ Our recommended approach is to first place these events into an outbox. This mea ```php namespace App\Modules\EventManagement\Application\Ports\Driven\OutboundEvents; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface Outbox { diff --git a/docs/guide/infrastructure/publishing-events.md b/docs/guide/infrastructure/publishing-events.md index 363f7469..2eda4bc9 100644 --- a/docs/guide/infrastructure/publishing-events.md +++ b/docs/guide/infrastructure/publishing-events.md @@ -61,7 +61,7 @@ specific closures to specific events, and add middleware to the publisher. Here' ```php namespace App\Modules\EventManagement\Infrastructure\OutboundEventBus; -use App\Modules\EventManagement\Application\Ports\Driven\OutboundEventBus\OutboundEventBus;use App\Modules\EventManagement\Infrastructure\GooglePubSub\EventSerializer;use App\Modules\EventManagement\Infrastructure\GooglePubSub\SecureTopicFactory;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;use Psr\Log\LoggerInterface;use VendorName\EventManagement\Shared\IntegrationEvents\V1\AttendeeTicketWasCancelled; +use App\Modules\EventManagement\Application\Ports\Driven\OutboundEventBus\OutboundEventBus;use App\Modules\EventManagement\Infrastructure\GooglePubSub\EventSerializer;use App\Modules\EventManagement\Infrastructure\GooglePubSub\SecureTopicFactory;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent;use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;use Psr\Log\LoggerInterface;use VendorName\EventManagement\Shared\IntegrationEvents\V1\AttendeeTicketWasCancelled; final readonly class OutboundEventBusAdapterProvider { @@ -255,7 +255,7 @@ implement the following interface that was extended by the driven port: ```php namespace CloudCreativity\Modules\Application\Ports\Driven\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface EventPublisher { @@ -313,7 +313,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Adapters\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent;use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware; +use Closure;use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; final class MyMiddleware implements OutboundEventMiddleware { diff --git a/docs/guide/infrastructure/queues.md b/docs/guide/infrastructure/queues.md index 1f1580b4..a6c24a05 100644 --- a/docs/guide/infrastructure/queues.md +++ b/docs/guide/infrastructure/queues.md @@ -79,7 +79,7 @@ Then you can create the adapter by providing it with the default closure for que ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use App\Modules\EventManagement\Application\Ports\Driven\Queue\Queue;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; +use App\Modules\EventManagement\Application\Ports\Driven\Queue\Queue;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; final class QueueAdapterProvider { @@ -217,7 +217,7 @@ example: ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; final class DefaultEnqueuer { @@ -244,7 +244,7 @@ implements the port interface that is extended in your application layer: ```php namespace CloudCreativity\Modules\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; interface Queue { @@ -279,7 +279,7 @@ For example, a default Laravel job for queuing and dispatching commands would be ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use App\Modules\EventManagement\Application\Ports\Driving\CommandBus;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Toolkit\Result\FailedResultException;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue; +use App\Modules\EventManagement\Application\Ports\Driving\CommandBus;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Toolkit\Result\FailedResultException;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue; class DispatchCommandJob implements ShouldQueue { @@ -454,7 +454,7 @@ following signature: ```php namespace App\Modules\Shared\Infrastructure\Queue\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Command;use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware; +use Closure;use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware;use CloudCreativity\Modules\Contracts\Messages\Command; final class MyQueueMiddleware implements QueueMiddleware { diff --git a/src/Application/Bus/CommandQueuer.php b/src/Application/Bus/CommandQueuer.php index 2fed242c..e645d55b 100644 --- a/src/Application/Bus/CommandQueuer.php +++ b/src/Application/Bus/CommandQueuer.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Application\Bus; use CloudCreativity\Modules\Contracts\Application\Ports\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\CommandQueuer as ICommandQueuer; +use CloudCreativity\Modules\Contracts\Messages\Command; class CommandQueuer implements ICommandQueuer { diff --git a/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php b/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php index acaf17cf..8c0b91eb 100644 --- a/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php +++ b/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php @@ -15,8 +15,8 @@ use Closure; use CloudCreativity\Modules\Application\Bus\AbortOnFailureException; use CloudCreativity\Modules\Contracts\Application\UnitOfWork\UnitOfWorkManager; -use CloudCreativity\Modules\Contracts\Bus\Message; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class ExecuteInUnitOfWork implements BusMiddleware diff --git a/src/Application/Bus/Middleware/FlushDeferredEvents.php b/src/Application/Bus/Middleware/FlushDeferredEvents.php index a32ecd62..b2c1e88b 100644 --- a/src/Application/Bus/Middleware/FlushDeferredEvents.php +++ b/src/Application/Bus/Middleware/FlushDeferredEvents.php @@ -14,8 +14,8 @@ use Closure; use CloudCreativity\Modules\Contracts\Application\DomainEventDispatching\DeferredDispatcher; -use CloudCreativity\Modules\Contracts\Bus\Message; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use Throwable; diff --git a/src/Bus/CommandDispatcher.php b/src/Bus/CommandDispatcher.php index 5ef4e6e3..45a4ab70 100644 --- a/src/Bus/CommandDispatcher.php +++ b/src/Bus/CommandDispatcher.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Bus\Command; -use CloudCreativity\Modules\Contracts\Bus\CommandDispatcher as ICommandDispatcher; use CloudCreativity\Modules\Contracts\Bus\CommandHandlerContainer as ICommandHandlerContainer; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\CommandDispatcher as ICommandDispatcher; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; diff --git a/src/Bus/CommandHandler.php b/src/Bus/CommandHandler.php index 6f2f6e5c..58e87c2b 100644 --- a/src/Bus/CommandHandler.php +++ b/src/Bus/CommandHandler.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\CommandHandler as ICommandHandler; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class CommandHandler implements ICommandHandler diff --git a/src/Bus/CommandHandlerContainer.php b/src/Bus/CommandHandlerContainer.php index eff9a3fa..28c3b09c 100644 --- a/src/Bus/CommandHandlerContainer.php +++ b/src/Bus/CommandHandlerContainer.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\CommandHandlerContainer as ICommandHandlerContainer; +use CloudCreativity\Modules\Contracts\Messages\Command; use Psr\Container\ContainerInterface; final class CommandHandlerContainer implements ICommandHandlerContainer diff --git a/src/Bus/EventHandler.php b/src/Bus/EventHandler.php index 9ec57363..d40d91d9 100644 --- a/src/Bus/EventHandler.php +++ b/src/Bus/EventHandler.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Bus\EventHandler as IEventHandler; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; final readonly class EventHandler implements IEventHandler { diff --git a/src/Bus/EventHandlerContainer.php b/src/Bus/EventHandlerContainer.php index 94a47713..00563175 100644 --- a/src/Bus/EventHandlerContainer.php +++ b/src/Bus/EventHandlerContainer.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer as IEventHandlerContainer; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use Psr\Container\ContainerInterface; final class EventHandlerContainer implements IEventHandlerContainer diff --git a/src/Bus/InboundEventDispatcher.php b/src/Bus/InboundEventDispatcher.php index 892a2f2b..38685b3b 100644 --- a/src/Bus/InboundEventDispatcher.php +++ b/src/Bus/InboundEventDispatcher.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer as IEventHandlerContainer; -use CloudCreativity\Modules\Contracts\Bus\InboundEventDispatcher as IInboundEventDispatcher; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\InboundEventDispatcher as IInboundEventDispatcher; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; diff --git a/src/Bus/Loggable/SimpleContextFactory.php b/src/Bus/Loggable/SimpleContextFactory.php index 144997f6..274e1b5c 100644 --- a/src/Bus/Loggable/SimpleContextFactory.php +++ b/src/Bus/Loggable/SimpleContextFactory.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class SimpleContextFactory implements ContextFactory diff --git a/src/Bus/Middleware/LogInboundEvent.php b/src/Bus/Middleware/LogInboundEvent.php index 0b4528b6..e3dd9ce1 100644 --- a/src/Bus/Middleware/LogInboundEvent.php +++ b/src/Bus/Middleware/LogInboundEvent.php @@ -14,9 +14,9 @@ use Closure; use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Bus/Middleware/LogMessageDispatch.php b/src/Bus/Middleware/LogMessageDispatch.php index 0815fe92..914d3d48 100644 --- a/src/Bus/Middleware/LogMessageDispatch.php +++ b/src/Bus/Middleware/LogMessageDispatch.php @@ -14,10 +14,10 @@ use Closure; use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Bus\Message; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; diff --git a/src/Bus/Middleware/SetupBeforeDispatch.php b/src/Bus/Middleware/SetupBeforeDispatch.php index 199c4165..309cf5eb 100644 --- a/src/Bus/Middleware/SetupBeforeDispatch.php +++ b/src/Bus/Middleware/SetupBeforeDispatch.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Message; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class SetupBeforeDispatch implements BusMiddleware diff --git a/src/Bus/Middleware/SetupBeforeEvent.php b/src/Bus/Middleware/SetupBeforeEvent.php index 7bec6ebc..a567ef0f 100644 --- a/src/Bus/Middleware/SetupBeforeEvent.php +++ b/src/Bus/Middleware/SetupBeforeEvent.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; final readonly class SetupBeforeEvent implements InboundEventMiddleware { diff --git a/src/Bus/Middleware/TearDownAfterDispatch.php b/src/Bus/Middleware/TearDownAfterDispatch.php index 3a4f271a..cef5475b 100644 --- a/src/Bus/Middleware/TearDownAfterDispatch.php +++ b/src/Bus/Middleware/TearDownAfterDispatch.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Message; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class TearDownAfterDispatch implements BusMiddleware diff --git a/src/Bus/Middleware/TearDownAfterEvent.php b/src/Bus/Middleware/TearDownAfterEvent.php index 4e74b922..2db05bce 100644 --- a/src/Bus/Middleware/TearDownAfterEvent.php +++ b/src/Bus/Middleware/TearDownAfterEvent.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; final readonly class TearDownAfterEvent implements InboundEventMiddleware { diff --git a/src/Bus/Middleware/ValidateCommand.php b/src/Bus/Middleware/ValidateCommand.php index 5c122d23..e9224709 100644 --- a/src/Bus/Middleware/ValidateCommand.php +++ b/src/Bus/Middleware/ValidateCommand.php @@ -13,10 +13,10 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/src/Bus/Middleware/ValidateQuery.php b/src/Bus/Middleware/ValidateQuery.php index 88776d1f..57ef9a39 100644 --- a/src/Bus/Middleware/ValidateQuery.php +++ b/src/Bus/Middleware/ValidateQuery.php @@ -14,9 +14,9 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\Middleware\QueryMiddleware; -use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/src/Bus/QueryDispatcher.php b/src/Bus/QueryDispatcher.php index a4a1d1b3..65b6bdd6 100644 --- a/src/Bus/QueryDispatcher.php +++ b/src/Bus/QueryDispatcher.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Bus\Query; -use CloudCreativity\Modules\Contracts\Bus\QueryDispatcher as IQueryDispatcher; use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer as IQueryHandlerContainer; +use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messages\QueryDispatcher as IQueryDispatcher; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; diff --git a/src/Bus/QueryHandler.php b/src/Bus/QueryHandler.php index 3fbe4c32..8ed1b9f8 100644 --- a/src/Bus/QueryHandler.php +++ b/src/Bus/QueryHandler.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Bus\QueryHandler as IQueryHandler; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class QueryHandler implements IQueryHandler diff --git a/src/Bus/QueryHandlerContainer.php b/src/Bus/QueryHandlerContainer.php index 39615140..583346e0 100644 --- a/src/Bus/QueryHandlerContainer.php +++ b/src/Bus/QueryHandlerContainer.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer as IQueryHandlerContainer; +use CloudCreativity\Modules\Contracts\Messages\Query; use Psr\Container\ContainerInterface; final class QueryHandlerContainer implements IQueryHandlerContainer diff --git a/src/Bus/SwallowInboundEvent.php b/src/Bus/SwallowInboundEvent.php index 694ff507..0e7d5d6d 100644 --- a/src/Bus/SwallowInboundEvent.php +++ b/src/Bus/SwallowInboundEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Bus/Validation/ValidationProcessor.php b/src/Bus/Validation/ValidationProcessor.php index ad7c1c14..6040ad84 100644 --- a/src/Bus/Validation/ValidationProcessor.php +++ b/src/Bus/Validation/ValidationProcessor.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Bus\Validation; -use CloudCreativity\Modules\Contracts\Bus\Command; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Processor; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/src/Bus/Validation/Validator.php b/src/Bus/Validation/Validator.php index 356ebf2e..0b0635c0 100644 --- a/src/Bus/Validation/Validator.php +++ b/src/Bus/Validation/Validator.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Bus\Validation; -use CloudCreativity\Modules\Contracts\Bus\Command; -use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator as IValidator; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Pipeline; use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors as IListOfErrors; diff --git a/src/Bus/WithCommand.php b/src/Bus/WithCommand.php index e30b4d7a..e68230c6 100644 --- a/src/Bus/WithCommand.php +++ b/src/Bus/WithCommand.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithCommand diff --git a/src/Bus/WithEvent.php b/src/Bus/WithEvent.php index 2fc08930..cbaaa63c 100644 --- a/src/Bus/WithEvent.php +++ b/src/Bus/WithEvent.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithEvent diff --git a/src/Bus/WithQuery.php b/src/Bus/WithQuery.php index 2220adc3..6f44f8ca 100644 --- a/src/Bus/WithQuery.php +++ b/src/Bus/WithQuery.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Query; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithQuery diff --git a/src/Contracts/Application/Ports/OutboundEventPublisher.php b/src/Contracts/Application/Ports/OutboundEventPublisher.php index a8011495..e29424d9 100644 --- a/src/Contracts/Application/Ports/OutboundEventPublisher.php +++ b/src/Contracts/Application/Ports/OutboundEventPublisher.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Application\Ports; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface OutboundEventPublisher { diff --git a/src/Contracts/Application/Ports/Queue.php b/src/Contracts/Application/Ports/Queue.php index bbace628..29246e30 100644 --- a/src/Contracts/Application/Ports/Queue.php +++ b/src/Contracts/Application/Ports/Queue.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Application\Ports; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; interface Queue { diff --git a/src/Contracts/Bus/CommandHandler.php b/src/Contracts/Bus/CommandHandler.php index ea5ff9c1..1c8b1ce6 100644 --- a/src/Contracts/Bus/CommandHandler.php +++ b/src/Contracts/Bus/CommandHandler.php @@ -12,6 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface CommandHandler extends DispatchThroughMiddleware diff --git a/src/Contracts/Bus/CommandHandlerContainer.php b/src/Contracts/Bus/CommandHandlerContainer.php index 5d0d149a..8b7ba50a 100644 --- a/src/Contracts/Bus/CommandHandlerContainer.php +++ b/src/Contracts/Bus/CommandHandlerContainer.php @@ -12,6 +12,8 @@ namespace CloudCreativity\Modules\Contracts\Bus; +use CloudCreativity\Modules\Contracts\Messages\Command; + interface CommandHandlerContainer { /** diff --git a/src/Contracts/Bus/CommandQueuer.php b/src/Contracts/Bus/CommandQueuer.php index d2e5bb6a..3214ae0f 100644 --- a/src/Contracts/Bus/CommandQueuer.php +++ b/src/Contracts/Bus/CommandQueuer.php @@ -12,6 +12,8 @@ namespace CloudCreativity\Modules\Contracts\Bus; +use CloudCreativity\Modules\Contracts\Messages\Command; + interface CommandQueuer { /** diff --git a/src/Contracts/Bus/EventHandler.php b/src/Contracts/Bus/EventHandler.php index 65ce9cee..e6578cf5 100644 --- a/src/Contracts/Bus/EventHandler.php +++ b/src/Contracts/Bus/EventHandler.php @@ -12,6 +12,8 @@ namespace CloudCreativity\Modules\Contracts\Bus; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; + interface EventHandler extends DispatchThroughMiddleware { /** diff --git a/src/Contracts/Bus/EventHandlerContainer.php b/src/Contracts/Bus/EventHandlerContainer.php index 9f5bb9d6..ed6c3ab6 100644 --- a/src/Contracts/Bus/EventHandlerContainer.php +++ b/src/Contracts/Bus/EventHandlerContainer.php @@ -12,6 +12,8 @@ namespace CloudCreativity\Modules\Contracts\Bus; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; + interface EventHandlerContainer { /** diff --git a/src/Contracts/Bus/Loggable/ContextFactory.php b/src/Contracts/Bus/Loggable/ContextFactory.php index 7085c04f..3643cd78 100644 --- a/src/Contracts/Bus/Loggable/ContextFactory.php +++ b/src/Contracts/Bus/Loggable/ContextFactory.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Loggable; -use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface ContextFactory diff --git a/src/Contracts/Bus/Middleware/BusMiddleware.php b/src/Contracts/Bus/Middleware/BusMiddleware.php index 513c555b..4e2d20aa 100644 --- a/src/Contracts/Bus/Middleware/BusMiddleware.php +++ b/src/Contracts/Bus/Middleware/BusMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface BusMiddleware diff --git a/src/Contracts/Bus/Middleware/CommandMiddleware.php b/src/Contracts/Bus/Middleware/CommandMiddleware.php index 8c654793..e869b772 100644 --- a/src/Contracts/Bus/Middleware/CommandMiddleware.php +++ b/src/Contracts/Bus/Middleware/CommandMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface CommandMiddleware diff --git a/src/Contracts/Bus/Middleware/InboundEventMiddleware.php b/src/Contracts/Bus/Middleware/InboundEventMiddleware.php index 2a2421f2..f72aede3 100644 --- a/src/Contracts/Bus/Middleware/InboundEventMiddleware.php +++ b/src/Contracts/Bus/Middleware/InboundEventMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface InboundEventMiddleware { diff --git a/src/Contracts/Bus/Middleware/QueryMiddleware.php b/src/Contracts/Bus/Middleware/QueryMiddleware.php index 4fd58985..1f19c3f5 100644 --- a/src/Contracts/Bus/Middleware/QueryMiddleware.php +++ b/src/Contracts/Bus/Middleware/QueryMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface QueryMiddleware diff --git a/src/Contracts/Bus/QueryHandler.php b/src/Contracts/Bus/QueryHandler.php index faf0d2b9..b8ef35fa 100644 --- a/src/Contracts/Bus/QueryHandler.php +++ b/src/Contracts/Bus/QueryHandler.php @@ -12,6 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface QueryHandler extends DispatchThroughMiddleware diff --git a/src/Contracts/Bus/QueryHandlerContainer.php b/src/Contracts/Bus/QueryHandlerContainer.php index b5193b73..f0f8de9e 100644 --- a/src/Contracts/Bus/QueryHandlerContainer.php +++ b/src/Contracts/Bus/QueryHandlerContainer.php @@ -12,6 +12,8 @@ namespace CloudCreativity\Modules\Contracts\Bus; +use CloudCreativity\Modules\Contracts\Messages\Query; + interface QueryHandlerContainer { /** diff --git a/src/Contracts/Bus/Validation/Validator.php b/src/Contracts/Bus/Validation/Validator.php index 0d126202..c0e10713 100644 --- a/src/Contracts/Bus/Validation/Validator.php +++ b/src/Contracts/Bus/Validation/Validator.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Contracts\Bus\Validation; -use CloudCreativity\Modules\Contracts\Bus\Command; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors; interface Validator diff --git a/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php b/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php index 89c0b335..3c523e48 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; use Closure; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface OutboundEventMiddleware { diff --git a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php index 71fda2f7..ba6d00ae 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface PublisherHandler { diff --git a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php index b8e1c0a1..ac254f7b 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; interface PublisherHandlerContainer { diff --git a/src/Contracts/Infrastructure/Queue/Enqueuer.php b/src/Contracts/Infrastructure/Queue/Enqueuer.php index e1892f7b..7dabaf5e 100644 --- a/src/Contracts/Infrastructure/Queue/Enqueuer.php +++ b/src/Contracts/Infrastructure/Queue/Enqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; interface Enqueuer { diff --git a/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php b/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php index 25821f14..e9ff4b73 100644 --- a/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php +++ b/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; interface EnqueuerContainer { diff --git a/src/Contracts/Infrastructure/Queue/QueueMiddleware.php b/src/Contracts/Infrastructure/Queue/QueueMiddleware.php index 007d1657..805499be 100644 --- a/src/Contracts/Infrastructure/Queue/QueueMiddleware.php +++ b/src/Contracts/Infrastructure/Queue/QueueMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; interface QueueMiddleware { diff --git a/src/Contracts/Bus/Command.php b/src/Contracts/Messages/Command.php similarity index 83% rename from src/Contracts/Bus/Command.php rename to src/Contracts/Messages/Command.php index dfce39b4..3794fcb1 100644 --- a/src/Contracts/Bus/Command.php +++ b/src/Contracts/Messages/Command.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Bus; +namespace CloudCreativity\Modules\Contracts\Messages; interface Command extends Message { diff --git a/src/Contracts/Bus/CommandDispatcher.php b/src/Contracts/Messages/CommandDispatcher.php similarity index 89% rename from src/Contracts/Bus/CommandDispatcher.php rename to src/Contracts/Messages/CommandDispatcher.php index 50aa0e10..b0f2c34d 100644 --- a/src/Contracts/Bus/CommandDispatcher.php +++ b/src/Contracts/Messages/CommandDispatcher.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Bus; +namespace CloudCreativity\Modules\Contracts\Messages; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; diff --git a/src/Contracts/Bus/InboundEventDispatcher.php b/src/Contracts/Messages/InboundEventDispatcher.php similarity index 88% rename from src/Contracts/Bus/InboundEventDispatcher.php rename to src/Contracts/Messages/InboundEventDispatcher.php index 143bf3ae..4b86ccec 100644 --- a/src/Contracts/Bus/InboundEventDispatcher.php +++ b/src/Contracts/Messages/InboundEventDispatcher.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Bus; +namespace CloudCreativity\Modules\Contracts\Messages; interface InboundEventDispatcher { diff --git a/src/Contracts/Bus/IntegrationEvent.php b/src/Contracts/Messages/IntegrationEvent.php similarity index 89% rename from src/Contracts/Bus/IntegrationEvent.php rename to src/Contracts/Messages/IntegrationEvent.php index 2f38a84e..fc1e5df9 100644 --- a/src/Contracts/Bus/IntegrationEvent.php +++ b/src/Contracts/Messages/IntegrationEvent.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Bus; +namespace CloudCreativity\Modules\Contracts\Messages; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/src/Contracts/Bus/Message.php b/src/Contracts/Messages/Message.php similarity index 82% rename from src/Contracts/Bus/Message.php rename to src/Contracts/Messages/Message.php index b71da774..0923f4d7 100644 --- a/src/Contracts/Bus/Message.php +++ b/src/Contracts/Messages/Message.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Bus; +namespace CloudCreativity\Modules\Contracts\Messages; interface Message { diff --git a/src/Contracts/Bus/Query.php b/src/Contracts/Messages/Query.php similarity index 83% rename from src/Contracts/Bus/Query.php rename to src/Contracts/Messages/Query.php index cadff8fc..cd023433 100644 --- a/src/Contracts/Bus/Query.php +++ b/src/Contracts/Messages/Query.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Bus; +namespace CloudCreativity\Modules\Contracts\Messages; interface Query extends Message { diff --git a/src/Contracts/Bus/QueryDispatcher.php b/src/Contracts/Messages/QueryDispatcher.php similarity index 89% rename from src/Contracts/Bus/QueryDispatcher.php rename to src/Contracts/Messages/QueryDispatcher.php index 281ac3d5..1c73ba90 100644 --- a/src/Contracts/Bus/QueryDispatcher.php +++ b/src/Contracts/Messages/QueryDispatcher.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Bus; +namespace CloudCreativity\Modules\Contracts\Messages; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; diff --git a/src/Infrastructure/OutboundEventBus/ClosurePublisher.php b/src/Infrastructure/OutboundEventBus/ClosurePublisher.php index d70ec27a..4cdb10b6 100644 --- a/src/Infrastructure/OutboundEventBus/ClosurePublisher.php +++ b/src/Infrastructure/OutboundEventBus/ClosurePublisher.php @@ -15,7 +15,7 @@ use Closure; use CloudCreativity\Modules\Bus\PsrPipeContainer; use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; diff --git a/src/Infrastructure/OutboundEventBus/ComponentPublisher.php b/src/Infrastructure/OutboundEventBus/ComponentPublisher.php index bb6f7e2a..d281f166 100644 --- a/src/Infrastructure/OutboundEventBus/ComponentPublisher.php +++ b/src/Infrastructure/OutboundEventBus/ComponentPublisher.php @@ -14,8 +14,8 @@ use CloudCreativity\Modules\Bus\PsrPipeContainer; use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\PublisherHandlerContainer as IPublisherHandlerContainer; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; diff --git a/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php b/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php index 556bf181..72410cb3 100644 --- a/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php +++ b/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php @@ -14,9 +14,9 @@ use Closure; use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Infrastructure/OutboundEventBus/PublisherHandler.php b/src/Infrastructure/OutboundEventBus/PublisherHandler.php index b7a9cf00..3519f2fa 100644 --- a/src/Infrastructure/OutboundEventBus/PublisherHandler.php +++ b/src/Infrastructure/OutboundEventBus/PublisherHandler.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\PublisherHandler as IPublisherHandler; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; final readonly class PublisherHandler implements IPublisherHandler { diff --git a/src/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php b/src/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php index 2ba24d5f..539ce831 100644 --- a/src/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php +++ b/src/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php @@ -13,9 +13,9 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus; use Closure; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\{ PublisherHandlerContainer as IPublisherHandlerContainer}; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Infrastructure\InfrastructureException; use Psr\Container\ContainerInterface; diff --git a/src/Infrastructure/OutboundEventBus/Publishes.php b/src/Infrastructure/OutboundEventBus/Publishes.php index d27bc429..f3bea8cf 100644 --- a/src/Infrastructure/OutboundEventBus/Publishes.php +++ b/src/Infrastructure/OutboundEventBus/Publishes.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus; use Attribute; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class Publishes diff --git a/src/Infrastructure/Queue/ClosureQueue.php b/src/Infrastructure/Queue/ClosureQueue.php index e9c8da82..d5ce3289 100644 --- a/src/Infrastructure/Queue/ClosureQueue.php +++ b/src/Infrastructure/Queue/ClosureQueue.php @@ -15,7 +15,7 @@ use Closure; use CloudCreativity\Modules\Bus\PsrPipeContainer; use CloudCreativity\Modules\Contracts\Application\Ports\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; diff --git a/src/Infrastructure/Queue/ComponentQueue.php b/src/Infrastructure/Queue/ComponentQueue.php index 098656f6..057fdfb0 100644 --- a/src/Infrastructure/Queue/ComponentQueue.php +++ b/src/Infrastructure/Queue/ComponentQueue.php @@ -14,8 +14,8 @@ use CloudCreativity\Modules\Bus\PsrPipeContainer; use CloudCreativity\Modules\Contracts\Application\Ports\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\EnqueuerContainer as IEnqueuerContainer; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; diff --git a/src/Infrastructure/Queue/Enqueuer.php b/src/Infrastructure/Queue/Enqueuer.php index f7005162..cd94f864 100644 --- a/src/Infrastructure/Queue/Enqueuer.php +++ b/src/Infrastructure/Queue/Enqueuer.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\Enqueuer as IEnqueuer; +use CloudCreativity\Modules\Contracts\Messages\Command; final readonly class Enqueuer implements IEnqueuer { diff --git a/src/Infrastructure/Queue/EnqueuerContainer.php b/src/Infrastructure/Queue/EnqueuerContainer.php index 4dbff20b..76c1d29e 100644 --- a/src/Infrastructure/Queue/EnqueuerContainer.php +++ b/src/Infrastructure/Queue/EnqueuerContainer.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Infrastructure\Queue; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\EnqueuerContainer as IEnqueuerContainer; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Infrastructure\InfrastructureException; use Psr\Container\ContainerInterface; diff --git a/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php b/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php index 3b81e9be..3fe1d9ee 100644 --- a/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php +++ b/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php @@ -14,9 +14,9 @@ use Closure; use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Infrastructure/Queue/Queues.php b/src/Infrastructure/Queue/Queues.php index 875a5ec5..746990e9 100644 --- a/src/Infrastructure/Queue/Queues.php +++ b/src/Infrastructure/Queue/Queues.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Infrastructure\Queue; use Attribute; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class Queues diff --git a/src/Testing/FakeOutboundEventPublisher.php b/src/Testing/FakeOutboundEventPublisher.php index 8de56a78..16d83497 100644 --- a/src/Testing/FakeOutboundEventPublisher.php +++ b/src/Testing/FakeOutboundEventPublisher.php @@ -14,7 +14,7 @@ use ArrayAccess; use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use Countable; use Generator; use IteratorAggregate; diff --git a/src/Testing/FakeQueue.php b/src/Testing/FakeQueue.php index 25391640..1bb53ea2 100644 --- a/src/Testing/FakeQueue.php +++ b/src/Testing/FakeQueue.php @@ -14,7 +14,7 @@ use ArrayAccess; use CloudCreativity\Modules\Contracts\Application\Ports\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use Countable; use Generator; use IteratorAggregate; diff --git a/tests/Integration/Bus/AddCommand.php b/tests/Integration/Bus/AddCommand.php index dbf21a71..e7456b91 100644 --- a/tests/Integration/Bus/AddCommand.php +++ b/tests/Integration/Bus/AddCommand.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; final readonly class AddCommand implements Command { diff --git a/tests/Integration/Bus/DefaultEventHandler.php b/tests/Integration/Bus/DefaultEventHandler.php index 0828886e..4fe1fa4c 100644 --- a/tests/Integration/Bus/DefaultEventHandler.php +++ b/tests/Integration/Bus/DefaultEventHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; final class DefaultEventHandler { diff --git a/tests/Integration/Bus/DivideQuery.php b/tests/Integration/Bus/DivideQuery.php index 39d1c0a5..2ba27011 100644 --- a/tests/Integration/Bus/DivideQuery.php +++ b/tests/Integration/Bus/DivideQuery.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Query; final readonly class DivideQuery implements Query { diff --git a/tests/Integration/Bus/FloorCommand.php b/tests/Integration/Bus/FloorCommand.php index e5dadd49..b4a0f376 100644 --- a/tests/Integration/Bus/FloorCommand.php +++ b/tests/Integration/Bus/FloorCommand.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; final readonly class FloorCommand implements Command { diff --git a/tests/Integration/Bus/MultiplyCommand.php b/tests/Integration/Bus/MultiplyCommand.php index e121e74b..80a95faf 100644 --- a/tests/Integration/Bus/MultiplyCommand.php +++ b/tests/Integration/Bus/MultiplyCommand.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; final readonly class MultiplyCommand implements Command { diff --git a/tests/Integration/Bus/NumbersAdded.php b/tests/Integration/Bus/NumbersAdded.php index 92bd6620..bdf0a444 100644 --- a/tests/Integration/Bus/NumbersAdded.php +++ b/tests/Integration/Bus/NumbersAdded.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Integration/Bus/NumbersDivided.php b/tests/Integration/Bus/NumbersDivided.php index 1bc6dc1f..35222b8a 100644 --- a/tests/Integration/Bus/NumbersDivided.php +++ b/tests/Integration/Bus/NumbersDivided.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Integration/Bus/NumbersSubtracted.php b/tests/Integration/Bus/NumbersSubtracted.php index f4d7ada1..1c3a6abf 100644 --- a/tests/Integration/Bus/NumbersSubtracted.php +++ b/tests/Integration/Bus/NumbersSubtracted.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Integration/Bus/SubtractQuery.php b/tests/Integration/Bus/SubtractQuery.php index c76b4f39..d823d78d 100644 --- a/tests/Integration/Bus/SubtractQuery.php +++ b/tests/Integration/Bus/SubtractQuery.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Query; final readonly class SubtractQuery implements Query { diff --git a/tests/Integration/Infrastructure/OutboundEventBus/TestDefaultPublisher.php b/tests/Integration/Infrastructure/OutboundEventBus/TestDefaultPublisher.php index 2252d2a4..a42f382c 100644 --- a/tests/Integration/Infrastructure/OutboundEventBus/TestDefaultPublisher.php +++ b/tests/Integration/Infrastructure/OutboundEventBus/TestDefaultPublisher.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; final class TestDefaultPublisher { diff --git a/tests/Integration/Infrastructure/Queue/TestDefaultEnqueuer.php b/tests/Integration/Infrastructure/Queue/TestDefaultEnqueuer.php index b73ba980..6ed65779 100644 --- a/tests/Integration/Infrastructure/Queue/TestDefaultEnqueuer.php +++ b/tests/Integration/Infrastructure/Queue/TestDefaultEnqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Integration\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; final class TestDefaultEnqueuer { diff --git a/tests/Unit/Application/Bus/CommandDispatcherTest.php b/tests/Unit/Application/Bus/CommandDispatcherTest.php index 4e473faa..5f280012 100644 --- a/tests/Unit/Application/Bus/CommandDispatcherTest.php +++ b/tests/Unit/Application/Bus/CommandDispatcherTest.php @@ -13,9 +13,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; use CloudCreativity\Modules\Bus\CommandDispatcher; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\CommandHandler; use CloudCreativity\Modules\Contracts\Bus\CommandHandlerContainer; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Application/Bus/CommandHandlerContainerTest.php b/tests/Unit/Application/Bus/CommandHandlerContainerTest.php index c8ef5f74..d16a0c88 100644 --- a/tests/Unit/Application/Bus/CommandHandlerContainerTest.php +++ b/tests/Unit/Application/Bus/CommandHandlerContainerTest.php @@ -15,7 +15,7 @@ use CloudCreativity\Modules\Bus\BusException; use CloudCreativity\Modules\Bus\CommandHandler; use CloudCreativity\Modules\Bus\CommandHandlerContainer; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; diff --git a/tests/Unit/Application/Bus/Middleware/ExecuteInUnitOfWorkTest.php b/tests/Unit/Application/Bus/Middleware/ExecuteInUnitOfWorkTest.php index 2b578ee8..fbcaf62c 100644 --- a/tests/Unit/Application/Bus/Middleware/ExecuteInUnitOfWorkTest.php +++ b/tests/Unit/Application/Bus/Middleware/ExecuteInUnitOfWorkTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; use CloudCreativity\Modules\Contracts\Application\UnitOfWork\UnitOfWorkManager; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use Throwable; diff --git a/tests/Unit/Application/Bus/Middleware/FlushDeferredEventsTest.php b/tests/Unit/Application/Bus/Middleware/FlushDeferredEventsTest.php index 33c45940..c8afe46e 100644 --- a/tests/Unit/Application/Bus/Middleware/FlushDeferredEventsTest.php +++ b/tests/Unit/Application/Bus/Middleware/FlushDeferredEventsTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Application\Bus\Middleware\FlushDeferredEvents; use CloudCreativity\Modules\Contracts\Application\DomainEventDispatching\DeferredDispatcher; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php b/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php index 5c5ebb4c..00f21fc1 100644 --- a/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php @@ -13,10 +13,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Bus\Message; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Toolkit\Result\Result; use LogicException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php b/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php index 1ed0048e..d400ddaa 100644 --- a/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php @@ -14,8 +14,8 @@ use Closure; use CloudCreativity\Modules\Bus\Middleware\SetupBeforeDispatch; -use CloudCreativity\Modules\Contracts\Bus\Command; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php b/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php index 45c428e3..d7ab1fa8 100644 --- a/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; use CloudCreativity\Modules\Bus\Middleware\TearDownAfterDispatch; -use CloudCreativity\Modules\Contracts\Bus\Command; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php b/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php index e0abf7a3..e6c30c26 100644 --- a/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php +++ b/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php @@ -13,9 +13,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; use CloudCreativity\Modules\Bus\Middleware\ValidateCommand; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php b/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php index fffc0cdc..2ce35904 100644 --- a/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php +++ b/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php @@ -13,9 +13,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; use CloudCreativity\Modules\Bus\Middleware\ValidateQuery; -use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/Bus/QueryDispatcherTest.php b/tests/Unit/Application/Bus/QueryDispatcherTest.php index f908e102..cf1fa036 100644 --- a/tests/Unit/Application/Bus/QueryDispatcherTest.php +++ b/tests/Unit/Application/Bus/QueryDispatcherTest.php @@ -13,9 +13,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; use CloudCreativity\Modules\Bus\QueryDispatcher; -use CloudCreativity\Modules\Contracts\Bus\Query; use CloudCreativity\Modules\Contracts\Bus\QueryHandler; use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Application/Bus/QueryHandlerContainerTest.php b/tests/Unit/Application/Bus/QueryHandlerContainerTest.php index b79f26ad..fee8695c 100644 --- a/tests/Unit/Application/Bus/QueryHandlerContainerTest.php +++ b/tests/Unit/Application/Bus/QueryHandlerContainerTest.php @@ -15,7 +15,7 @@ use CloudCreativity\Modules\Bus\BusException; use CloudCreativity\Modules\Bus\QueryHandler; use CloudCreativity\Modules\Bus\QueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Query; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; diff --git a/tests/Unit/Application/Bus/TestCommand.php b/tests/Unit/Application/Bus/TestCommand.php index 90470023..f09fba6e 100644 --- a/tests/Unit/Application/Bus/TestCommand.php +++ b/tests/Unit/Application/Bus/TestCommand.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; class TestCommand implements Command { diff --git a/tests/Unit/Application/Bus/TestQuery.php b/tests/Unit/Application/Bus/TestQuery.php index 7c0e6f50..4ece49bf 100644 --- a/tests/Unit/Application/Bus/TestQuery.php +++ b/tests/Unit/Application/Bus/TestQuery.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Query; class TestQuery implements Query { diff --git a/tests/Unit/Application/Bus/ValidatorTest.php b/tests/Unit/Application/Bus/ValidatorTest.php index 7eefcf0d..b91f99f4 100644 --- a/tests/Unit/Application/Bus/ValidatorTest.php +++ b/tests/Unit/Application/Bus/ValidatorTest.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; use CloudCreativity\Modules\Bus\Validation\Validator; -use CloudCreativity\Modules\Contracts\Bus\Command; -use CloudCreativity\Modules\Contracts\Bus\Query; +use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messages\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php b/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php index df7513e4..b510637c 100644 --- a/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php +++ b/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php @@ -15,7 +15,7 @@ use CloudCreativity\Modules\Bus\InboundEventDispatcher; use CloudCreativity\Modules\Contracts\Bus\EventHandler; use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php index 92933593..6ba8b240 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Bus\Loggable\ObjectDecorator; use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\TestOutboundEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use LogicException; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php index aef9b3c4..a2edc6af 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Bus\Middleware\SetupBeforeEvent; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php index eb32c9f9..50a50154 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus\Middleware; use CloudCreativity\Modules\Bus\Middleware\TearDownAfterEvent; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/InboundEventBus/TestInboundEvent.php b/tests/Unit/Application/InboundEventBus/TestInboundEvent.php index 4940f9ab..d0f8e80c 100644 --- a/tests/Unit/Application/InboundEventBus/TestInboundEvent.php +++ b/tests/Unit/Application/InboundEventBus/TestInboundEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php b/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php index ec429ca5..04d6ce11 100644 --- a/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php +++ b/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php @@ -16,7 +16,7 @@ use CloudCreativity\Modules\Bus\Loggable\Sensitive; use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Bus\Message; +use CloudCreativity\Modules\Contracts\Messages\Message; use CloudCreativity\Modules\Tests\TestBackedEnum; use CloudCreativity\Modules\Tests\TestBackedIntEnum; use CloudCreativity\Modules\Tests\TestUnitEnum; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php b/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php index 1045292e..24b4e975 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\ClosurePublisher; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php b/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php index 45a7bb01..35e34d79 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\Middleware; use CloudCreativity\Modules\Bus\Loggable\ObjectDecorator; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent; use CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\TestOutboundEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php b/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php index 48e2bd20..e8df86d3 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php b/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php index 92fd286e..8b5beb3f 100644 --- a/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Infrastructure\Queue\ClosureQueue; use CloudCreativity\Modules\Tests\Unit\Application\Bus\TestCommand; diff --git a/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php b/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php index f960e4aa..2a7ce890 100644 --- a/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php @@ -12,9 +12,9 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\Enqueuer; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\EnqueuerContainer; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Infrastructure\Queue\ComponentQueue; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php b/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php index dcf6db20..6d311c4b 100644 --- a/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php +++ b/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Infrastructure\Queue\Enqueuer; use CloudCreativity\Modules\Infrastructure\Queue\EnqueuerContainer; use CloudCreativity\Modules\Tests\Unit\Application\Bus\TestCommand; diff --git a/tests/Unit/Infrastructure/Queue/EnqueuerTest.php b/tests/Unit/Infrastructure/Queue/EnqueuerTest.php index 78f25f9d..294907f6 100644 --- a/tests/Unit/Infrastructure/Queue/EnqueuerTest.php +++ b/tests/Unit/Infrastructure/Queue/EnqueuerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Infrastructure\Queue\Enqueuer; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php b/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php index 752336a1..61bf1f18 100644 --- a/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue\Middleware; -use CloudCreativity\Modules\Contracts\Bus\Command; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue; use LogicException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Infrastructure/Queue/TestEnqueuer.php b/tests/Unit/Infrastructure/Queue/TestEnqueuer.php index 3ad676c2..ac2557b7 100644 --- a/tests/Unit/Infrastructure/Queue/TestEnqueuer.php +++ b/tests/Unit/Infrastructure/Queue/TestEnqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; class TestEnqueuer { diff --git a/tests/Unit/Testing/FakeOutboundEventPublisherTest.php b/tests/Unit/Testing/FakeOutboundEventPublisherTest.php index 1f28f697..9b8b8e6a 100644 --- a/tests/Unit/Testing/FakeOutboundEventPublisherTest.php +++ b/tests/Unit/Testing/FakeOutboundEventPublisherTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Testing; use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; -use CloudCreativity\Modules\Contracts\Bus\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; use CloudCreativity\Modules\Testing\FakeOutboundEventPublisher; use LogicException; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Testing/FakeQueueTest.php b/tests/Unit/Testing/FakeQueueTest.php index 71e04259..c3489e56 100644 --- a/tests/Unit/Testing/FakeQueueTest.php +++ b/tests/Unit/Testing/FakeQueueTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Testing; use CloudCreativity\Modules\Contracts\Application\Ports\Queue; -use CloudCreativity\Modules\Contracts\Bus\Command; +use CloudCreativity\Modules\Contracts\Messages\Command; use CloudCreativity\Modules\Testing\FakeQueue; use LogicException; use PHPUnit\Framework\TestCase; From e550c4f018bc0ef233382339951a6fe3cac4f22f Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Fri, 2 Jan 2026 05:47:11 +0000 Subject: [PATCH 3/8] wip: move processing of log context to monolog processor --- composer.json | 1 + deptrac.yaml | 16 ++- docs/guide/application/commands.md | 10 +- docs/guide/application/integration-events.md | 16 +-- docs/guide/application/queries.md | 8 +- docs/guide/infrastructure/outbox.md | 2 +- .../guide/infrastructure/publishing-events.md | 6 +- docs/guide/infrastructure/queues.md | 10 +- src/Application/Bus/CommandQueuer.php | 2 +- .../Bus/Middleware/ExecuteInUnitOfWork.php | 2 +- .../Bus/Middleware/FlushDeferredEvents.php | 2 +- src/Bus/CommandDispatcher.php | 4 +- src/Bus/CommandHandler.php | 2 +- src/Bus/CommandHandlerContainer.php | 2 +- src/Bus/EventHandler.php | 2 +- src/Bus/EventHandlerContainer.php | 2 +- src/Bus/InboundEventDispatcher.php | 4 +- src/Bus/Loggable/ObjectDecorator.php | 3 +- src/Bus/Loggable/ResultDecorator.php | 2 +- src/Bus/Loggable/SimpleContextFactory.php | 2 +- src/Bus/Logging/SanitizedMessage.php | 55 +++++++++ src/Bus/Logging/SanitizedResult.php | 70 +++++++++++ src/Bus/Middleware/LogInboundEvent.php | 2 +- src/Bus/Middleware/LogMessageDispatch.php | 22 ++-- src/Bus/Middleware/SetupBeforeDispatch.php | 2 +- src/Bus/Middleware/SetupBeforeEvent.php | 2 +- src/Bus/Middleware/TearDownAfterDispatch.php | 2 +- src/Bus/Middleware/TearDownAfterEvent.php | 2 +- src/Bus/Middleware/ValidateCommand.php | 2 +- src/Bus/Middleware/ValidateQuery.php | 2 +- src/Bus/QueryDispatcher.php | 4 +- src/Bus/QueryHandler.php | 2 +- src/Bus/QueryHandlerContainer.php | 2 +- src/Bus/SwallowInboundEvent.php | 2 +- src/Bus/Validation/ValidationProcessor.php | 4 +- src/Bus/Validation/Validator.php | 4 +- src/Bus/WithCommand.php | 2 +- src/Bus/WithEvent.php | 2 +- src/Bus/WithQuery.php | 2 +- .../Ports/OutboundEventPublisher.php | 2 +- src/Contracts/Application/Ports/Queue.php | 2 +- src/Contracts/Bus/CommandHandler.php | 2 +- src/Contracts/Bus/CommandHandlerContainer.php | 2 +- src/Contracts/Bus/CommandQueuer.php | 2 +- src/Contracts/Bus/EventHandler.php | 2 +- src/Contracts/Bus/EventHandlerContainer.php | 2 +- src/Contracts/Bus/Loggable/ContextFactory.php | 2 +- .../Bus/Middleware/BusMiddleware.php | 2 +- .../Bus/Middleware/CommandMiddleware.php | 2 +- .../Bus/Middleware/InboundEventMiddleware.php | 2 +- .../Bus/Middleware/QueryMiddleware.php | 2 +- src/Contracts/Bus/QueryHandler.php | 2 +- src/Contracts/Bus/QueryHandlerContainer.php | 2 +- src/Contracts/Bus/Validation/Validator.php | 4 +- .../OutboundEventMiddleware.php | 2 +- .../OutboundEventBus/PublisherHandler.php | 2 +- .../PublisherHandlerContainer.php | 2 +- .../Infrastructure/Queue/Enqueuer.php | 2 +- .../Queue/EnqueuerContainer.php | 2 +- .../Infrastructure/Queue/QueueMiddleware.php | 2 +- .../{Messages => Messaging}/Command.php | 2 +- .../CommandDispatcher.php | 2 +- .../InboundEventDispatcher.php | 2 +- .../IntegrationEvent.php | 2 +- .../{Messages => Messaging}/Message.php | 2 +- .../{Messages => Messaging}/Query.php | 2 +- .../QueryDispatcher.php | 2 +- .../{Bus/Loggable => Toolkit}/Contextual.php | 2 +- .../Toolkit/Identifiers/Identifier.php | 8 +- .../Monolog/ContextProcessor.php | 80 ++++++++++++ .../Monolog/RecursiveParser.php | 37 ++++++ src/Infrastructure/Monolog/ValueParser.php | 18 +++ .../OutboundEventBus/ClosurePublisher.php | 2 +- .../OutboundEventBus/ComponentPublisher.php | 2 +- .../Middleware/LogOutboundEvent.php | 2 +- .../OutboundEventBus/PublisherHandler.php | 2 +- .../PublisherHandlerContainer.php | 2 +- .../OutboundEventBus/Publishes.php | 2 +- src/Infrastructure/Queue/ClosureQueue.php | 2 +- src/Infrastructure/Queue/ComponentQueue.php | 2 +- src/Infrastructure/Queue/Enqueuer.php | 2 +- .../Queue/EnqueuerContainer.php | 2 +- .../Queue/Middleware/LogPushedToQueue.php | 2 +- src/Infrastructure/Queue/Queues.php | 2 +- src/{Bus/Loggable => Messaging}/Sensitive.php | 2 +- src/Testing/FakeOutboundEventPublisher.php | 2 +- src/Testing/FakeQueue.php | 2 +- tests/Integration/Bus/AddCommand.php | 2 +- tests/Integration/Bus/DefaultEventHandler.php | 2 +- tests/Integration/Bus/DivideQuery.php | 2 +- tests/Integration/Bus/FloorCommand.php | 2 +- tests/Integration/Bus/MultiplyCommand.php | 2 +- tests/Integration/Bus/NumbersAdded.php | 2 +- tests/Integration/Bus/NumbersDivided.php | 2 +- tests/Integration/Bus/NumbersSubtracted.php | 2 +- tests/Integration/Bus/SubtractQuery.php | 2 +- .../OutboundEventBus/TestDefaultPublisher.php | 2 +- .../Queue/TestDefaultEnqueuer.php | 2 +- .../Application/Bus/CommandDispatcherTest.php | 2 +- .../Bus/CommandHandlerContainerTest.php | 2 +- .../Middleware/ExecuteInUnitOfWorkTest.php | 2 +- .../Middleware/FlushDeferredEventsTest.php | 2 +- .../Bus/Middleware/LogMessageDispatchTest.php | 114 ++++++------------ .../Middleware/SetupBeforeDispatchTest.php | 4 +- .../Middleware/TearDownAfterDispatchTest.php | 4 +- .../Bus/Middleware/ValidateCommandTest.php | 2 +- .../Bus/Middleware/ValidateQueryTest.php | 2 +- .../Application/Bus/QueryDispatcherTest.php | 2 +- .../Bus/QueryHandlerContainerTest.php | 2 +- tests/Unit/Application/Bus/TestCommand.php | 2 +- tests/Unit/Application/Bus/TestQuery.php | 2 +- tests/Unit/Application/Bus/ValidatorTest.php | 4 +- .../InboundEventDispatcherTest.php | 2 +- .../Middleware/LogInboundEventTest.php | 2 +- .../Middleware/SetupBeforeEventTest.php | 2 +- .../Middleware/TearDownAfterEventTest.php | 2 +- .../InboundEventBus/TestInboundEvent.php | 2 +- .../Unit/Bus/Loggable/ObjectDecoratorTest.php | 4 +- .../Unit/Bus/Loggable/ResultDecoratorTest.php | 2 +- .../OutboundEventBus/ClosurePublisherTest.php | 2 +- .../Middleware/LogOutboundEventTest.php | 2 +- .../OutboundEventBus/TestOutboundEvent.php | 2 +- .../Infrastructure/Queue/ClosureQueueTest.php | 2 +- .../Queue/ComponentQueueTest.php | 2 +- .../Queue/EnqueuerContainerTest.php | 2 +- .../Infrastructure/Queue/EnqueuerTest.php | 2 +- .../Queue/Middleware/LogPushedToQueueTest.php | 2 +- .../Infrastructure/Queue/TestEnqueuer.php | 2 +- .../FakeOutboundEventPublisherTest.php | 2 +- tests/Unit/Testing/FakeQueueTest.php | 2 +- 130 files changed, 474 insertions(+), 248 deletions(-) create mode 100644 src/Bus/Logging/SanitizedMessage.php create mode 100644 src/Bus/Logging/SanitizedResult.php rename src/Contracts/{Messages => Messaging}/Command.php (83%) rename src/Contracts/{Messages => Messaging}/CommandDispatcher.php (89%) rename src/Contracts/{Messages => Messaging}/InboundEventDispatcher.php (87%) rename src/Contracts/{Messages => Messaging}/IntegrationEvent.php (89%) rename src/Contracts/{Messages => Messaging}/Message.php (82%) rename src/Contracts/{Messages => Messaging}/Query.php (83%) rename src/Contracts/{Messages => Messaging}/QueryDispatcher.php (89%) rename src/Contracts/{Bus/Loggable => Toolkit}/Contextual.php (86%) create mode 100644 src/Infrastructure/Monolog/ContextProcessor.php create mode 100644 src/Infrastructure/Monolog/RecursiveParser.php create mode 100644 src/Infrastructure/Monolog/ValueParser.php rename src/{Bus/Loggable => Messaging}/Sensitive.php (86%) diff --git a/composer.json b/composer.json index 87b1cfae..fab87ed2 100644 --- a/composer.json +++ b/composer.json @@ -32,6 +32,7 @@ "require-dev": { "deptrac/deptrac": "^4.4", "laravel/pint": "^1.26", + "monolog/monolog": "^3.9", "phpstan/phpstan": "^2.1", "phpunit/phpunit": "^11.5" }, diff --git a/deptrac.yaml b/deptrac.yaml index f6034981..0b6745f1 100644 --- a/deptrac.yaml +++ b/deptrac.yaml @@ -26,10 +26,14 @@ deptrac: value: CloudCreativity\\Modules\\Contracts\\Infrastructure\\* - type: classLike value: CloudCreativity\\Modules\\Infrastructure\\* - - name: Messages + - type: classLike + value: Monolog\\* + - name: Messaging collectors: - type: classLike - value: CloudCreativity\\Modules\\Contracts\\Messages\\* + value: CloudCreativity\\Modules\\Contracts\\Messaging\\* + - type: classLike + value: CloudCreativity\\Modules\\Messaging\\* - name: PSR Container collectors: - type: classLike @@ -52,12 +56,12 @@ deptrac: Application: - Bus - Domain - - Messages + - Messaging - PSR Container - PSR Log - Toolkit Bus: - - Messages + - Messaging - PSR Container - PSR Log - Toolkit @@ -66,10 +70,10 @@ deptrac: Infrastructure: - Application - Bus - - Messages + - Messaging - PSR Container - PSR Log - Toolkit - Messages: + Messaging: - Toolkit Toolkit: diff --git a/docs/guide/application/commands.md b/docs/guide/application/commands.md index 6118ffa5..3c6a10ff 100644 --- a/docs/guide/application/commands.md +++ b/docs/guide/application/commands.md @@ -18,7 +18,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\UseCases\Commands\CancelAttendeeTicket; -use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; +use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; final readonly class CancelAttendeeTicketCommand implements Command { @@ -602,7 +602,7 @@ However, there may be scenarios where a property should not be logged, e.g. beca In this scenario, use the `Sensitive` attribute on the property, and it will not be logged: ```php -use CloudCreativity\Modules\Bus\Loggable\Sensitive;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use CloudCreativity\Modules\Messaging\Sensitive; final readonly class CancelAttendeeTicketCommand implements Command { @@ -618,7 +618,7 @@ final readonly class CancelAttendeeTicketCommand implements Command If you need full control over the log context, implement the `ContextProvider` interface on your command message: ```php -use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class CancelAttendeeTicketCommand implements Command, @@ -648,7 +648,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class MyMiddleware implements CommandMiddleware { @@ -687,7 +687,7 @@ instead: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Messages\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Messaging\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; class MyBusMiddleware implements BusMiddleware { diff --git a/docs/guide/application/integration-events.md b/docs/guide/application/integration-events.md index 19a3d458..602b69f5 100644 --- a/docs/guide/application/integration-events.md +++ b/docs/guide/application/integration-events.md @@ -36,7 +36,7 @@ For example: ```php namespace VendorName\EventManagement\Shared\IntegrationEvents\V1; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use CloudCreativity\Modules\Toolkit\Identifiers\Uuid;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use CloudCreativity\Modules\Toolkit\Identifiers\Uuid;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum; final readonly class AttendeeTicketWasCancelled implements IntegrationEvent @@ -94,7 +94,7 @@ This can be expressed via an interface. To illustrate the point, a JSON serializ ```php namespace VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface JsonSerializer { @@ -396,7 +396,7 @@ We do this by defining an interface in our application's driving ports: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Messages\InboundEventDispatcher; +use CloudCreativity\Modules\Contracts\Messaging\InboundEventDispatcher; interface InboundEventBus extends InboundEventDispatcher { @@ -523,7 +523,7 @@ Here is an example controller from a Laravel application to demonstrate the patt ```php namespace App\Http\Controllers\Api\PubSub; -use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; +use App\Modules\EventManagement\Application\Ports\Driving\InboundEventBus;use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; class InboundEventController extends Controller { @@ -627,7 +627,7 @@ example: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface Inbox { @@ -642,7 +642,7 @@ might look like this: ```php namespace App\Modules\EventManagement\Application\Ports\Driven\Inbox; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface InboxRepository { @@ -661,7 +661,7 @@ This means we can now update the previous controller example to use the inbox in ```php namespace App\Http\Controllers\Api\PubSub; -use App\Modules\EventManagement\Application\Ports\Driving\InboundEvents\Inbox;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; +use App\Modules\EventManagement\Application\Ports\Driving\InboundEvents\Inbox;use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent;use VendorName\Ordering\Shared\IntegrationEvents\V1\Serializers\JsonSerializer; class InboundEventController extends Controller { @@ -865,7 +865,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware;use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; final class MyMiddleware implements InboundEventMiddleware { diff --git a/docs/guide/application/queries.md b/docs/guide/application/queries.md index 527a7cd1..8f032ec1 100644 --- a/docs/guide/application/queries.md +++ b/docs/guide/application/queries.md @@ -18,7 +18,7 @@ For example: ```php namespace App\Modules\EventManagement\Application\UseCases\Queries\GetAttendeeTickets; -use CloudCreativity\Modules\Contracts\Messages\Query;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Messaging\Query;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class GetAttendeeTicketsQuery implements Query { @@ -105,7 +105,7 @@ We do this by defining an interface in our application's driving ports: ```php namespace App\Modules\EventManagement\Application\Ports\Driving; -use CloudCreativity\Modules\Contracts\Messages\QueryDispatcher; +use CloudCreativity\Modules\Contracts\Messaging\QueryDispatcher; interface QueryBus extends QueryDispatcher { @@ -391,7 +391,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\QueryMiddleware;use CloudCreativity\Modules\Contracts\Messages\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\QueryMiddleware;use CloudCreativity\Modules\Contracts\Messaging\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class MyMiddleware implements QueryMiddleware { @@ -430,7 +430,7 @@ instead: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Contracts\Messages\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Messaging\Query;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; class MyBusMiddleware implements BusMiddleware { diff --git a/docs/guide/infrastructure/outbox.md b/docs/guide/infrastructure/outbox.md index 019091da..e33ec21f 100644 --- a/docs/guide/infrastructure/outbox.md +++ b/docs/guide/infrastructure/outbox.md @@ -62,7 +62,7 @@ Our recommended approach is to first place these events into an outbox. This mea ```php namespace App\Modules\EventManagement\Application\Ports\Driven\OutboundEvents; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface Outbox { diff --git a/docs/guide/infrastructure/publishing-events.md b/docs/guide/infrastructure/publishing-events.md index 2eda4bc9..83d85368 100644 --- a/docs/guide/infrastructure/publishing-events.md +++ b/docs/guide/infrastructure/publishing-events.md @@ -61,7 +61,7 @@ specific closures to specific events, and add middleware to the publisher. Here' ```php namespace App\Modules\EventManagement\Infrastructure\OutboundEventBus; -use App\Modules\EventManagement\Application\Ports\Driven\OutboundEventBus\OutboundEventBus;use App\Modules\EventManagement\Infrastructure\GooglePubSub\EventSerializer;use App\Modules\EventManagement\Infrastructure\GooglePubSub\SecureTopicFactory;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent;use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;use Psr\Log\LoggerInterface;use VendorName\EventManagement\Shared\IntegrationEvents\V1\AttendeeTicketWasCancelled; +use App\Modules\EventManagement\Application\Ports\Driven\OutboundEventBus\OutboundEventBus;use App\Modules\EventManagement\Infrastructure\GooglePubSub\EventSerializer;use App\Modules\EventManagement\Infrastructure\GooglePubSub\SecureTopicFactory;use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent;use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;use Psr\Log\LoggerInterface;use VendorName\EventManagement\Shared\IntegrationEvents\V1\AttendeeTicketWasCancelled; final readonly class OutboundEventBusAdapterProvider { @@ -255,7 +255,7 @@ implement the following interface that was extended by the driven port: ```php namespace CloudCreativity\Modules\Application\Ports\Driven\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface EventPublisher { @@ -313,7 +313,7 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Adapters\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware;use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use Closure;use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware;use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; final class MyMiddleware implements OutboundEventMiddleware { diff --git a/docs/guide/infrastructure/queues.md b/docs/guide/infrastructure/queues.md index a6c24a05..d1bcaa43 100644 --- a/docs/guide/infrastructure/queues.md +++ b/docs/guide/infrastructure/queues.md @@ -79,7 +79,7 @@ Then you can create the adapter by providing it with the default closure for que ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use App\Modules\EventManagement\Application\Ports\Driven\Queue\Queue;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; +use App\Modules\EventManagement\Application\Ports\Driven\Queue\Queue;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue;use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; final class QueueAdapterProvider { @@ -217,7 +217,7 @@ example: ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; final class DefaultEnqueuer { @@ -244,7 +244,7 @@ implements the port interface that is extended in your application layer: ```php namespace CloudCreativity\Modules\Application\Ports\Driven\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; interface Queue { @@ -279,7 +279,7 @@ For example, a default Laravel job for queuing and dispatching commands would be ```php namespace App\Modules\EventManagement\Infrastructure\Queue; -use App\Modules\EventManagement\Application\Ports\Driving\CommandBus;use CloudCreativity\Modules\Contracts\Messages\Command;use CloudCreativity\Modules\Toolkit\Result\FailedResultException;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue; +use App\Modules\EventManagement\Application\Ports\Driving\CommandBus;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Toolkit\Result\FailedResultException;use Illuminate\Bus\Queueable;use Illuminate\Contracts\Queue\ShouldQueue;use Illuminate\Foundation\Bus\Dispatchable;use Illuminate\Queue\InteractsWithQueue; class DispatchCommandJob implements ShouldQueue { @@ -454,7 +454,7 @@ following signature: ```php namespace App\Modules\Shared\Infrastructure\Queue\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware;use CloudCreativity\Modules\Contracts\Messages\Command; +use Closure;use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware;use CloudCreativity\Modules\Contracts\Messaging\Command; final class MyQueueMiddleware implements QueueMiddleware { diff --git a/src/Application/Bus/CommandQueuer.php b/src/Application/Bus/CommandQueuer.php index e645d55b..243e890d 100644 --- a/src/Application/Bus/CommandQueuer.php +++ b/src/Application/Bus/CommandQueuer.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Contracts\Application\Ports\Queue; use CloudCreativity\Modules\Contracts\Bus\CommandQueuer as ICommandQueuer; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; class CommandQueuer implements ICommandQueuer { diff --git a/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php b/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php index 8c0b91eb..e57ff90d 100644 --- a/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php +++ b/src/Application/Bus/Middleware/ExecuteInUnitOfWork.php @@ -16,7 +16,7 @@ use CloudCreativity\Modules\Application\Bus\AbortOnFailureException; use CloudCreativity\Modules\Contracts\Application\UnitOfWork\UnitOfWorkManager; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class ExecuteInUnitOfWork implements BusMiddleware diff --git a/src/Application/Bus/Middleware/FlushDeferredEvents.php b/src/Application/Bus/Middleware/FlushDeferredEvents.php index b2c1e88b..2f853444 100644 --- a/src/Application/Bus/Middleware/FlushDeferredEvents.php +++ b/src/Application/Bus/Middleware/FlushDeferredEvents.php @@ -15,7 +15,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Application\DomainEventDispatching\DeferredDispatcher; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use Throwable; diff --git a/src/Bus/CommandDispatcher.php b/src/Bus/CommandDispatcher.php index 45a4ab70..76a698d6 100644 --- a/src/Bus/CommandDispatcher.php +++ b/src/Bus/CommandDispatcher.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Bus\CommandHandlerContainer as ICommandHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\Command; -use CloudCreativity\Modules\Contracts\Messages\CommandDispatcher as ICommandDispatcher; +use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\CommandDispatcher as ICommandDispatcher; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; diff --git a/src/Bus/CommandHandler.php b/src/Bus/CommandHandler.php index 58e87c2b..d32b80db 100644 --- a/src/Bus/CommandHandler.php +++ b/src/Bus/CommandHandler.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Bus\CommandHandler as ICommandHandler; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class CommandHandler implements ICommandHandler diff --git a/src/Bus/CommandHandlerContainer.php b/src/Bus/CommandHandlerContainer.php index 28c3b09c..07ede5be 100644 --- a/src/Bus/CommandHandlerContainer.php +++ b/src/Bus/CommandHandlerContainer.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\CommandHandlerContainer as ICommandHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use Psr\Container\ContainerInterface; final class CommandHandlerContainer implements ICommandHandlerContainer diff --git a/src/Bus/EventHandler.php b/src/Bus/EventHandler.php index d40d91d9..e9739f96 100644 --- a/src/Bus/EventHandler.php +++ b/src/Bus/EventHandler.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Bus\EventHandler as IEventHandler; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; final readonly class EventHandler implements IEventHandler { diff --git a/src/Bus/EventHandlerContainer.php b/src/Bus/EventHandlerContainer.php index 00563175..29d160de 100644 --- a/src/Bus/EventHandlerContainer.php +++ b/src/Bus/EventHandlerContainer.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer as IEventHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use Psr\Container\ContainerInterface; final class EventHandlerContainer implements IEventHandlerContainer diff --git a/src/Bus/InboundEventDispatcher.php b/src/Bus/InboundEventDispatcher.php index 38685b3b..d0861df9 100644 --- a/src/Bus/InboundEventDispatcher.php +++ b/src/Bus/InboundEventDispatcher.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer as IEventHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\InboundEventDispatcher as IInboundEventDispatcher; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\InboundEventDispatcher as IInboundEventDispatcher; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; diff --git a/src/Bus/Loggable/ObjectDecorator.php b/src/Bus/Loggable/ObjectDecorator.php index 4c6e897d..de10ae8e 100644 --- a/src/Bus/Loggable/ObjectDecorator.php +++ b/src/Bus/Loggable/ObjectDecorator.php @@ -13,7 +13,8 @@ namespace CloudCreativity\Modules\Bus\Loggable; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Bus\Loggable\Contextual; +use CloudCreativity\Modules\Contracts\Toolkit\Contextual; +use CloudCreativity\Modules\Messaging\Sensitive; use DateTimeInterface; use DateTimeZone; use Generator; diff --git a/src/Bus/Loggable/ResultDecorator.php b/src/Bus/Loggable/ResultDecorator.php index 656cf837..0507085a 100644 --- a/src/Bus/Loggable/ResultDecorator.php +++ b/src/Bus/Loggable/ResultDecorator.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus\Loggable; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Bus\Loggable\Contextual; +use CloudCreativity\Modules\Contracts\Toolkit\Contextual; use CloudCreativity\Modules\Contracts\Toolkit\Result\Error; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; diff --git a/src/Bus/Loggable/SimpleContextFactory.php b/src/Bus/Loggable/SimpleContextFactory.php index 274e1b5c..d57d880e 100644 --- a/src/Bus/Loggable/SimpleContextFactory.php +++ b/src/Bus/Loggable/SimpleContextFactory.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final class SimpleContextFactory implements ContextFactory diff --git a/src/Bus/Logging/SanitizedMessage.php b/src/Bus/Logging/SanitizedMessage.php new file mode 100644 index 00000000..da3facbb --- /dev/null +++ b/src/Bus/Logging/SanitizedMessage.php @@ -0,0 +1,55 @@ + + */ +final readonly class SanitizedMessage implements IteratorAggregate +{ + public function __construct(private Message $message) + { + } + + /** + * @return Generator + */ + public function getIterator(): Generator + { + foreach ($this->cursor() as $key) { + yield $key => $this->message->{$key}; + } + } + + /** + * @return Generator + */ + private function cursor(): Generator + { + $reflect = new ReflectionClass($this->message); + + foreach ($reflect->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { + $attributes = $property->getAttributes(Sensitive::class); + if (count($attributes) === 0) { + yield $property->getName(); + } + } + } +} diff --git a/src/Bus/Logging/SanitizedResult.php b/src/Bus/Logging/SanitizedResult.php new file mode 100644 index 00000000..1272f8b9 --- /dev/null +++ b/src/Bus/Logging/SanitizedResult.php @@ -0,0 +1,70 @@ + $result + */ + public function __construct(private Result $result) + { + } + + public function success(): bool + { + return $this->result->didSucceed(); + } + + public function value(): ?Contextual + { + $value = $this->result->safe(); + + return $value instanceof Contextual ? $value : null; + } + + /** + * @return array + */ + public function meta(): array + { + return $this->result->meta()->all(); + } + + /** + * @return array> + */ + public function errors(): array + { + return array_map( + fn (Error $error): array => $this->error($error), + $this->result->errors()->all(), + ); + } + + /** + * @return array + */ + private function error(Error $error): array + { + return array_filter([ + 'code' => $error->code(), + 'key' => $error->key(), + 'message' => $error->message(), + ]); + } +} diff --git a/src/Bus/Middleware/LogInboundEvent.php b/src/Bus/Middleware/LogInboundEvent.php index e3dd9ce1..bd3d4923 100644 --- a/src/Bus/Middleware/LogInboundEvent.php +++ b/src/Bus/Middleware/LogInboundEvent.php @@ -16,7 +16,7 @@ use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Bus/Middleware/LogMessageDispatch.php b/src/Bus/Middleware/LogMessageDispatch.php index 914d3d48..62b9b702 100644 --- a/src/Bus/Middleware/LogMessageDispatch.php +++ b/src/Bus/Middleware/LogMessageDispatch.php @@ -13,11 +13,13 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; -use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; +use CloudCreativity\Modules\Bus\Logging\SanitizedMessage; +use CloudCreativity\Modules\Bus\Logging\SanitizedResult; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; -use CloudCreativity\Modules\Contracts\Messages\Command; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\Message; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; @@ -29,19 +31,23 @@ public function __construct( private LoggerInterface $logger, private string $dispatchLevel = LogLevel::DEBUG, private string $dispatchedLevel = LogLevel::INFO, - private ContextFactory $context = new SimpleContextFactory(), ) { } public function __invoke(Message $message, Closure $next): ?Result { $name = ModuleBasename::tryFrom($message)?->toString() ?? $message::class; - $key = ($message instanceof Command) ? 'command' : 'query'; + $key = match (true) { + $message instanceof Command => 'command', + $message instanceof Query => 'query', + $message instanceof IntegrationEvent => 'event', + default => 'message', + }; $this->logger->log( $this->dispatchLevel, "Bus dispatching {$name}.", - [$key => $this->context->make($message)], + [$key => new SanitizedMessage($message)], ); $result = $next($message); @@ -49,7 +55,7 @@ public function __invoke(Message $message, Closure $next): ?Result $this->logger->log( $this->dispatchedLevel, "Bus dispatched {$name}.", - $result ? ['result' => $this->context->make($result)] : [], + $result ? ['result' => new SanitizedResult($result)] : [], ); return $result; diff --git a/src/Bus/Middleware/SetupBeforeDispatch.php b/src/Bus/Middleware/SetupBeforeDispatch.php index 309cf5eb..13e846be 100644 --- a/src/Bus/Middleware/SetupBeforeDispatch.php +++ b/src/Bus/Middleware/SetupBeforeDispatch.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class SetupBeforeDispatch implements BusMiddleware diff --git a/src/Bus/Middleware/SetupBeforeEvent.php b/src/Bus/Middleware/SetupBeforeEvent.php index a567ef0f..80724c39 100644 --- a/src/Bus/Middleware/SetupBeforeEvent.php +++ b/src/Bus/Middleware/SetupBeforeEvent.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; final readonly class SetupBeforeEvent implements InboundEventMiddleware { diff --git a/src/Bus/Middleware/TearDownAfterDispatch.php b/src/Bus/Middleware/TearDownAfterDispatch.php index cef5475b..87a03cf6 100644 --- a/src/Bus/Middleware/TearDownAfterDispatch.php +++ b/src/Bus/Middleware/TearDownAfterDispatch.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class TearDownAfterDispatch implements BusMiddleware diff --git a/src/Bus/Middleware/TearDownAfterEvent.php b/src/Bus/Middleware/TearDownAfterEvent.php index 2db05bce..182fcaac 100644 --- a/src/Bus/Middleware/TearDownAfterEvent.php +++ b/src/Bus/Middleware/TearDownAfterEvent.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; final readonly class TearDownAfterEvent implements InboundEventMiddleware { diff --git a/src/Bus/Middleware/ValidateCommand.php b/src/Bus/Middleware/ValidateCommand.php index e9224709..801b5db9 100644 --- a/src/Bus/Middleware/ValidateCommand.php +++ b/src/Bus/Middleware/ValidateCommand.php @@ -16,7 +16,7 @@ use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/src/Bus/Middleware/ValidateQuery.php b/src/Bus/Middleware/ValidateQuery.php index 57ef9a39..e89578ed 100644 --- a/src/Bus/Middleware/ValidateQuery.php +++ b/src/Bus/Middleware/ValidateQuery.php @@ -16,7 +16,7 @@ use CloudCreativity\Modules\Contracts\Bus\Middleware\QueryMiddleware; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Toolkit\Result\Result; diff --git a/src/Bus/QueryDispatcher.php b/src/Bus/QueryDispatcher.php index 65b6bdd6..5ee1b95b 100644 --- a/src/Bus/QueryDispatcher.php +++ b/src/Bus/QueryDispatcher.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer as IQueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\Query; -use CloudCreativity\Modules\Contracts\Messages\QueryDispatcher as IQueryDispatcher; +use CloudCreativity\Modules\Contracts\Messaging\Query; +use CloudCreativity\Modules\Contracts\Messaging\QueryDispatcher as IQueryDispatcher; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; diff --git a/src/Bus/QueryHandler.php b/src/Bus/QueryHandler.php index 8ed1b9f8..ea27c167 100644 --- a/src/Bus/QueryHandler.php +++ b/src/Bus/QueryHandler.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Bus\QueryHandler as IQueryHandler; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; final readonly class QueryHandler implements IQueryHandler diff --git a/src/Bus/QueryHandlerContainer.php b/src/Bus/QueryHandlerContainer.php index 583346e0..3a10fa7d 100644 --- a/src/Bus/QueryHandlerContainer.php +++ b/src/Bus/QueryHandlerContainer.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer as IQueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; use Psr\Container\ContainerInterface; final class QueryHandlerContainer implements IQueryHandlerContainer diff --git a/src/Bus/SwallowInboundEvent.php b/src/Bus/SwallowInboundEvent.php index 0e7d5d6d..858f14ea 100644 --- a/src/Bus/SwallowInboundEvent.php +++ b/src/Bus/SwallowInboundEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Bus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; diff --git a/src/Bus/Validation/ValidationProcessor.php b/src/Bus/Validation/ValidationProcessor.php index 6040ad84..732cc115 100644 --- a/src/Bus/Validation/ValidationProcessor.php +++ b/src/Bus/Validation/ValidationProcessor.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Bus\Validation; -use CloudCreativity\Modules\Contracts\Messages\Command; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Processor; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/src/Bus/Validation/Validator.php b/src/Bus/Validation/Validator.php index 0b0635c0..8f0c6d3d 100644 --- a/src/Bus/Validation/Validator.php +++ b/src/Bus/Validation/Validator.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Bus\Validation; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator as IValidator; -use CloudCreativity\Modules\Contracts\Messages\Command; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Pipeline; use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors as IListOfErrors; diff --git a/src/Bus/WithCommand.php b/src/Bus/WithCommand.php index e68230c6..fc757b64 100644 --- a/src/Bus/WithCommand.php +++ b/src/Bus/WithCommand.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithCommand diff --git a/src/Bus/WithEvent.php b/src/Bus/WithEvent.php index cbaaa63c..4ebf8bb6 100644 --- a/src/Bus/WithEvent.php +++ b/src/Bus/WithEvent.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithEvent diff --git a/src/Bus/WithQuery.php b/src/Bus/WithQuery.php index 6f44f8ca..3f4a5979 100644 --- a/src/Bus/WithQuery.php +++ b/src/Bus/WithQuery.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Bus; use Attribute; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; #[Attribute(Attribute::TARGET_CLASS | Attribute::IS_REPEATABLE)] final readonly class WithQuery diff --git a/src/Contracts/Application/Ports/OutboundEventPublisher.php b/src/Contracts/Application/Ports/OutboundEventPublisher.php index e29424d9..795775ee 100644 --- a/src/Contracts/Application/Ports/OutboundEventPublisher.php +++ b/src/Contracts/Application/Ports/OutboundEventPublisher.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Application\Ports; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface OutboundEventPublisher { diff --git a/src/Contracts/Application/Ports/Queue.php b/src/Contracts/Application/Ports/Queue.php index 29246e30..23ddb531 100644 --- a/src/Contracts/Application/Ports/Queue.php +++ b/src/Contracts/Application/Ports/Queue.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Application\Ports; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; interface Queue { diff --git a/src/Contracts/Bus/CommandHandler.php b/src/Contracts/Bus/CommandHandler.php index 1c8b1ce6..76703a20 100644 --- a/src/Contracts/Bus/CommandHandler.php +++ b/src/Contracts/Bus/CommandHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface CommandHandler extends DispatchThroughMiddleware diff --git a/src/Contracts/Bus/CommandHandlerContainer.php b/src/Contracts/Bus/CommandHandlerContainer.php index 8b7ba50a..4d53ae81 100644 --- a/src/Contracts/Bus/CommandHandlerContainer.php +++ b/src/Contracts/Bus/CommandHandlerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; interface CommandHandlerContainer { diff --git a/src/Contracts/Bus/CommandQueuer.php b/src/Contracts/Bus/CommandQueuer.php index 3214ae0f..39f31498 100644 --- a/src/Contracts/Bus/CommandQueuer.php +++ b/src/Contracts/Bus/CommandQueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; interface CommandQueuer { diff --git a/src/Contracts/Bus/EventHandler.php b/src/Contracts/Bus/EventHandler.php index e6578cf5..952f19c3 100644 --- a/src/Contracts/Bus/EventHandler.php +++ b/src/Contracts/Bus/EventHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface EventHandler extends DispatchThroughMiddleware { diff --git a/src/Contracts/Bus/EventHandlerContainer.php b/src/Contracts/Bus/EventHandlerContainer.php index ed6c3ab6..15d4c53b 100644 --- a/src/Contracts/Bus/EventHandlerContainer.php +++ b/src/Contracts/Bus/EventHandlerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface EventHandlerContainer { diff --git a/src/Contracts/Bus/Loggable/ContextFactory.php b/src/Contracts/Bus/Loggable/ContextFactory.php index 3643cd78..6bbe2e45 100644 --- a/src/Contracts/Bus/Loggable/ContextFactory.php +++ b/src/Contracts/Bus/Loggable/ContextFactory.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Loggable; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface ContextFactory diff --git a/src/Contracts/Bus/Middleware/BusMiddleware.php b/src/Contracts/Bus/Middleware/BusMiddleware.php index 4e2d20aa..e9e6d9e7 100644 --- a/src/Contracts/Bus/Middleware/BusMiddleware.php +++ b/src/Contracts/Bus/Middleware/BusMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface BusMiddleware diff --git a/src/Contracts/Bus/Middleware/CommandMiddleware.php b/src/Contracts/Bus/Middleware/CommandMiddleware.php index e869b772..2b5ec4cb 100644 --- a/src/Contracts/Bus/Middleware/CommandMiddleware.php +++ b/src/Contracts/Bus/Middleware/CommandMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface CommandMiddleware diff --git a/src/Contracts/Bus/Middleware/InboundEventMiddleware.php b/src/Contracts/Bus/Middleware/InboundEventMiddleware.php index f72aede3..a87525c2 100644 --- a/src/Contracts/Bus/Middleware/InboundEventMiddleware.php +++ b/src/Contracts/Bus/Middleware/InboundEventMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface InboundEventMiddleware { diff --git a/src/Contracts/Bus/Middleware/QueryMiddleware.php b/src/Contracts/Bus/Middleware/QueryMiddleware.php index 1f19c3f5..e2d097ea 100644 --- a/src/Contracts/Bus/Middleware/QueryMiddleware.php +++ b/src/Contracts/Bus/Middleware/QueryMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface QueryMiddleware diff --git a/src/Contracts/Bus/QueryHandler.php b/src/Contracts/Bus/QueryHandler.php index b8ef35fa..f14230d0 100644 --- a/src/Contracts/Bus/QueryHandler.php +++ b/src/Contracts/Bus/QueryHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; interface QueryHandler extends DispatchThroughMiddleware diff --git a/src/Contracts/Bus/QueryHandlerContainer.php b/src/Contracts/Bus/QueryHandlerContainer.php index f0f8de9e..37640261 100644 --- a/src/Contracts/Bus/QueryHandlerContainer.php +++ b/src/Contracts/Bus/QueryHandlerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; interface QueryHandlerContainer { diff --git a/src/Contracts/Bus/Validation/Validator.php b/src/Contracts/Bus/Validation/Validator.php index c0e10713..879856c8 100644 --- a/src/Contracts/Bus/Validation/Validator.php +++ b/src/Contracts/Bus/Validation/Validator.php @@ -12,8 +12,8 @@ namespace CloudCreativity\Modules\Contracts\Bus\Validation; -use CloudCreativity\Modules\Contracts\Messages\Command; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors; interface Validator diff --git a/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php b/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php index 3c523e48..d87f1470 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; use Closure; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface OutboundEventMiddleware { diff --git a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php index ba6d00ae..9146f4b2 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandler.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface PublisherHandler { diff --git a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php index ac254f7b..f980b5a2 100644 --- a/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php +++ b/src/Contracts/Infrastructure/OutboundEventBus/PublisherHandlerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; interface PublisherHandlerContainer { diff --git a/src/Contracts/Infrastructure/Queue/Enqueuer.php b/src/Contracts/Infrastructure/Queue/Enqueuer.php index 7dabaf5e..30f83ac8 100644 --- a/src/Contracts/Infrastructure/Queue/Enqueuer.php +++ b/src/Contracts/Infrastructure/Queue/Enqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; interface Enqueuer { diff --git a/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php b/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php index e9ff4b73..dc087066 100644 --- a/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php +++ b/src/Contracts/Infrastructure/Queue/EnqueuerContainer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; interface EnqueuerContainer { diff --git a/src/Contracts/Infrastructure/Queue/QueueMiddleware.php b/src/Contracts/Infrastructure/Queue/QueueMiddleware.php index 805499be..5b97ba69 100644 --- a/src/Contracts/Infrastructure/Queue/QueueMiddleware.php +++ b/src/Contracts/Infrastructure/Queue/QueueMiddleware.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Contracts\Infrastructure\Queue; use Closure; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; interface QueueMiddleware { diff --git a/src/Contracts/Messages/Command.php b/src/Contracts/Messaging/Command.php similarity index 83% rename from src/Contracts/Messages/Command.php rename to src/Contracts/Messaging/Command.php index 3794fcb1..4cddcab8 100644 --- a/src/Contracts/Messages/Command.php +++ b/src/Contracts/Messaging/Command.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Messages; +namespace CloudCreativity\Modules\Contracts\Messaging; interface Command extends Message { diff --git a/src/Contracts/Messages/CommandDispatcher.php b/src/Contracts/Messaging/CommandDispatcher.php similarity index 89% rename from src/Contracts/Messages/CommandDispatcher.php rename to src/Contracts/Messaging/CommandDispatcher.php index b0f2c34d..707b09d9 100644 --- a/src/Contracts/Messages/CommandDispatcher.php +++ b/src/Contracts/Messaging/CommandDispatcher.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Messages; +namespace CloudCreativity\Modules\Contracts\Messaging; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; diff --git a/src/Contracts/Messages/InboundEventDispatcher.php b/src/Contracts/Messaging/InboundEventDispatcher.php similarity index 87% rename from src/Contracts/Messages/InboundEventDispatcher.php rename to src/Contracts/Messaging/InboundEventDispatcher.php index 4b86ccec..fc0e3bff 100644 --- a/src/Contracts/Messages/InboundEventDispatcher.php +++ b/src/Contracts/Messaging/InboundEventDispatcher.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Messages; +namespace CloudCreativity\Modules\Contracts\Messaging; interface InboundEventDispatcher { diff --git a/src/Contracts/Messages/IntegrationEvent.php b/src/Contracts/Messaging/IntegrationEvent.php similarity index 89% rename from src/Contracts/Messages/IntegrationEvent.php rename to src/Contracts/Messaging/IntegrationEvent.php index fc1e5df9..f16d27e7 100644 --- a/src/Contracts/Messages/IntegrationEvent.php +++ b/src/Contracts/Messaging/IntegrationEvent.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Messages; +namespace CloudCreativity\Modules\Contracts\Messaging; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/src/Contracts/Messages/Message.php b/src/Contracts/Messaging/Message.php similarity index 82% rename from src/Contracts/Messages/Message.php rename to src/Contracts/Messaging/Message.php index 0923f4d7..baa37c51 100644 --- a/src/Contracts/Messages/Message.php +++ b/src/Contracts/Messaging/Message.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Messages; +namespace CloudCreativity\Modules\Contracts\Messaging; interface Message { diff --git a/src/Contracts/Messages/Query.php b/src/Contracts/Messaging/Query.php similarity index 83% rename from src/Contracts/Messages/Query.php rename to src/Contracts/Messaging/Query.php index cd023433..c2f5c57e 100644 --- a/src/Contracts/Messages/Query.php +++ b/src/Contracts/Messaging/Query.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Messages; +namespace CloudCreativity\Modules\Contracts\Messaging; interface Query extends Message { diff --git a/src/Contracts/Messages/QueryDispatcher.php b/src/Contracts/Messaging/QueryDispatcher.php similarity index 89% rename from src/Contracts/Messages/QueryDispatcher.php rename to src/Contracts/Messaging/QueryDispatcher.php index 1c73ba90..53c5827d 100644 --- a/src/Contracts/Messages/QueryDispatcher.php +++ b/src/Contracts/Messaging/QueryDispatcher.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Messages; +namespace CloudCreativity\Modules\Contracts\Messaging; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; diff --git a/src/Contracts/Bus/Loggable/Contextual.php b/src/Contracts/Toolkit/Contextual.php similarity index 86% rename from src/Contracts/Bus/Loggable/Contextual.php rename to src/Contracts/Toolkit/Contextual.php index d434b9d0..8cbb0b0e 100644 --- a/src/Contracts/Bus/Loggable/Contextual.php +++ b/src/Contracts/Toolkit/Contextual.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Contracts\Bus\Loggable; +namespace CloudCreativity\Modules\Contracts\Toolkit; interface Contextual { diff --git a/src/Contracts/Toolkit/Identifiers/Identifier.php b/src/Contracts/Toolkit/Identifiers/Identifier.php index cdb1d3bc..504fb8bc 100644 --- a/src/Contracts/Toolkit/Identifiers/Identifier.php +++ b/src/Contracts/Toolkit/Identifiers/Identifier.php @@ -12,9 +12,10 @@ namespace CloudCreativity\Modules\Contracts\Toolkit\Identifiers; +use CloudCreativity\Modules\Contracts\Toolkit\Contextual; use Stringable; -interface Identifier extends Stringable +interface Identifier extends Stringable, Contextual { /** * Is the identifier the same as the provided identifier? @@ -37,9 +38,4 @@ public function toString(): string; * @return array-key */ public function key(): int|string; - - /** - * Get the value to use when adding the value to log context. - */ - public function context(): mixed; } diff --git a/src/Infrastructure/Monolog/ContextProcessor.php b/src/Infrastructure/Monolog/ContextProcessor.php new file mode 100644 index 00000000..d0b06ee6 --- /dev/null +++ b/src/Infrastructure/Monolog/ContextProcessor.php @@ -0,0 +1,80 @@ +context; + + foreach ($context as $key => $value) { + $context[$key] = match (true) { + $value instanceof SanitizedMessage => $this->message($value), + $value instanceof SanitizedResult => $this->result($value), + default => $this->process($value), + }; + } + + return $record->with(context: $context); + } + + private function process(mixed $value): mixed + { + if ($value instanceof Contextual) { + $value = $value->context(); + } + + return $this->parser ? $this->parser->parse($value) : $value; + } + + /** + * @return array + */ + private function message(SanitizedMessage $message): array + { + $values = []; + + foreach ($message as $key => $value) { + $values[$key] = $this->process($value); + } + + return $values; + } + + /** + * @return array + */ + private function result(SanitizedResult $result): array + { + $errors = $result->errors(); + + return array_filter([ + 'success' => $result->success(), + 'value' => $this->process($result->value()), + 'error' => count($errors) === 1 ? $errors[0] : null, + 'errors' => count($errors) > 1 ? $errors : null, + 'meta' => $this->process($result->meta()), + ], fn (mixed $value): bool => $value !== null); + } +} diff --git a/src/Infrastructure/Monolog/RecursiveParser.php b/src/Infrastructure/Monolog/RecursiveParser.php new file mode 100644 index 00000000..24f30902 --- /dev/null +++ b/src/Infrastructure/Monolog/RecursiveParser.php @@ -0,0 +1,37 @@ +innerParser->parse($value); + } + + $parsed = []; + + foreach ($value as $key => $item) { + if (is_string($key) || is_int($key)) { + $parsed[$key] = $this->parse($item); + } + } + + return $parsed; + } +} diff --git a/src/Infrastructure/Monolog/ValueParser.php b/src/Infrastructure/Monolog/ValueParser.php new file mode 100644 index 00000000..7f366ad1 --- /dev/null +++ b/src/Infrastructure/Monolog/ValueParser.php @@ -0,0 +1,18 @@ + + */ + private array $logs = []; + protected function setUp(): void { parent::setUp(); - $this->logger = $this->createMock(LoggerInterface::class); - $this->context = $this->createMock(ContextFactory::class); + $this->logger = $this->createStub(LoggerInterface::class); + $this->logger + ->method('log') + ->willReturnCallback(function ($level, $message, $context): bool { + $this->logs[] = [$level, $message, $context]; + return true; + }); + $this->message = new class () implements Command {}; } protected function tearDown(): void { parent::tearDown(); - unset($this->logger, $this->context, $this->message); + unset($this->logger, $this->message, $this->logs); } public function testWithDefaultLevels(): void { - $expected = Result::ok()->withMeta(['foobar' => 'bazbat']); + $expected = Result::ok(); $name = $this->message::class; - $logs = []; - - $this->logger - ->expects($this->exactly(2)) - ->method('log') - ->willReturnCallback(function ($level, $message, $context) use (&$logs): bool { - $logs[] = [$level, $message, $context]; - return true; - }); - - $context1 = ['message' => 'blah!']; - $context2 = ['result' => 'blah!']; - - $this->context - ->expects($this->exactly(2)) - ->method('make') - ->willReturnCallback(fn (object $in) => match ($in) { - $this->message => $context1, - $expected => $context2, - default => $this->fail('Unexpected object to convert to context.'), - }); - $middleware = new LogMessageDispatch($this->logger, context: $this->context); + $middleware = new LogMessageDispatch($this->logger); $actual = $middleware($this->message, function (Message $received) use ($expected) { $this->assertSame($this->message, $received); return $expected; }); $this->assertSame($expected, $actual); - $this->assertSame([ - [LogLevel::DEBUG, "Bus dispatching {$name}.", ['command' => $context1]], - [LogLevel::INFO, "Bus dispatched {$name}.", ['result' => $context2]], - ], $logs); + $this->assertEquals([ + [LogLevel::DEBUG, "Bus dispatching {$name}.", ['command' => new SanitizedMessage($this->message)]], + [LogLevel::INFO, "Bus dispatched {$name}.", ['result' => new SanitizedResult($expected)]], + ], $this->logs); } public function testWithCustomLevels(): void { $expected = Result::failed('Something went wrong.'); $name = $this->message::class; - $logs = []; - $this->logger - ->expects($this->exactly(2)) - ->method('log') - ->willReturnCallback(function ($level, $message, $context) use (&$logs): bool { - $logs[] = [$level, $message, $context]; - return true; - }); - - $context1 = ['message' => 'blah!']; - $context2 = ['result' => 'blah!']; - - $this->context - ->expects($this->exactly(2)) - ->method('make') - ->willReturnCallback(fn (object $in) => match ($in) { - $this->message => $context1, - $expected => $context2, - default => $this->fail('Unexpected object to convert to context.'), - }); - - - $middleware = new LogMessageDispatch($this->logger, LogLevel::NOTICE, LogLevel::WARNING, $this->context); + $middleware = new LogMessageDispatch($this->logger, LogLevel::NOTICE, LogLevel::WARNING); $actual = $middleware($this->message, function (Message $received) use ($expected) { $this->assertSame($this->message, $received); return $expected; }); $this->assertSame($expected, $actual); - $this->assertSame([ - [LogLevel::NOTICE, "Bus dispatching {$name}.", ['command' => $context1]], - [LogLevel::WARNING, "Bus dispatched {$name}.", ['result' => $context2]], - ], $logs); + $this->assertEquals([ + [LogLevel::NOTICE, "Bus dispatching {$name}.", ['command' => new SanitizedMessage($this->message)]], + [LogLevel::WARNING, "Bus dispatched {$name}.", ['result' => new SanitizedResult($expected)]], + ], $this->logs); } public function testItLogsAfterTheNextClosureIsInvoked(): void @@ -131,19 +98,7 @@ public function testItLogsAfterTheNextClosureIsInvoked(): void $expected = new LogicException(); $message = $this->createMock(Query::class); $name = $message::class; - - $this->context - ->expects($this->once()) - ->method('make') - ->with($this->identicalTo($message)) - ->willReturn($context = ['foo' => 'bar']); - - $this->logger - ->expects($this->once()) - ->method('log') - ->with(LogLevel::DEBUG, "Bus dispatching {$name}.", ['query' => $context]); - - $middleware = new LogMessageDispatch($this->logger, context: $this->context); + $middleware = new LogMessageDispatch($this->logger); try { $middleware($message, static function () use ($expected) { @@ -152,6 +107,9 @@ public function testItLogsAfterTheNextClosureIsInvoked(): void $this->fail('No exception thrown.'); } catch (LogicException $ex) { $this->assertSame($expected, $ex); + $this->assertEquals([ + [LogLevel::DEBUG, "Bus dispatching {$name}.", ['query' => new SanitizedMessage($message)]], + ], $this->logs); } } } diff --git a/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php b/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php index d400ddaa..25a1f02b 100644 --- a/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/SetupBeforeDispatchTest.php @@ -14,8 +14,8 @@ use Closure; use CloudCreativity\Modules\Bus\Middleware\SetupBeforeDispatch; -use CloudCreativity\Modules\Contracts\Messages\Command; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php b/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php index d7ab1fa8..d8d5d0bd 100644 --- a/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/TearDownAfterDispatchTest.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; use CloudCreativity\Modules\Bus\Middleware\TearDownAfterDispatch; -use CloudCreativity\Modules\Contracts\Messages\Command; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php b/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php index e6c30c26..4942dd53 100644 --- a/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php +++ b/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php @@ -15,7 +15,7 @@ use CloudCreativity\Modules\Bus\Middleware\ValidateCommand; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php b/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php index 2ce35904..962614d1 100644 --- a/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php +++ b/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php @@ -15,7 +15,7 @@ use CloudCreativity\Modules\Bus\Middleware\ValidateQuery; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/Bus/QueryDispatcherTest.php b/tests/Unit/Application/Bus/QueryDispatcherTest.php index cf1fa036..7a6595f4 100644 --- a/tests/Unit/Application/Bus/QueryDispatcherTest.php +++ b/tests/Unit/Application/Bus/QueryDispatcherTest.php @@ -15,7 +15,7 @@ use CloudCreativity\Modules\Bus\QueryDispatcher; use CloudCreativity\Modules\Contracts\Bus\QueryHandler; use CloudCreativity\Modules\Contracts\Bus\QueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Application/Bus/QueryHandlerContainerTest.php b/tests/Unit/Application/Bus/QueryHandlerContainerTest.php index fee8695c..24c83e83 100644 --- a/tests/Unit/Application/Bus/QueryHandlerContainerTest.php +++ b/tests/Unit/Application/Bus/QueryHandlerContainerTest.php @@ -15,7 +15,7 @@ use CloudCreativity\Modules\Bus\BusException; use CloudCreativity\Modules\Bus\QueryHandler; use CloudCreativity\Modules\Bus\QueryHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; diff --git a/tests/Unit/Application/Bus/TestCommand.php b/tests/Unit/Application/Bus/TestCommand.php index f09fba6e..e778cdf4 100644 --- a/tests/Unit/Application/Bus/TestCommand.php +++ b/tests/Unit/Application/Bus/TestCommand.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; class TestCommand implements Command { diff --git a/tests/Unit/Application/Bus/TestQuery.php b/tests/Unit/Application/Bus/TestQuery.php index 4ece49bf..4bd7666b 100644 --- a/tests/Unit/Application/Bus/TestQuery.php +++ b/tests/Unit/Application/Bus/TestQuery.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Query; class TestQuery implements Query { diff --git a/tests/Unit/Application/Bus/ValidatorTest.php b/tests/Unit/Application/Bus/ValidatorTest.php index b91f99f4..403f82e0 100644 --- a/tests/Unit/Application/Bus/ValidatorTest.php +++ b/tests/Unit/Application/Bus/ValidatorTest.php @@ -13,8 +13,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus; use CloudCreativity\Modules\Bus\Validation\Validator; -use CloudCreativity\Modules\Contracts\Messages\Command; -use CloudCreativity\Modules\Contracts\Messages\Query; +use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; diff --git a/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php b/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php index b510637c..1331479d 100644 --- a/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php +++ b/tests/Unit/Application/InboundEventBus/InboundEventDispatcherTest.php @@ -15,7 +15,7 @@ use CloudCreativity\Modules\Bus\InboundEventDispatcher; use CloudCreativity\Modules\Contracts\Bus\EventHandler; use CloudCreativity\Modules\Contracts\Bus\EventHandlerContainer; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php index 6ba8b240..8e493f19 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Bus\Loggable\ObjectDecorator; use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\TestOutboundEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use LogicException; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php index a2edc6af..f9bf2311 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/SetupBeforeEventTest.php @@ -14,7 +14,7 @@ use Closure; use CloudCreativity\Modules\Bus\Middleware\SetupBeforeEvent; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Result\Result; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php index 50a50154..1a55f553 100644 --- a/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php +++ b/tests/Unit/Application/InboundEventBus/Middleware/TearDownAfterEventTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus\Middleware; use CloudCreativity\Modules\Bus\Middleware\TearDownAfterEvent; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use PHPUnit\Framework\TestCase; use RuntimeException; diff --git a/tests/Unit/Application/InboundEventBus/TestInboundEvent.php b/tests/Unit/Application/InboundEventBus/TestInboundEvent.php index d0f8e80c..8456fb35 100644 --- a/tests/Unit/Application/InboundEventBus/TestInboundEvent.php +++ b/tests/Unit/Application/InboundEventBus/TestInboundEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php b/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php index 04d6ce11..a534f1ca 100644 --- a/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php +++ b/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php @@ -13,10 +13,10 @@ namespace CloudCreativity\Modules\Tests\Unit\Bus\Loggable; use CloudCreativity\Modules\Bus\Loggable\ObjectDecorator; -use CloudCreativity\Modules\Bus\Loggable\Sensitive; use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Messages\Message; +use CloudCreativity\Modules\Contracts\Messaging\Message; +use CloudCreativity\Modules\Messaging\Sensitive; use CloudCreativity\Modules\Tests\TestBackedEnum; use CloudCreativity\Modules\Tests\TestBackedIntEnum; use CloudCreativity\Modules\Tests\TestUnitEnum; diff --git a/tests/Unit/Bus/Loggable/ResultDecoratorTest.php b/tests/Unit/Bus/Loggable/ResultDecoratorTest.php index d7b0b498..3590b4b1 100644 --- a/tests/Unit/Bus/Loggable/ResultDecoratorTest.php +++ b/tests/Unit/Bus/Loggable/ResultDecoratorTest.php @@ -16,7 +16,7 @@ use CloudCreativity\Modules\Bus\Loggable\ResultDecorator; use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; -use CloudCreativity\Modules\Contracts\Bus\Loggable\Contextual; +use CloudCreativity\Modules\Contracts\Toolkit\Contextual; use CloudCreativity\Modules\Contracts\Toolkit\Result\Error as IError; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Tests\TestBackedEnum; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php b/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php index 24b4e975..177751f0 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/ClosurePublisherTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\ClosurePublisher; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php b/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php index 35e34d79..d907cf77 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\Middleware; use CloudCreativity\Modules\Bus\Loggable\ObjectDecorator; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware\LogOutboundEvent; use CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus\TestOutboundEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php b/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php index e8df86d3..8ca9e2a8 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use DateTimeImmutable; diff --git a/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php b/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php index 8b5beb3f..12de5c2a 100644 --- a/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/ClosureQueueTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Infrastructure\Queue\ClosureQueue; use CloudCreativity\Modules\Tests\Unit\Application\Bus\TestCommand; diff --git a/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php b/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php index 2a7ce890..26821351 100644 --- a/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/ComponentQueueTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Contracts\Infrastructure\Queue\Enqueuer; use CloudCreativity\Modules\Contracts\Infrastructure\Queue\EnqueuerContainer; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Infrastructure\Queue\ComponentQueue; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php b/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php index 6d311c4b..a478f17d 100644 --- a/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php +++ b/tests/Unit/Infrastructure/Queue/EnqueuerContainerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Infrastructure\Queue\Enqueuer; use CloudCreativity\Modules\Infrastructure\Queue\EnqueuerContainer; use CloudCreativity\Modules\Tests\Unit\Application\Bus\TestCommand; diff --git a/tests/Unit/Infrastructure/Queue/EnqueuerTest.php b/tests/Unit/Infrastructure/Queue/EnqueuerTest.php index 294907f6..7c18dd9b 100644 --- a/tests/Unit/Infrastructure/Queue/EnqueuerTest.php +++ b/tests/Unit/Infrastructure/Queue/EnqueuerTest.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Infrastructure\Queue\Enqueuer; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php b/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php index 61bf1f18..94a6968c 100644 --- a/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php +++ b/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue\Middleware; use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Infrastructure\Queue\Middleware\LogPushedToQueue; use LogicException; use PHPUnit\Framework\MockObject\MockObject; diff --git a/tests/Unit/Infrastructure/Queue/TestEnqueuer.php b/tests/Unit/Infrastructure/Queue/TestEnqueuer.php index ac2557b7..8a1b845d 100644 --- a/tests/Unit/Infrastructure/Queue/TestEnqueuer.php +++ b/tests/Unit/Infrastructure/Queue/TestEnqueuer.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; class TestEnqueuer { diff --git a/tests/Unit/Testing/FakeOutboundEventPublisherTest.php b/tests/Unit/Testing/FakeOutboundEventPublisherTest.php index 9b8b8e6a..e30b3c4c 100644 --- a/tests/Unit/Testing/FakeOutboundEventPublisherTest.php +++ b/tests/Unit/Testing/FakeOutboundEventPublisherTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Testing; use CloudCreativity\Modules\Contracts\Application\Ports\OutboundEventPublisher; -use CloudCreativity\Modules\Contracts\Messages\IntegrationEvent; +use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Testing\FakeOutboundEventPublisher; use LogicException; use PHPUnit\Framework\TestCase; diff --git a/tests/Unit/Testing/FakeQueueTest.php b/tests/Unit/Testing/FakeQueueTest.php index c3489e56..7d0356d8 100644 --- a/tests/Unit/Testing/FakeQueueTest.php +++ b/tests/Unit/Testing/FakeQueueTest.php @@ -13,7 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Testing; use CloudCreativity\Modules\Contracts\Application\Ports\Queue; -use CloudCreativity\Modules\Contracts\Messages\Command; +use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Testing\FakeQueue; use LogicException; use PHPUnit\Framework\TestCase; From 6fb027f9b9cabdbb66b2c53edc300aeb53cf724d Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Fri, 2 Jan 2026 06:26:19 +0000 Subject: [PATCH 4/8] wip: update uuid implementation to use interface --- src/Contracts/Messaging/IntegrationEvent.php | 2 +- src/Contracts/Toolkit/Identifiers/Uuid.php | 21 +++++++++++++++++++ .../Toolkit/Identifiers/UuidFactory.php | 11 +++++----- src/Toolkit/Identifiers/Guid.php | 12 ++++++----- src/Toolkit/Identifiers/GuidTypeMap.php | 3 ++- src/Toolkit/Identifiers/IsUuid.php | 11 ++++++++-- src/Toolkit/Identifiers/Uuid.php | 14 ++++++------- src/Toolkit/Identifiers/UuidFactory.php | 20 +++++++++++------- src/Toolkit/Identifiers/UuidV4.php | 12 +++++------ src/Toolkit/Identifiers/UuidV7.php | 12 +++++------ tests/Integration/Bus/NumbersAdded.php | 8 +++---- tests/Integration/Bus/NumbersDivided.php | 8 +++---- tests/Integration/Bus/NumbersSubtracted.php | 8 +++---- .../InboundEventBus/TestInboundEvent.php | 6 +++--- .../OutboundEventBus/TestOutboundEvent.php | 8 +++---- tests/Unit/Toolkit/Identifiers/GuidTest.php | 12 ++++++----- .../Toolkit/Identifiers/UuidFactoryTest.php | 8 ++++--- tests/Unit/Toolkit/Identifiers/UuidTest.php | 7 ++++--- tests/Unit/Toolkit/Identifiers/UuidV4Test.php | 11 +++++----- tests/Unit/Toolkit/Identifiers/UuidV7Test.php | 11 +++++----- 20 files changed, 123 insertions(+), 82 deletions(-) create mode 100644 src/Contracts/Toolkit/Identifiers/Uuid.php diff --git a/src/Contracts/Messaging/IntegrationEvent.php b/src/Contracts/Messaging/IntegrationEvent.php index f16d27e7..ad832864 100644 --- a/src/Contracts/Messaging/IntegrationEvent.php +++ b/src/Contracts/Messaging/IntegrationEvent.php @@ -12,7 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Messaging; -use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; +use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Uuid; use DateTimeImmutable; interface IntegrationEvent extends Message diff --git a/src/Contracts/Toolkit/Identifiers/Uuid.php b/src/Contracts/Toolkit/Identifiers/Uuid.php new file mode 100644 index 00000000..871a837c --- /dev/null +++ b/src/Contracts/Toolkit/Identifiers/Uuid.php @@ -0,0 +1,21 @@ + self::fromUuid($type, $id), is_string($id) => self::fromString($type, $id), is_int($id) => self::fromInteger($type, $id), @@ -82,7 +83,7 @@ public static function make(string|UnitEnum $type, int|string|Uuid|UuidInterface public function __construct( public string|UnitEnum $type, - public IntegerId|StringId|Uuid $id, + public IntegerId|IUuid|StringId $id, ) { Contracts::assert(!empty($this->type), 'Type must be a non-empty string.'); } @@ -129,8 +130,9 @@ public function equals(self $other): bool public function toString(string $glue = ':'): string { $type = enum_string($this->type); + $id = $this->id->toString(); - return "{$type}{$glue}{$this->id->value}"; + return "{$type}{$glue}{$id}"; } public function key(): string diff --git a/src/Toolkit/Identifiers/GuidTypeMap.php b/src/Toolkit/Identifiers/GuidTypeMap.php index c24b3654..293879f5 100644 --- a/src/Toolkit/Identifiers/GuidTypeMap.php +++ b/src/Toolkit/Identifiers/GuidTypeMap.php @@ -12,6 +12,7 @@ namespace CloudCreativity\Modules\Toolkit\Identifiers; +use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Uuid as IUuid; use Ramsey\Uuid\UuidInterface; use UnitEnum; @@ -39,7 +40,7 @@ public function define(string|UnitEnum $alias, string|UnitEnum $type): void /** * Get the GUID for the specified alias and id. */ - public function guidFor(string|UnitEnum $alias, int|string|Uuid|UuidInterface $id): Guid + public function guidFor(string|UnitEnum $alias, int|IUuid|string|UuidInterface $id): Guid { return Guid::make($this->typeFor($alias), $id); } diff --git a/src/Toolkit/Identifiers/IsUuid.php b/src/Toolkit/Identifiers/IsUuid.php index c13f25f3..53ef1089 100644 --- a/src/Toolkit/Identifiers/IsUuid.php +++ b/src/Toolkit/Identifiers/IsUuid.php @@ -13,6 +13,8 @@ namespace CloudCreativity\Modules\Toolkit\Identifiers; use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Uuid as IUuid; +use Ramsey\Uuid\UuidInterface; trait IsUuid { @@ -35,8 +37,8 @@ public function getBytes(): string public function is(?Identifier $other): bool { - if ($other instanceof self) { - return $this->equals($other); + if ($other instanceof IUuid) { + return $this->value->equals($other->toBase()); } return false; @@ -61,4 +63,9 @@ public function jsonSerialize(): string { return $this->value->toString(); } + + public function toBase(): UuidInterface + { + return $this->value; + } } diff --git a/src/Toolkit/Identifiers/Uuid.php b/src/Toolkit/Identifiers/Uuid.php index ee766d8d..f1c342e1 100644 --- a/src/Toolkit/Identifiers/Uuid.php +++ b/src/Toolkit/Identifiers/Uuid.php @@ -13,13 +13,13 @@ namespace CloudCreativity\Modules\Toolkit\Identifiers; use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Uuid as IUuid; use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\UuidFactory as IUuidFactory; use CloudCreativity\Modules\Toolkit\ContractException; -use JsonSerializable; use Ramsey\Uuid\Uuid as BaseUuid; use Ramsey\Uuid\UuidInterface as IBaseUuid; -final class Uuid implements Identifier, JsonSerializable +final class Uuid implements IUuid { use IsUuid; @@ -39,7 +39,7 @@ public static function getFactory(): IUuidFactory return self::$factory = new UuidFactory(); } - public static function from(IBaseUuid|Identifier|string|null $value): self + public static function from(IBaseUuid|Identifier|string|null $value): IUuid { $factory = self::getFactory(); @@ -50,10 +50,10 @@ public static function from(IBaseUuid|Identifier|string|null $value): self }; } - public static function tryFrom(IBaseUuid|Identifier|string|null $value): ?self + public static function tryFrom(IBaseUuid|Identifier|string|null $value): ?IUuid { return match(true) { - $value instanceof self => $value, + $value instanceof IUuid => $value, $value instanceof IBaseUuid => self::getFactory()->from($value), is_string($value) && BaseUuid::isValid($value) => self::getFactory()->fromString($value), default => null, @@ -63,7 +63,7 @@ public static function tryFrom(IBaseUuid|Identifier|string|null $value): ?self /** * Generate a random UUID, useful in tests. */ - public static function random(): self + public static function random(): UuidV4 { return self::getFactory()->uuid4(); } @@ -71,7 +71,7 @@ public static function random(): self /** * Create a nil UUID. */ - public static function nil(): self + public static function nil(): IUuid { return self::from(BaseUuid::NIL); } diff --git a/src/Toolkit/Identifiers/UuidFactory.php b/src/Toolkit/Identifiers/UuidFactory.php index b7e590d0..401b2f36 100644 --- a/src/Toolkit/Identifiers/UuidFactory.php +++ b/src/Toolkit/Identifiers/UuidFactory.php @@ -16,12 +16,16 @@ use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\UuidFactory as IUuidFactory; use CloudCreativity\Modules\Toolkit\ContractException; use DateTimeInterface; +use Ramsey\Uuid\Lazy\LazyUuidFromString; +use Ramsey\Uuid\Rfc4122\UuidV4 as BaseUuidV4; +use Ramsey\Uuid\Rfc4122\UuidV7 as BaseUuidV7; use Ramsey\Uuid\Type\Hexadecimal; use Ramsey\Uuid\Type\Integer as IntegerObject; use Ramsey\Uuid\Uuid as BaseUuid; use Ramsey\Uuid\UuidFactoryInterface as BaseUuidFactory; use Ramsey\Uuid\UuidInterface; use RuntimeException; +use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Uuid as IUuid; final readonly class UuidFactory implements IUuidFactory { @@ -32,10 +36,10 @@ public function __construct(?BaseUuidFactory $factory = null) $this->baseFactory = $factory ?? BaseUuid::getFactory(); } - public function from(Identifier|UuidInterface $uuid): Uuid + public function from(Identifier|UuidInterface $uuid): IUuid { return match(true) { - $uuid instanceof Uuid => $uuid, + $uuid instanceof IUuid => $uuid, $uuid instanceof UuidInterface => new Uuid($uuid), default => throw new ContractException( 'Unexpected identifier type, received: ' . get_debug_type($uuid), @@ -84,9 +88,11 @@ public function uuid3(string|UuidInterface $ns, string $name): Uuid return new Uuid($this->baseFactory->uuid3($ns, $name)); } - public function uuid4(): Uuid + public function uuid4(): UuidV4 { - return new Uuid($this->baseFactory->uuid4()); + $base = $this->baseFactory->uuid4(); + assert($base instanceof BaseUuidV4 || $base instanceof LazyUuidFromString); + return new UuidV4($base); } public function uuid5(string|UuidInterface $ns, string $name): Uuid @@ -99,12 +105,12 @@ public function uuid6(?Hexadecimal $node = null, ?int $clockSeq = null): Uuid return new Uuid($this->baseFactory->uuid6($node, $clockSeq)); } - public function uuid7(?DateTimeInterface $dateTime = null): Uuid + public function uuid7(?DateTimeInterface $dateTime = null): UuidV7 { if (method_exists($this->baseFactory, 'uuid7')) { $base = $this->baseFactory->uuid7($dateTime); - assert($base instanceof UuidInterface); - return new Uuid($base); + assert($base instanceof BaseUuidV7 || $base instanceof LazyUuidFromString); + return new UuidV7($base); } throw new RuntimeException('UUID version 7 is not supported by the underlying factory.'); diff --git a/src/Toolkit/Identifiers/UuidV4.php b/src/Toolkit/Identifiers/UuidV4.php index 1d43ff64..28398c32 100644 --- a/src/Toolkit/Identifiers/UuidV4.php +++ b/src/Toolkit/Identifiers/UuidV4.php @@ -13,23 +13,21 @@ namespace CloudCreativity\Modules\Toolkit\Identifiers; use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Uuid as IUuid; use CloudCreativity\Modules\Toolkit\ContractException; use CloudCreativity\Modules\Toolkit\Contracts; -use JsonSerializable; use Ramsey\Uuid\Lazy\LazyUuidFromString; use Ramsey\Uuid\Rfc4122\UuidV4 as BaseUuidV4; use Ramsey\Uuid\Uuid as BaseUuid; use Ramsey\Uuid\UuidInterface as IBaseUuid; -final class UuidV4 implements Identifier, JsonSerializable +final class UuidV4 implements IUuid { use IsUuid; public static function make(): self { - $uuid = BaseUuid::getFactory()->uuid4(); - assert($uuid instanceof BaseUuidV4 || $uuid instanceof LazyUuidFromString); - return new self($uuid); + return Uuid::getFactory()->uuid4(); } public static function from(IBaseUuid|Identifier|string|null $value): self @@ -43,7 +41,7 @@ public static function tryFrom(IBaseUuid|Identifier|string|null $value): ?self { $parsed = match (true) { $value instanceof self, $value instanceof IBaseUuid => $value, - $value instanceof Uuid => $value->value, + $value instanceof IUuid => $value->toBase(), is_string($value) && BaseUuid::isValid($value) => BaseUuid::getFactory()->fromString($value), default => null, }; @@ -55,7 +53,7 @@ public static function tryFrom(IBaseUuid|Identifier|string|null $value): ?self }; } - private function __construct(public readonly BaseUuidV4|LazyUuidFromString $value) + public function __construct(public readonly BaseUuidV4|LazyUuidFromString $value) { if ($this->value instanceof LazyUuidFromString) { Contracts::assert($this->value->getVersion() === 4); diff --git a/src/Toolkit/Identifiers/UuidV7.php b/src/Toolkit/Identifiers/UuidV7.php index 9dabc716..ce03fada 100644 --- a/src/Toolkit/Identifiers/UuidV7.php +++ b/src/Toolkit/Identifiers/UuidV7.php @@ -13,24 +13,22 @@ namespace CloudCreativity\Modules\Toolkit\Identifiers; use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Uuid as IUuid; use CloudCreativity\Modules\Toolkit\ContractException; use CloudCreativity\Modules\Toolkit\Contracts; use DateTimeInterface; -use JsonSerializable; use Ramsey\Uuid\Lazy\LazyUuidFromString; use Ramsey\Uuid\Rfc4122\UuidV7 as BaseUuidV7; use Ramsey\Uuid\Uuid as BaseUuid; use Ramsey\Uuid\UuidInterface as IBaseUuid; -final class UuidV7 implements Identifier, JsonSerializable +final class UuidV7 implements IUuid { use IsUuid; public static function make(?DateTimeInterface $date = null): self { - $uuid = BaseUuid::uuid7($date); - assert($uuid instanceof BaseUuidV7 || $uuid instanceof LazyUuidFromString); - return new self($uuid); + return Uuid::getFactory()->uuid7($date); } public static function from(IBaseUuid|Identifier|string|null $value): self @@ -44,7 +42,7 @@ public static function tryFrom(IBaseUuid|Identifier|string|null $value): ?self { $parsed = match (true) { $value instanceof self, $value instanceof IBaseUuid => $value, - $value instanceof Uuid => $value->value, + $value instanceof IUuid => $value->toBase(), is_string($value) && BaseUuid::isValid($value) => BaseUuid::getFactory()->fromString($value), default => null, }; @@ -56,7 +54,7 @@ public static function tryFrom(IBaseUuid|Identifier|string|null $value): ?self }; } - private function __construct(public readonly BaseUuidV7|LazyUuidFromString $value) + public function __construct(public readonly BaseUuidV7|LazyUuidFromString $value) { if ($this->value instanceof LazyUuidFromString) { Contracts::assert($this->value->getVersion() === 7); diff --git a/tests/Integration/Bus/NumbersAdded.php b/tests/Integration/Bus/NumbersAdded.php index e745ae66..11bd0fa5 100644 --- a/tests/Integration/Bus/NumbersAdded.php +++ b/tests/Integration/Bus/NumbersAdded.php @@ -14,12 +14,12 @@ use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; -use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; +use CloudCreativity\Modules\Toolkit\Identifiers\UuidV4; use DateTimeImmutable; final readonly class NumbersAdded implements IntegrationEvent { - public Uuid $uuid; + public UuidV4 $uuid; public function __construct( public int $a, @@ -28,10 +28,10 @@ public function __construct( public DateTimeImmutable $calculatedAt = new DateTimeImmutable(), ) { Contracts::assert($sum === ($a + $b), 'The sum must be equal to a plus b.'); - $this->uuid = Uuid::random(); + $this->uuid = UuidV4::make(); } - public function getUuid(): Uuid + public function getUuid(): UuidV4 { return $this->uuid; } diff --git a/tests/Integration/Bus/NumbersDivided.php b/tests/Integration/Bus/NumbersDivided.php index 75caebce..f99c5c2c 100644 --- a/tests/Integration/Bus/NumbersDivided.php +++ b/tests/Integration/Bus/NumbersDivided.php @@ -14,12 +14,12 @@ use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; -use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; +use CloudCreativity\Modules\Toolkit\Identifiers\UuidV4; use DateTimeImmutable; final readonly class NumbersDivided implements IntegrationEvent { - public Uuid $uuid; + public UuidV4 $uuid; public function __construct( public int $a, @@ -28,10 +28,10 @@ public function __construct( public DateTimeImmutable $calculatedAt = new DateTimeImmutable(), ) { Contracts::assert($sum == ($a / $b), 'The sum must be equal to a divided by b.'); - $this->uuid = Uuid::random(); + $this->uuid = UuidV4::make(); } - public function getUuid(): Uuid + public function getUuid(): UuidV4 { return $this->uuid; } diff --git a/tests/Integration/Bus/NumbersSubtracted.php b/tests/Integration/Bus/NumbersSubtracted.php index d9b07ff8..cfed34ce 100644 --- a/tests/Integration/Bus/NumbersSubtracted.php +++ b/tests/Integration/Bus/NumbersSubtracted.php @@ -14,12 +14,12 @@ use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\Contracts; -use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; +use CloudCreativity\Modules\Toolkit\Identifiers\UuidV4; use DateTimeImmutable; final readonly class NumbersSubtracted implements IntegrationEvent { - public Uuid $uuid; + public UuidV4 $uuid; public function __construct( public int $a, @@ -28,10 +28,10 @@ public function __construct( public DateTimeImmutable $calculatedAt = new DateTimeImmutable(), ) { Contracts::assert($sum === ($a - $b), 'The sum must be equal to a minus b.'); - $this->uuid = Uuid::random(); + $this->uuid = UuidV4::make(); } - public function getUuid(): Uuid + public function getUuid(): UuidV4 { return $this->uuid; } diff --git a/tests/Unit/Application/InboundEventBus/TestInboundEvent.php b/tests/Unit/Application/InboundEventBus/TestInboundEvent.php index 8456fb35..ba18ecf9 100644 --- a/tests/Unit/Application/InboundEventBus/TestInboundEvent.php +++ b/tests/Unit/Application/InboundEventBus/TestInboundEvent.php @@ -13,14 +13,14 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\InboundEventBus; use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; -use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; +use CloudCreativity\Modules\Toolkit\Identifiers\UuidV4; use DateTimeImmutable; class TestInboundEvent implements IntegrationEvent { - public function getUuid(): Uuid + public function getUuid(): UuidV4 { - return Uuid::random(); + return UuidV4::make(); } public function getOccurredAt(): DateTimeImmutable diff --git a/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php b/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php index 8ca9e2a8..8ec03222 100644 --- a/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php +++ b/tests/Unit/Infrastructure/OutboundEventBus/TestOutboundEvent.php @@ -13,12 +13,12 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\OutboundEventBus; use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; -use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; +use CloudCreativity\Modules\Toolkit\Identifiers\UuidV4; use DateTimeImmutable; class TestOutboundEvent implements IntegrationEvent { - public readonly Uuid $uuid; + public readonly UuidV4 $uuid; public readonly DateTimeImmutable $occurredAt; @@ -27,11 +27,11 @@ class TestOutboundEvent implements IntegrationEvent */ public function __construct() { - $this->uuid = Uuid::random(); + $this->uuid = UuidV4::make(); $this->occurredAt = new DateTimeImmutable(); } - public function getUuid(): Uuid + public function getUuid(): UuidV4 { return $this->uuid; } diff --git a/tests/Unit/Toolkit/Identifiers/GuidTest.php b/tests/Unit/Toolkit/Identifiers/GuidTest.php index e42ec70d..51bec62a 100644 --- a/tests/Unit/Toolkit/Identifiers/GuidTest.php +++ b/tests/Unit/Toolkit/Identifiers/GuidTest.php @@ -13,6 +13,7 @@ namespace CloudCreativity\Modules\Tests\Unit\Toolkit\Identifiers; use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Uuid as IUuid; use CloudCreativity\Modules\Tests\TestBackedEnum; use CloudCreativity\Modules\Tests\TestUnitEnum; use CloudCreativity\Modules\Toolkit\ContractException; @@ -20,6 +21,7 @@ use CloudCreativity\Modules\Toolkit\Identifiers\IntegerId; use CloudCreativity\Modules\Toolkit\Identifiers\StringId; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; +use CloudCreativity\Modules\Toolkit\Identifiers\UuidV4; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Ramsey\Uuid\Uuid as BaseUuid; @@ -115,7 +117,7 @@ public function testUuid(string|UnitEnum $type, string $value, string|UnitEnum $ $guid = Guid::fromUuid($type, $uuid->value); $this->assertSame($type, $guid->type); - $this->assertObjectEquals($uuid, $guid->id); + $this->assertTrue($uuid->is($guid->id)); $this->assertObjectEquals($guid, Guid::fromUuid($type, $uuid)); $this->assertSame($value . ':' . $uuid->toString(), $guid->toString()); $this->assertSame($value . ':' . $uuid->toString(), (string) $guid); @@ -132,11 +134,11 @@ public function testUuid(string|UnitEnum $type, string $value, string|UnitEnum $ } /** - * @return array + * @return array */ public static function makeProvider(): array { - $uuid = Uuid::random(); + $uuid = UuidV4::make(); return [ 'integer' => [123, new IntegerId(123)], @@ -148,10 +150,10 @@ public static function makeProvider(): array } #[DataProvider('makeProvider')] - public function testItMakesGuid(int|string|Uuid|UuidInterface $value, Identifier $expected): void + public function testItMakesGuid(int|IUuid|string|UuidInterface $value, Identifier $expected): void { $guid = Guid::make('SomeType', $value); - $this->assertObjectEquals($expected, $guid->id); + $this->assertTrue($expected->is($guid->id)); $this->assertSame($guid, Guid::from($guid)); $this->assertSame($guid, Guid::tryFrom($guid)); } diff --git a/tests/Unit/Toolkit/Identifiers/UuidFactoryTest.php b/tests/Unit/Toolkit/Identifiers/UuidFactoryTest.php index d7af207e..59e09ad0 100644 --- a/tests/Unit/Toolkit/Identifiers/UuidFactoryTest.php +++ b/tests/Unit/Toolkit/Identifiers/UuidFactoryTest.php @@ -16,6 +16,8 @@ use CloudCreativity\Modules\Toolkit\ContractException; use CloudCreativity\Modules\Toolkit\Identifiers\Uuid; use CloudCreativity\Modules\Toolkit\Identifiers\UuidFactory; +use CloudCreativity\Modules\Toolkit\Identifiers\UuidV4; +use CloudCreativity\Modules\Toolkit\Identifiers\UuidV7; use DateTimeImmutable; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; @@ -198,7 +200,7 @@ public function testUuid4(): void $uuid = $this->factory->uuid4(); - $this->assertInstanceOf(Uuid::class, $uuid); + $this->assertInstanceOf(UuidV4::class, $uuid); $this->assertSame($uuid->value, $base); } @@ -244,11 +246,11 @@ public function testUuid7(): void ->expects($this->once()) ->method('uuid7') ->with($this->identicalTo($date)) - ->willReturn($base = BaseUuid::uuid4()); + ->willReturn($base = BaseUuid::uuid7()); $uuid = $this->factory->uuid7($date); - $this->assertInstanceOf(Uuid::class, $uuid); + $this->assertInstanceOf(UuidV7::class, $uuid); $this->assertSame($uuid->value, $base); } diff --git a/tests/Unit/Toolkit/Identifiers/UuidTest.php b/tests/Unit/Toolkit/Identifiers/UuidTest.php index c211e7aa..b3505d25 100644 --- a/tests/Unit/Toolkit/Identifiers/UuidTest.php +++ b/tests/Unit/Toolkit/Identifiers/UuidTest.php @@ -51,8 +51,9 @@ public function test(): void public function testItIsEquals(): void { $base = RamseyUuid::uuid4(); + $id = new Uuid($base); - $this->assertObjectEquals($id = new Uuid($base), $other = Uuid::from($base)); + $this->assertTrue($id->is($other = Uuid::from($base))); $this->assertSame($id, Uuid::from($id)); $this->assertTrue($id->is($other)); $this->assertTrue($id->any(null, Uuid::random(), $other)); @@ -63,7 +64,7 @@ public function testItIsEquals(): void public function testItIsNotEqual(): void { $id = new Uuid(RamseyUuid::fromString('6dcbad65-ed92-4e60-973b-9ba58a022816')); - $this->assertFalse($id->equals($other = new Uuid( + $this->assertFalse($id->is($other = new Uuid( RamseyUuid::fromString('38c7be26-6887-4742-8b6b-7d07b30ca596'), ))); $this->assertFalse($id->is($other)); @@ -164,6 +165,6 @@ public function testNil(): void $base = RamseyUuid::fromString(RamseyUuid::NIL); $actual = Uuid::nil(); - $this->assertTrue($actual->value->equals($base)); + $this->assertTrue($actual->toBase()->equals($base)); } } diff --git a/tests/Unit/Toolkit/Identifiers/UuidV4Test.php b/tests/Unit/Toolkit/Identifiers/UuidV4Test.php index 9d183582..d9a86bee 100644 --- a/tests/Unit/Toolkit/Identifiers/UuidV4Test.php +++ b/tests/Unit/Toolkit/Identifiers/UuidV4Test.php @@ -46,22 +46,23 @@ public function test(): void public function testItIsEquals(): void { $base = RamseyUuid::uuid4(); + $id = UuidV4::from($base); - $this->assertObjectEquals($id = UuidV4::from($base), $other = UuidV4::from($base)); + $this->assertTrue($id->is($other = UuidV4::from($base))); $this->assertSame($id, UuidV4::from($id)); $this->assertTrue($id->is($other)); $this->assertTrue($id->any(null, UuidV4::make(), $other)); $this->assertEquals($id, UuidV4::tryFrom($base)); $this->assertSame($id, UuidV4::tryFrom($id)); + $this->assertTrue($id->is(new Uuid($base))); } public function testItIsNotEqual(): void { - $id = UuidV4::from($base = RamseyUuid::fromString('6dcbad65-ed92-4e60-973b-9ba58a022816')); - $this->assertFalse($id->equals($other = UuidV4::from( + $id = UuidV4::from(RamseyUuid::fromString('6dcbad65-ed92-4e60-973b-9ba58a022816')); + $this->assertFalse($id->is($other = UuidV4::from( RamseyUuid::fromString('38c7be26-6887-4742-8b6b-7d07b30ca596'), ))); - $this->assertFalse($id->is(new Uuid($base))); // not equal as not specifically UuidV4 $this->assertFalse($id->is($other)); $this->assertFalse($id->any(null, UuidV4::make(), $other)); } @@ -109,7 +110,7 @@ public function testFromWithString(): void { $base = RamseyUuid::fromString('6dcbad65-ed92-4e60-973b-9ba58a022816'); - $this->assertObjectEquals(UuidV4::from($base), UuidV4::from($base->toString())); + $this->assertTrue(UuidV4::from($base)->is(UuidV4::from($base->toString()))); } public function testTryFromWithString(): void diff --git a/tests/Unit/Toolkit/Identifiers/UuidV7Test.php b/tests/Unit/Toolkit/Identifiers/UuidV7Test.php index b914a93e..92ccbfca 100644 --- a/tests/Unit/Toolkit/Identifiers/UuidV7Test.php +++ b/tests/Unit/Toolkit/Identifiers/UuidV7Test.php @@ -46,22 +46,23 @@ public function test(): void public function testItIsEquals(): void { $base = RamseyUuid::uuid7(); + $id = UuidV7::from($base); - $this->assertObjectEquals($id = UuidV7::from($base), $other = UuidV7::from($base)); + $this->assertTrue($id->is($other = UuidV7::from($base))); $this->assertSame($id, UuidV7::from($id)); $this->assertTrue($id->is($other)); $this->assertTrue($id->any(null, UuidV7::make(), $other)); $this->assertEquals($id, UuidV7::tryFrom($base)); $this->assertSame($id, UuidV7::tryFrom($id)); + $this->assertTrue($id->is(new Uuid($base))); } public function testItIsNotEqual(): void { - $id = UuidV7::from($base = RamseyUuid::fromString('019b7acc-aff8-7f70-adc9-e9c7f632e6df')); - $this->assertFalse($id->equals($other = UuidV7::from( + $id = UuidV7::from(RamseyUuid::fromString('019b7acc-aff8-7f70-adc9-e9c7f632e6df')); + $this->assertFalse($id->is($other = UuidV7::from( RamseyUuid::fromString('019b7acd-0f6f-7828-a1cf-94c34a239594'), ))); - $this->assertFalse($id->is(new Uuid($base))); // not equal as not specifically UuidV7 $this->assertFalse($id->is($other)); $this->assertFalse($id->any(null, UuidV7::make(), $other)); } @@ -109,7 +110,7 @@ public function testFromWithString(): void { $base = RamseyUuid::fromString('019b7acc-aff8-7f70-adc9-e9c7f632e6df'); - $this->assertObjectEquals(UuidV7::from($base), UuidV7::from($base->toString())); + $this->assertTrue(UuidV7::from($base)->is(UuidV7::from($base->toString()))); } public function testTryFromWithString(): void From b8a359906b7c876b4c38b13fe9876b1e8852e94c Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Mon, 5 Jan 2026 13:46:32 +0000 Subject: [PATCH 5/8] wip: allow validator to use psr container for rules --- .../DomainEventDispatching/Dispatcher.php | 4 +- src/Bus/Validation/Validator.php | 9 +++- tests/Unit/Application/Bus/ValidatorTest.php | 47 +++++++++++++++++++ 3 files changed, 57 insertions(+), 3 deletions(-) diff --git a/src/Application/DomainEventDispatching/Dispatcher.php b/src/Application/DomainEventDispatching/Dispatcher.php index 1007db3e..f74ce6f3 100644 --- a/src/Application/DomainEventDispatching/Dispatcher.php +++ b/src/Application/DomainEventDispatching/Dispatcher.php @@ -13,12 +13,12 @@ namespace CloudCreativity\Modules\Application\DomainEventDispatching; use Closure; +use CloudCreativity\Modules\Bus\PsrPipeContainer; use CloudCreativity\Modules\Contracts\Application\DomainEventDispatching\ListenerContainer as IListenerContainer; use CloudCreativity\Modules\Contracts\Domain\Events\DomainEvent; use CloudCreativity\Modules\Contracts\Domain\Events\DomainEventDispatcher; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer as IPipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\MiddlewareProcessor; -use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; use CloudCreativity\Modules\Toolkit\Pipeline\Through; use Generator; @@ -51,7 +51,7 @@ public function __construct( $listeners; $this->middleware = $middleware === null && $listeners instanceof ContainerInterface ? - new PipeContainer($listeners) : + new PsrPipeContainer($listeners) : $middleware; $this->autowire(); diff --git a/src/Bus/Validation/Validator.php b/src/Bus/Validation/Validator.php index 8f0c6d3d..4203fc39 100644 --- a/src/Bus/Validation/Validator.php +++ b/src/Bus/Validation/Validator.php @@ -12,6 +12,7 @@ namespace CloudCreativity\Modules\Bus\Validation; +use CloudCreativity\Modules\Bus\PsrPipeContainer; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator as IValidator; use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Messaging\Query; @@ -20,9 +21,12 @@ use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors as IListOfErrors; use CloudCreativity\Modules\Toolkit\Pipeline\PipelineBuilder; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; +use Psr\Container\ContainerInterface; final class Validator implements IValidator { + private readonly ?PipeContainer $rules; + /** * @var iterable */ @@ -30,8 +34,11 @@ final class Validator implements IValidator private bool $stopOnFirstFailure = false; - public function __construct(private readonly ?PipeContainer $rules = null) + public function __construct(ContainerInterface|PipeContainer|null $rules = null) { + $this->rules = $rules instanceof ContainerInterface + ? new PsrPipeContainer($rules) + : $rules; } public function using(iterable $rules): static diff --git a/tests/Unit/Application/Bus/ValidatorTest.php b/tests/Unit/Application/Bus/ValidatorTest.php index 403f82e0..cf9a40f6 100644 --- a/tests/Unit/Application/Bus/ValidatorTest.php +++ b/tests/Unit/Application/Bus/ValidatorTest.php @@ -21,6 +21,7 @@ use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; +use Psr\Container\ContainerInterface; class ValidatorTest extends TestCase { @@ -81,6 +82,52 @@ public function testItValidatesMessage(string $message): void $this->assertSame([$error1, $error2, $error3], $actual->all()); } + /** + * @param class-string $message + */ + #[DataProvider('messageProvider')] + public function testItValidatesMessageUsingPsrContainer(string $message): void + { + /** @var (Command&MockObject)|(MockObject&Query) $query */ + $query = $this->createMock($message); + $error1 = new Error(null, 'Message 1'); + $error2 = new Error(null, 'Message 2'); + $error3 = new Error(null, 'Message 3'); + + $a = function ($actual) use ($query, $error1): ListOfErrors { + $this->assertSame($query, $actual); + return new ListOfErrors($error1); + }; + + $b = function ($actual) use ($query): ?ListOfErrors { + $this->assertSame($query, $actual); + return null; + }; + + $c = function ($actual) use ($query, $error2, $error3): ListOfErrors { + $this->assertSame($query, $actual); + return new ListOfErrors($error2, $error3); + }; + + $rules = $this->createMock(ContainerInterface::class); + $rules + ->expects($this->exactly(2)) + ->method('get') + ->willReturnCallback(fn (string $name) => match ($name) { + 'Rule2' => $b, + 'Rule3' => $c, + default => $this->fail('Unexpected rule name: ' . $name), + }); + + $validator = new Validator(rules: $rules); + $actual = $validator + ->using([$a, 'Rule2', 'Rule3']) + ->validate($query); + + $this->assertInstanceOf(ListOfErrors::class, $actual); + $this->assertSame([$error1, $error2, $error3], $actual->all()); + } + /** * @param class-string $message */ From e1f5464b13aeed194634b301bfc3502d734d4527 Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Mon, 5 Jan 2026 14:16:09 +0000 Subject: [PATCH 6/8] wip: allow validation of any message type --- ...alidateCommand.php => ValidateMessage.php} | 39 ++-- src/Bus/Middleware/ValidateQuery.php | 54 ----- src/Bus/Validation/ValidationProcessor.php | 22 +- src/Bus/Validation/Validator.php | 5 +- src/Bus/Validation/WithRules.php | 26 +++ src/Contracts/Bus/Validation/Validator.php | 5 +- ...ommandTest.php => ValidateMessageTest.php} | 38 ++-- .../Bus/Middleware/ValidateQueryTest.php | 210 ------------------ tests/Unit/Application/Bus/ValidatorTest.php | 66 +++--- 9 files changed, 120 insertions(+), 345 deletions(-) rename src/Bus/Middleware/{ValidateCommand.php => ValidateMessage.php} (55%) delete mode 100644 src/Bus/Middleware/ValidateQuery.php create mode 100644 src/Bus/Validation/WithRules.php rename tests/Unit/Application/Bus/Middleware/{ValidateCommandTest.php => ValidateMessageTest.php} (84%) delete mode 100644 tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php diff --git a/src/Bus/Middleware/ValidateCommand.php b/src/Bus/Middleware/ValidateMessage.php similarity index 55% rename from src/Bus/Middleware/ValidateCommand.php rename to src/Bus/Middleware/ValidateMessage.php index 801b5db9..0e4f162b 100644 --- a/src/Bus/Middleware/ValidateCommand.php +++ b/src/Bus/Middleware/ValidateMessage.php @@ -13,41 +13,50 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware; +use CloudCreativity\Modules\Bus\Validation\WithRules; +use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; -use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result as IResult; use CloudCreativity\Modules\Toolkit\Result\Result; +use ReflectionClass; -abstract class ValidateCommand implements CommandMiddleware +abstract class ValidateMessage implements BusMiddleware { - /** - * Get the rules for the validation. - * - * @return iterable - */ - abstract protected function rules(): iterable; - public function __construct(private readonly Validator $validator) { } - public function __invoke(Command $command, Closure $next): IResult + public function __invoke(Message $message, Closure $next): ?IResult { $errors = $this->validator ->using($this->rules()) - ->stopOnFirstFailure($this->stopOnFirstFailure($command)) - ->validate($command); + ->stopOnFirstFailure($this->stopOnFirstFailure($message)) + ->validate($message); if ($errors->isNotEmpty()) { return Result::failed($errors); } - return $next($command); + return $next($message); + } + + /** + * Get the rules for the validation. + * + * @return iterable + */ + protected function rules(): iterable + { + $reflection = new ReflectionClass($this); + + foreach ($reflection->getAttributes(WithRules::class) as $attribute) { + yield from $attribute->newInstance()->rules; + } } - protected function stopOnFirstFailure(Command $command): bool + protected function stopOnFirstFailure(Message $message): bool { return $this instanceof Bail; } diff --git a/src/Bus/Middleware/ValidateQuery.php b/src/Bus/Middleware/ValidateQuery.php deleted file mode 100644 index e89578ed..00000000 --- a/src/Bus/Middleware/ValidateQuery.php +++ /dev/null @@ -1,54 +0,0 @@ - - */ - abstract protected function rules(): iterable; - - public function __construct(private readonly Validator $validator) - { - } - - public function __invoke(Query $query, Closure $next): IResult - { - $errors = $this->validator - ->using($this->rules()) - ->stopOnFirstFailure($this->stopOnFirstFailure($query)) - ->validate($query); - - if ($errors->isNotEmpty()) { - return Result::failed($errors); - } - - return $next($query); - } - - protected function stopOnFirstFailure(Query $query): bool - { - return $this instanceof Bail; - } -} diff --git a/src/Bus/Validation/ValidationProcessor.php b/src/Bus/Validation/ValidationProcessor.php index 732cc115..ab9f9bb6 100644 --- a/src/Bus/Validation/ValidationProcessor.php +++ b/src/Bus/Validation/ValidationProcessor.php @@ -12,9 +12,11 @@ namespace CloudCreativity\Modules\Bus\Validation; -use CloudCreativity\Modules\Contracts\Messaging\Command; -use CloudCreativity\Modules\Contracts\Messaging\Query; +use CloudCreativity\Modules\Bus\BusException; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Processor; +use CloudCreativity\Modules\Contracts\Toolkit\Result\Error as IError; +use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors as IListOfErrors; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; final readonly class ValidationProcessor implements Processor @@ -24,20 +26,24 @@ public function __construct(private bool $stopOnFirstFailure = false) } /** - * @param (callable(Command|Query): ?ListOfErrors) ...$stages + * @param callable(Message): (IError|IListOfErrors|null) ...$stages */ - public function process(mixed $payload, callable ...$stages): ListOfErrors + public function process(mixed $payload, callable ...$stages): IListOfErrors { - assert($payload instanceof Command || $payload instanceof Query); + if (!$payload instanceof Message) { + throw new BusException('Expecting a message to validate.'); + } $errors = new ListOfErrors(); foreach ($stages as $stage) { $result = $stage($payload); - if ($result) { - $errors = $errors->merge($result); - } + $errors = match (true) { + $result instanceof IListOfErrors => $errors->merge($result), + $result instanceof IError => $errors->push($result), + $result === null => $errors, + }; if ($this->stopOnFirstFailure && $errors->isNotEmpty()) { return $errors; diff --git a/src/Bus/Validation/Validator.php b/src/Bus/Validation/Validator.php index 4203fc39..9cd5b21e 100644 --- a/src/Bus/Validation/Validator.php +++ b/src/Bus/Validation/Validator.php @@ -14,8 +14,7 @@ use CloudCreativity\Modules\Bus\PsrPipeContainer; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator as IValidator; -use CloudCreativity\Modules\Contracts\Messaging\Command; -use CloudCreativity\Modules\Contracts\Messaging\Query; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\Pipeline; use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors as IListOfErrors; @@ -55,7 +54,7 @@ public function stopOnFirstFailure(bool $stop = true): static return $this; } - public function validate(Command|Query $message): IListOfErrors + public function validate(Message $message): IListOfErrors { $errors = $this ->getPipeline() diff --git a/src/Bus/Validation/WithRules.php b/src/Bus/Validation/WithRules.php new file mode 100644 index 00000000..078abd0f --- /dev/null +++ b/src/Bus/Validation/WithRules.php @@ -0,0 +1,26 @@ + $rules + */ + public function __construct(public readonly array $rules) + { + } +} diff --git a/src/Contracts/Bus/Validation/Validator.php b/src/Contracts/Bus/Validation/Validator.php index 879856c8..78be603c 100644 --- a/src/Contracts/Bus/Validation/Validator.php +++ b/src/Contracts/Bus/Validation/Validator.php @@ -12,8 +12,7 @@ namespace CloudCreativity\Modules\Contracts\Bus\Validation; -use CloudCreativity\Modules\Contracts\Messaging\Command; -use CloudCreativity\Modules\Contracts\Messaging\Query; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Result\ListOfErrors; interface Validator @@ -36,5 +35,5 @@ public function stopOnFirstFailure(bool $stop = true): static; /** * Validate the provided message. */ - public function validate(Command|Query $message): ListOfErrors; + public function validate(Message $message): ListOfErrors; } diff --git a/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php b/tests/Unit/Application/Bus/Middleware/ValidateMessageTest.php similarity index 84% rename from tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php rename to tests/Unit/Application/Bus/Middleware/ValidateMessageTest.php index 4942dd53..2a0ac6d1 100644 --- a/tests/Unit/Application/Bus/Middleware/ValidateCommandTest.php +++ b/tests/Unit/Application/Bus/Middleware/ValidateMessageTest.php @@ -12,24 +12,26 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; -use CloudCreativity\Modules\Bus\Middleware\ValidateCommand; +use CloudCreativity\Modules\Bus\Middleware\ValidateMessage; use CloudCreativity\Modules\Contracts\Bus\Validation\Bail; use CloudCreativity\Modules\Contracts\Bus\Validation\Validator; use CloudCreativity\Modules\Contracts\Messaging\Command; -use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; +use CloudCreativity\Modules\Contracts\Messaging\Message; +use CloudCreativity\Modules\Contracts\Messaging\Query; +use CloudCreativity\Modules\Toolkit\Result\Result; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; -class ValidateCommandTest extends TestCase +class ValidateMessageTest extends TestCase { /** * @var MockObject&Validator */ private Validator $validator; - private ValidateCommand $middleware; + private ValidateMessage $middleware; protected function setUp(): void { @@ -37,7 +39,7 @@ protected function setUp(): void $this->validator = $this->createMock(Validator::class); - $this->middleware = new class ($this->validator) extends ValidateCommand { + $this->middleware = new class ($this->validator) extends ValidateMessage { /** * @return iterable */ @@ -51,8 +53,8 @@ protected function rules(): iterable public function testItSucceeds(): void { $rules = []; - $command = $this->createMock(Command::class); - $expected = $this->createMock(Result::class); + $command = $this->createStub(Command::class); + $expected = Result::ok(); $this->validator ->expects($this->once()) @@ -104,7 +106,7 @@ public function testItFails(): void $this->validator ->expects($this->once()) ->method('validate') - ->with($command = $this->createMock(Command::class)) + ->with($command = $this->createStub(Query::class)) ->willReturn($errors = new ListOfErrors(new Error(null, 'Something went wrong.'))); $next = function () { @@ -113,13 +115,13 @@ public function testItFails(): void $result = ($this->middleware)($command, $next); - $this->assertTrue($result->didFail()); + $this->assertTrue($result?->didFail()); $this->assertSame($errors, $result->errors()); } public function testItStopsOnFirstFailureViaBail(): void { - $this->middleware = new class ($this->validator) extends ValidateCommand implements Bail { + $this->middleware = new class ($this->validator) extends ValidateMessage implements Bail { /** * @return iterable */ @@ -143,7 +145,7 @@ protected function rules(): iterable $this->validator ->expects($this->once()) ->method('validate') - ->with($command = $this->createMock(Command::class)) + ->with($command = $this->createStub(Message::class)) ->willReturn($errors = new ListOfErrors(new Error(null, 'Something went wrong.'))); $next = function () { @@ -152,16 +154,16 @@ protected function rules(): iterable $result = ($this->middleware)($command, $next); - $this->assertTrue($result->didFail()); + $this->assertTrue($result?->didFail()); $this->assertSame($errors, $result->errors()); } public function testItStopsOnFirstFailure(): void { - $command = $this->createMock(Command::class); + $command = $this->createStub(Command::class); - $this->middleware = new class ($command, $this->validator) extends ValidateCommand { - public function __construct(private Command $command, Validator $validator) + $this->middleware = new class ($command, $this->validator) extends ValidateMessage { + public function __construct(private Message $message, Validator $validator) { parent::__construct($validator); } @@ -174,9 +176,9 @@ protected function rules(): iterable return ['foo', 'bar']; } - protected function stopOnFirstFailure(Command $command): bool + protected function stopOnFirstFailure(Message $message): bool { - return $this->command === $command; + return $this->message === $message; } }; @@ -203,7 +205,7 @@ protected function stopOnFirstFailure(Command $command): bool $result = ($this->middleware)($command, $next); - $this->assertTrue($result->didFail()); + $this->assertTrue($result?->didFail()); $this->assertSame($errors, $result->errors()); } } diff --git a/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php b/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php deleted file mode 100644 index 962614d1..00000000 --- a/tests/Unit/Application/Bus/Middleware/ValidateQueryTest.php +++ /dev/null @@ -1,210 +0,0 @@ -validator = $this->createMock(Validator::class); - - $this->middleware = new class ($this->validator) extends ValidateQuery { - /** - * @return iterable - */ - protected function rules(): iterable - { - return ['foobar', 'bazbat']; - } - }; - } - - public function testItSucceeds(): void - { - $rules = []; - $query = $this->createMock(Query::class); - $expected = $this->createMock(Result::class); - - $this->validator - ->expects($this->once()) - ->method('using') - ->with($this->callback(function (array $actual) use (&$rules): bool { - $rules = $actual; - return true; - })) - ->willReturnSelf(); - - $this->validator - ->expects($this->once()) - ->method('stopOnFirstFailure') - ->with(false) - ->willReturnSelf(); - - $this->validator - ->expects($this->once()) - ->method('validate') - ->with($this->callback(function (Query $actual) use ($query, &$rules): bool { - $this->assertSame(['foobar', 'bazbat'], $rules); - $this->assertSame($query, $actual); - return true; - })) - ->willReturn(new ListOfErrors()); - - $next = function ($actual) use ($query, $expected) { - $this->assertSame($query, $actual); - return $expected; - }; - - $actual = ($this->middleware)($query, $next); - - $this->assertSame($expected, $actual); - } - - public function testItFails(): void - { - $this->validator - ->expects($this->once()) - ->method('using') - ->willReturnSelf(); - - $this->validator - ->expects($this->once()) - ->method('stopOnFirstFailure') - ->with(false) - ->willReturnSelf(); - - $this->validator - ->expects($this->once()) - ->method('validate') - ->with($query = $this->createMock(Query::class)) - ->willReturn($errors = new ListOfErrors(new Error(null, 'Something went wrong.'))); - - $next = function () { - throw new \LogicException('Not expecting next closure to be called.'); - }; - - $result = ($this->middleware)($query, $next); - - $this->assertTrue($result->didFail()); - $this->assertSame($errors, $result->errors()); - } - - public function testItStopsOnFirstFailureViaBail(): void - { - $this->middleware = new class ($this->validator) extends ValidateQuery implements Bail { - /** - * @return iterable - */ - protected function rules(): iterable - { - return ['foobar', 'bazbat']; - } - }; - - $this->validator - ->expects($this->once()) - ->method('using') - ->willReturnSelf(); - - $this->validator - ->expects($this->once()) - ->method('stopOnFirstFailure') - ->with(true) - ->willReturnSelf(); - - $this->validator - ->expects($this->once()) - ->method('validate') - ->with($query = $this->createMock(Query::class)) - ->willReturn($errors = new ListOfErrors(new Error(null, 'Something went wrong.'))); - - $next = function () { - throw new \LogicException('Not expecting next closure to be called.'); - }; - - $result = ($this->middleware)($query, $next); - - $this->assertTrue($result->didFail()); - $this->assertSame($errors, $result->errors()); - } - - public function testItStopsOnFirstFailure(): void - { - $query = $this->createMock(Query::class); - - $this->middleware = new class ($query, $this->validator) extends ValidateQuery { - public function __construct(private Query $query, Validator $validator) - { - parent::__construct($validator); - } - - /** - * @return iterable - */ - protected function rules(): iterable - { - return ['foobar', 'bazbat']; - } - - protected function stopOnFirstFailure(Query $query): bool - { - return $this->query === $query; - } - }; - - $this->validator - ->expects($this->once()) - ->method('using') - ->willReturnSelf(); - - $this->validator - ->expects($this->once()) - ->method('stopOnFirstFailure') - ->with(true) - ->willReturnSelf(); - - $this->validator - ->expects($this->once()) - ->method('validate') - ->with($query) - ->willReturn($errors = new ListOfErrors(new Error(null, 'Something went wrong.'))); - - $next = function () { - throw new \LogicException('Not expecting next closure to be called.'); - }; - - $result = ($this->middleware)($query, $next); - - $this->assertTrue($result->didFail()); - $this->assertSame($errors, $result->errors()); - } -} diff --git a/tests/Unit/Application/Bus/ValidatorTest.php b/tests/Unit/Application/Bus/ValidatorTest.php index cf9a40f6..c6ae6ab5 100644 --- a/tests/Unit/Application/Bus/ValidatorTest.php +++ b/tests/Unit/Application/Bus/ValidatorTest.php @@ -14,12 +14,12 @@ use CloudCreativity\Modules\Bus\Validation\Validator; use CloudCreativity\Modules\Contracts\Messaging\Command; +use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Messaging\Query; use CloudCreativity\Modules\Contracts\Toolkit\Pipeline\PipeContainer; use CloudCreativity\Modules\Toolkit\Result\Error; use CloudCreativity\Modules\Toolkit\Result\ListOfErrors; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerInterface; @@ -33,33 +33,33 @@ public static function messageProvider(): array return [ [Query::class], [Command::class], + [Message::class], ]; } /** - * @param class-string $message + * @param class-string $class */ #[DataProvider('messageProvider')] - public function testItValidatesMessage(string $message): void + public function testItValidatesMessage(string $class): void { - /** @var (Command&MockObject)|(MockObject&Query) $query */ - $query = $this->createMock($message); + $message = $this->createStub($class); $error1 = new Error(null, 'Message 1'); $error2 = new Error(null, 'Message 2'); $error3 = new Error(null, 'Message 3'); - $a = function ($actual) use ($query, $error1): ListOfErrors { - $this->assertSame($query, $actual); + $a = function ($actual) use ($message, $error1): ListOfErrors { + $this->assertSame($message, $actual); return new ListOfErrors($error1); }; - $b = function ($actual) use ($query): ?ListOfErrors { - $this->assertSame($query, $actual); + $b = function ($actual) use ($message): ?ListOfErrors { + $this->assertSame($message, $actual); return null; }; - $c = function ($actual) use ($query, $error2, $error3): ListOfErrors { - $this->assertSame($query, $actual); + $c = function ($actual) use ($message, $error2, $error3): ListOfErrors { + $this->assertSame($message, $actual); return new ListOfErrors($error2, $error3); }; @@ -76,36 +76,35 @@ public function testItValidatesMessage(string $message): void $validator = new Validator(rules: $rules); $actual = $validator ->using([$a, 'Rule2', 'Rule3']) - ->validate($query); + ->validate($message); $this->assertInstanceOf(ListOfErrors::class, $actual); $this->assertSame([$error1, $error2, $error3], $actual->all()); } /** - * @param class-string $message + * @param class-string $class */ #[DataProvider('messageProvider')] - public function testItValidatesMessageUsingPsrContainer(string $message): void + public function testItValidatesMessageUsingPsrContainer(string $class): void { - /** @var (Command&MockObject)|(MockObject&Query) $query */ - $query = $this->createMock($message); + $message = $this->createStub($class); $error1 = new Error(null, 'Message 1'); $error2 = new Error(null, 'Message 2'); $error3 = new Error(null, 'Message 3'); - $a = function ($actual) use ($query, $error1): ListOfErrors { - $this->assertSame($query, $actual); - return new ListOfErrors($error1); + $a = function ($actual) use ($message, $error1): Error { + $this->assertSame($message, $actual); + return $error1; }; - $b = function ($actual) use ($query): ?ListOfErrors { - $this->assertSame($query, $actual); + $b = function ($actual) use ($message): ?ListOfErrors { + $this->assertSame($message, $actual); return null; }; - $c = function ($actual) use ($query, $error2, $error3): ListOfErrors { - $this->assertSame($query, $actual); + $c = function ($actual) use ($message, $error2, $error3): ListOfErrors { + $this->assertSame($message, $actual); return new ListOfErrors($error2, $error3); }; @@ -122,29 +121,28 @@ public function testItValidatesMessageUsingPsrContainer(string $message): void $validator = new Validator(rules: $rules); $actual = $validator ->using([$a, 'Rule2', 'Rule3']) - ->validate($query); + ->validate($message); $this->assertInstanceOf(ListOfErrors::class, $actual); $this->assertSame([$error1, $error2, $error3], $actual->all()); } /** - * @param class-string $message + * @param class-string $class */ #[DataProvider('messageProvider')] - public function testItStopsOnFirstFailure(string $message): void + public function testItStopsOnFirstFailure(string $class): void { - /** @var (Command&MockObject)|(MockObject&Query) $query */ - $query = $this->createMock($message); + $message = $this->createStub($class); $error = new Error(null, 'Message 1'); - $a = function ($actual) use ($query): null { - $this->assertSame($query, $actual); + $a = function ($actual) use ($message): null { + $this->assertSame($message, $actual); return null; }; - $b = function ($actual) use ($query, $error): ListOfErrors { - $this->assertSame($query, $actual); + $b = function ($actual) use ($message, $error): ListOfErrors { + $this->assertSame($message, $actual); return new ListOfErrors($error); }; @@ -156,7 +154,7 @@ public function testItStopsOnFirstFailure(string $message): void $actual = $validator ->using([$a, $b, $c]) ->stopOnFirstFailure() - ->validate($query); + ->validate($message); $this->assertInstanceOf(ListOfErrors::class, $actual); $this->assertSame([$error], $actual->all()); @@ -164,7 +162,7 @@ public function testItStopsOnFirstFailure(string $message): void public function testItHasNoRules(): void { - $query = $this->createMock(Query::class); + $query = $this->createStub(Query::class); $validator = new Validator(); $this->assertEquals(new ListOfErrors(), $validator->validate($query)); From 3d6f4655adce29dc107d0e834ec343cfbf69c672 Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Mon, 5 Jan 2026 15:10:27 +0000 Subject: [PATCH 7/8] wip: add logging improvements --- docs/guide/application/commands.md | 2 +- docs/guide/application/integration-events.md | 4 +- src/Bus/Loggable/ObjectDecorator.php | 96 ------ src/Bus/Loggable/ResultDecorator.php | 90 ------ src/Bus/Loggable/SimpleContextFactory.php | 32 -- src/Bus/Middleware/LogInboundEvent.php | 48 --- src/Bus/Middleware/LogMessageDispatch.php | 7 +- src/Bus/Middleware/SetupBeforeEvent.php | 4 +- src/Bus/Middleware/TearDownAfterEvent.php | 4 +- src/Bus/{Logging => }/SanitizedMessage.php | 14 +- src/{Messaging => Bus}/Sensitive.php | 2 +- src/Contracts/Bus/Loggable/ContextFactory.php | 27 -- .../Bus/Loggable/ContextProvider.php | 23 -- .../Bus/Middleware/BusMiddleware.php | 2 +- .../Bus/Middleware/CommandMiddleware.php | 4 +- ...are.php => IntegrationEventMiddleware.php} | 2 +- .../Bus/Middleware/QueryMiddleware.php | 4 +- .../OutboundEventMiddleware.php | 26 -- src/Contracts/Toolkit/Result/Result.php | 3 +- .../PsrLogExceptionReporter.php | 5 - .../Monolog/ContextProcessor.php | 80 ----- .../Monolog/ContextualProcessor.php | 52 ++++ .../Monolog/RecursiveParser.php | 18 +- .../Middleware/LogOutboundEvent.php | 10 +- .../Queue/Middleware/LogPushedToQueue.php | 14 +- .../Result/ContextualResult.php} | 45 ++- src/Toolkit/Result/FailedResultException.php | 10 + src/Toolkit/Result/Result.php | 8 + tests/Integration/Bus/MathEventBus.php | 4 +- tests/Integration/Bus/MathEventBusTest.php | 4 +- .../Bus/Middleware/LogMessageDispatchTest.php | 13 +- .../Middleware/LogInboundEventTest.php | 117 ------- .../Unit/Bus/Loggable/ObjectDecoratorTest.php | 159 ---------- .../Unit/Bus/Loggable/ResultDecoratorTest.php | 294 ------------------ .../PsrLogExceptionReporterTest.php | 6 +- .../Middleware/LogOutboundEventTest.php | 117 ------- .../Queue/Middleware/LogPushedToQueueTest.php | 153 --------- 37 files changed, 178 insertions(+), 1325 deletions(-) delete mode 100644 src/Bus/Loggable/ObjectDecorator.php delete mode 100644 src/Bus/Loggable/ResultDecorator.php delete mode 100644 src/Bus/Loggable/SimpleContextFactory.php delete mode 100644 src/Bus/Middleware/LogInboundEvent.php rename src/Bus/{Logging => }/SanitizedMessage.php (82%) rename src/{Messaging => Bus}/Sensitive.php (87%) delete mode 100644 src/Contracts/Bus/Loggable/ContextFactory.php delete mode 100644 src/Contracts/Bus/Loggable/ContextProvider.php rename src/Contracts/Bus/Middleware/{InboundEventMiddleware.php => IntegrationEventMiddleware.php} (93%) delete mode 100644 src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php delete mode 100644 src/Infrastructure/Monolog/ContextProcessor.php create mode 100644 src/Infrastructure/Monolog/ContextualProcessor.php rename src/{Bus/Logging/SanitizedResult.php => Toolkit/Result/ContextualResult.php} (52%) delete mode 100644 tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php delete mode 100644 tests/Unit/Bus/Loggable/ObjectDecoratorTest.php delete mode 100644 tests/Unit/Bus/Loggable/ResultDecoratorTest.php delete mode 100644 tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php delete mode 100644 tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php diff --git a/docs/guide/application/commands.md b/docs/guide/application/commands.md index 3c6a10ff..cdc1f40d 100644 --- a/docs/guide/application/commands.md +++ b/docs/guide/application/commands.md @@ -602,7 +602,7 @@ However, there may be scenarios where a property should not be logged, e.g. beca In this scenario, use the `Sensitive` attribute on the property, and it will not be logged: ```php -use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use CloudCreativity\Modules\Messaging\Sensitive; +use CloudCreativity\Modules\Bus\Sensitive;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class CancelAttendeeTicketCommand implements Command { diff --git a/docs/guide/application/integration-events.md b/docs/guide/application/integration-events.md index 602b69f5..9aa47dea 100644 --- a/docs/guide/application/integration-events.md +++ b/docs/guide/application/integration-events.md @@ -865,9 +865,9 @@ following signature: ```php namespace App\Modules\EventManagement\Application\Bus\Middleware; -use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware;use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; +use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\IntegrationEventMiddleware;use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; -final class MyMiddleware implements InboundEventMiddleware +final class MyMiddleware implements IntegrationEventMiddleware { /** * Execute the middleware. diff --git a/src/Bus/Loggable/ObjectDecorator.php b/src/Bus/Loggable/ObjectDecorator.php deleted file mode 100644 index de10ae8e..00000000 --- a/src/Bus/Loggable/ObjectDecorator.php +++ /dev/null @@ -1,96 +0,0 @@ - - */ -final readonly class ObjectDecorator implements IteratorAggregate, ContextProvider -{ - private const DATE_FORMAT = 'Y-m-d\TH:i:s.uP'; - - public function __construct( - private object $source, - private ?string $dateFormat = self::DATE_FORMAT, - ) { - } - - /** - * @return Generator - */ - public function getIterator(): Generator - { - foreach ($this->cursor() as $key) { - $value = $this->source->{$key}; - yield $key => match (true) { - $value instanceof ContextProvider => $value->context(), - $value instanceof Contextual => $value->context(), - $value instanceof UuidInterface => $value->toString(), - $value instanceof UnitEnum => enum_string($value), - $value instanceof DateTimeInterface && $this->dateFormat !== null => $value->format($this->dateFormat), - $value instanceof DateTimeZone => $value->getName(), - default => $value, - }; - } - } - - /** - * @return array - */ - public function keys(): array - { - return iterator_to_array($this->cursor()); - } - - /** - * @return array - */ - public function all(): array - { - return iterator_to_array($this); - } - - public function context(): array - { - return $this->all(); - } - - /** - * @return Generator - */ - private function cursor(): Generator - { - $reflect = new ReflectionClass($this->source); - - foreach ($reflect->getProperties(ReflectionProperty::IS_PUBLIC) as $property) { - $attributes = $property->getAttributes(Sensitive::class); - if (count($attributes) === 0) { - yield $property->getName(); - } - } - } -} diff --git a/src/Bus/Loggable/ResultDecorator.php b/src/Bus/Loggable/ResultDecorator.php deleted file mode 100644 index 0507085a..00000000 --- a/src/Bus/Loggable/ResultDecorator.php +++ /dev/null @@ -1,90 +0,0 @@ - $result - */ - public function __construct(private Result $result) - { - } - - public function context(): array - { - if ($this->result instanceof ContextProvider) { - return $this->result->context(); - } - - $value = $this->result->safe(); - $errors = $this->errors(); - $error = null; - - if ( - count($errors) === 1 && - count($errors[0]) === 1 && - (isset($errors[0]['message']) || isset($errors[0]['code'])) - ) { - $error = $errors[0]['message'] ?? $errors[0]['code']; - $errors = null; - } - - return array_filter([ - 'success' => $this->result->didSucceed(), - 'value' => match(true) { - $value instanceof ContextProvider => $value->context(), - $value instanceof Contextual => $value->context(), - is_scalar($value) => $value, - default => null, - }, - 'error' => $error, - 'errors' => $errors ?: null, - 'meta' => $this->result->meta()->all() ?: null, - ], static fn ($value) => $value !== null); - } - - /** - * @return array> - */ - private function errors(): array - { - return array_map( - fn (Error $error): array => $this->error($error), - $this->result->errors()->all(), - ); - } - - /** - * @return array - */ - private function error(Error $error): array - { - if ($error instanceof ContextProvider) { - return $error->context(); - } - - return array_filter([ - 'code' => enum_string($error->code() ?? ''), - 'key' => enum_string($error->key() ?? ''), - 'message' => $error->message(), - ]); - } -} diff --git a/src/Bus/Loggable/SimpleContextFactory.php b/src/Bus/Loggable/SimpleContextFactory.php deleted file mode 100644 index d57d880e..00000000 --- a/src/Bus/Loggable/SimpleContextFactory.php +++ /dev/null @@ -1,32 +0,0 @@ - $object, - $object instanceof Result => new ResultDecorator($object), - $object instanceof Message => new ObjectDecorator($object), - }; - - return $object->context(); - } -} diff --git a/src/Bus/Middleware/LogInboundEvent.php b/src/Bus/Middleware/LogInboundEvent.php deleted file mode 100644 index bd3d4923..00000000 --- a/src/Bus/Middleware/LogInboundEvent.php +++ /dev/null @@ -1,48 +0,0 @@ -toString() ?? $event::class; - - $this->log->log( - $this->publishLevel, - "Receiving integration event {$name}.", - $context = ['event' => $this->context->make($event)], - ); - - $next($event); - - $this->log->log($this->publishedLevel, "Received integration event {$name}.", $context); - } -} diff --git a/src/Bus/Middleware/LogMessageDispatch.php b/src/Bus/Middleware/LogMessageDispatch.php index 62b9b702..469bb8f2 100644 --- a/src/Bus/Middleware/LogMessageDispatch.php +++ b/src/Bus/Middleware/LogMessageDispatch.php @@ -13,8 +13,7 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Bus\Logging\SanitizedMessage; -use CloudCreativity\Modules\Bus\Logging\SanitizedResult; +use CloudCreativity\Modules\Bus\SanitizedMessage; use CloudCreativity\Modules\Contracts\Bus\Middleware\BusMiddleware; use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; @@ -47,7 +46,7 @@ public function __invoke(Message $message, Closure $next): ?Result $this->logger->log( $this->dispatchLevel, "Bus dispatching {$name}.", - [$key => new SanitizedMessage($message)], + [$key => (new SanitizedMessage($message))->context()], ); $result = $next($message); @@ -55,7 +54,7 @@ public function __invoke(Message $message, Closure $next): ?Result $this->logger->log( $this->dispatchedLevel, "Bus dispatched {$name}.", - $result ? ['result' => new SanitizedResult($result)] : [], + $result ? ['result' => $result->context()] : [], ); return $result; diff --git a/src/Bus/Middleware/SetupBeforeEvent.php b/src/Bus/Middleware/SetupBeforeEvent.php index 80724c39..4a9fc61d 100644 --- a/src/Bus/Middleware/SetupBeforeEvent.php +++ b/src/Bus/Middleware/SetupBeforeEvent.php @@ -13,10 +13,10 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; +use CloudCreativity\Modules\Contracts\Bus\Middleware\IntegrationEventMiddleware; use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; -final readonly class SetupBeforeEvent implements InboundEventMiddleware +final readonly class SetupBeforeEvent implements IntegrationEventMiddleware { /** * @param Closure(): ?Closure(): void $callback diff --git a/src/Bus/Middleware/TearDownAfterEvent.php b/src/Bus/Middleware/TearDownAfterEvent.php index 182fcaac..2defda63 100644 --- a/src/Bus/Middleware/TearDownAfterEvent.php +++ b/src/Bus/Middleware/TearDownAfterEvent.php @@ -13,10 +13,10 @@ namespace CloudCreativity\Modules\Bus\Middleware; use Closure; -use CloudCreativity\Modules\Contracts\Bus\Middleware\InboundEventMiddleware; +use CloudCreativity\Modules\Contracts\Bus\Middleware\IntegrationEventMiddleware; use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; -final readonly class TearDownAfterEvent implements InboundEventMiddleware +final readonly class TearDownAfterEvent implements IntegrationEventMiddleware { /** * @param Closure(): void $callback diff --git a/src/Bus/Logging/SanitizedMessage.php b/src/Bus/SanitizedMessage.php similarity index 82% rename from src/Bus/Logging/SanitizedMessage.php rename to src/Bus/SanitizedMessage.php index da3facbb..4e773a1a 100644 --- a/src/Bus/Logging/SanitizedMessage.php +++ b/src/Bus/SanitizedMessage.php @@ -10,10 +10,10 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Bus\Logging; +namespace CloudCreativity\Modules\Bus; use CloudCreativity\Modules\Contracts\Messaging\Message; -use CloudCreativity\Modules\Messaging\Sensitive; +use CloudCreativity\Modules\Contracts\Toolkit\Contextual; use Generator; use IteratorAggregate; use ReflectionClass; @@ -22,7 +22,7 @@ /** * @implements IteratorAggregate */ -final readonly class SanitizedMessage implements IteratorAggregate +final readonly class SanitizedMessage implements IteratorAggregate, Contextual { public function __construct(private Message $message) { @@ -38,6 +38,14 @@ public function getIterator(): Generator } } + /** + * @return array + */ + public function context(): array + { + return iterator_to_array($this); + } + /** * @return Generator */ diff --git a/src/Messaging/Sensitive.php b/src/Bus/Sensitive.php similarity index 87% rename from src/Messaging/Sensitive.php rename to src/Bus/Sensitive.php index 927664d4..ad86cc64 100644 --- a/src/Messaging/Sensitive.php +++ b/src/Bus/Sensitive.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Messaging; +namespace CloudCreativity\Modules\Bus; use Attribute; diff --git a/src/Contracts/Bus/Loggable/ContextFactory.php b/src/Contracts/Bus/Loggable/ContextFactory.php deleted file mode 100644 index 6bbe2e45..00000000 --- a/src/Contracts/Bus/Loggable/ContextFactory.php +++ /dev/null @@ -1,27 +0,0 @@ - $object - * @return array - */ - public function make(Message|Result $object): array; -} diff --git a/src/Contracts/Bus/Loggable/ContextProvider.php b/src/Contracts/Bus/Loggable/ContextProvider.php deleted file mode 100644 index fee132c9..00000000 --- a/src/Contracts/Bus/Loggable/ContextProvider.php +++ /dev/null @@ -1,23 +0,0 @@ - - */ - public function context(): array; -} diff --git a/src/Contracts/Bus/Middleware/BusMiddleware.php b/src/Contracts/Bus/Middleware/BusMiddleware.php index e9e6d9e7..be70086e 100644 --- a/src/Contracts/Bus/Middleware/BusMiddleware.php +++ b/src/Contracts/Bus/Middleware/BusMiddleware.php @@ -21,7 +21,7 @@ interface BusMiddleware /** * Handle the message. * - * @param (Closure(Message): ?Result) $next + * @param Closure(Message): ?Result $next * @return Result|null */ public function __invoke(Message $message, Closure $next): ?Result; diff --git a/src/Contracts/Bus/Middleware/CommandMiddleware.php b/src/Contracts/Bus/Middleware/CommandMiddleware.php index 2b5ec4cb..68cc45c4 100644 --- a/src/Contracts/Bus/Middleware/CommandMiddleware.php +++ b/src/Contracts/Bus/Middleware/CommandMiddleware.php @@ -22,7 +22,7 @@ interface CommandMiddleware * Handle the command. * * @param Closure(Command): Result $next - * @return Result + * @return Result|null */ - public function __invoke(Command $command, Closure $next): Result; + public function __invoke(Command $command, Closure $next): ?Result; } diff --git a/src/Contracts/Bus/Middleware/InboundEventMiddleware.php b/src/Contracts/Bus/Middleware/IntegrationEventMiddleware.php similarity index 93% rename from src/Contracts/Bus/Middleware/InboundEventMiddleware.php rename to src/Contracts/Bus/Middleware/IntegrationEventMiddleware.php index a87525c2..69cb2f2c 100644 --- a/src/Contracts/Bus/Middleware/InboundEventMiddleware.php +++ b/src/Contracts/Bus/Middleware/IntegrationEventMiddleware.php @@ -15,7 +15,7 @@ use Closure; use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; -interface InboundEventMiddleware +interface IntegrationEventMiddleware { /** * Handle the inbound event. diff --git a/src/Contracts/Bus/Middleware/QueryMiddleware.php b/src/Contracts/Bus/Middleware/QueryMiddleware.php index e2d097ea..85e297d4 100644 --- a/src/Contracts/Bus/Middleware/QueryMiddleware.php +++ b/src/Contracts/Bus/Middleware/QueryMiddleware.php @@ -22,7 +22,7 @@ interface QueryMiddleware * Handle the query. * * @param Closure(Query): Result $next - * @return Result + * @return Result|null */ - public function __invoke(Query $query, Closure $next): Result; + public function __invoke(Query $query, Closure $next): ?Result; } diff --git a/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php b/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php deleted file mode 100644 index d87f1470..00000000 --- a/src/Contracts/Infrastructure/OutboundEventBus/OutboundEventMiddleware.php +++ /dev/null @@ -1,26 +0,0 @@ -context(); - } - if (method_exists($ex, 'context')) { $context = $ex->context(); return is_array($context) ? $context : []; diff --git a/src/Infrastructure/Monolog/ContextProcessor.php b/src/Infrastructure/Monolog/ContextProcessor.php deleted file mode 100644 index d0b06ee6..00000000 --- a/src/Infrastructure/Monolog/ContextProcessor.php +++ /dev/null @@ -1,80 +0,0 @@ -context; - - foreach ($context as $key => $value) { - $context[$key] = match (true) { - $value instanceof SanitizedMessage => $this->message($value), - $value instanceof SanitizedResult => $this->result($value), - default => $this->process($value), - }; - } - - return $record->with(context: $context); - } - - private function process(mixed $value): mixed - { - if ($value instanceof Contextual) { - $value = $value->context(); - } - - return $this->parser ? $this->parser->parse($value) : $value; - } - - /** - * @return array - */ - private function message(SanitizedMessage $message): array - { - $values = []; - - foreach ($message as $key => $value) { - $values[$key] = $this->process($value); - } - - return $values; - } - - /** - * @return array - */ - private function result(SanitizedResult $result): array - { - $errors = $result->errors(); - - return array_filter([ - 'success' => $result->success(), - 'value' => $this->process($result->value()), - 'error' => count($errors) === 1 ? $errors[0] : null, - 'errors' => count($errors) > 1 ? $errors : null, - 'meta' => $this->process($result->meta()), - ], fn (mixed $value): bool => $value !== null); - } -} diff --git a/src/Infrastructure/Monolog/ContextualProcessor.php b/src/Infrastructure/Monolog/ContextualProcessor.php new file mode 100644 index 00000000..b1e1b090 --- /dev/null +++ b/src/Infrastructure/Monolog/ContextualProcessor.php @@ -0,0 +1,52 @@ +parser = match (true) { + $recursive => new RecursiveParser($sorted, $parser), + default => $parser, + }; + } + + public function __invoke(LogRecord $record): LogRecord + { + $context = $record->context; + + foreach ($context as $key => $value) { + if ($key === 'exception') { + continue; + } + + if ($value instanceof Contextual) { + $value = $value->context(); + } + + $context[$key] = $this->parser ? $this->parser->parse($value) : $value; + } + + return $record->with(context: $context); + } +} diff --git a/src/Infrastructure/Monolog/RecursiveParser.php b/src/Infrastructure/Monolog/RecursiveParser.php index 24f30902..17ddc697 100644 --- a/src/Infrastructure/Monolog/RecursiveParser.php +++ b/src/Infrastructure/Monolog/RecursiveParser.php @@ -12,16 +12,24 @@ namespace CloudCreativity\Modules\Infrastructure\Monolog; +use CloudCreativity\Modules\Contracts\Toolkit\Contextual; + final readonly class RecursiveParser implements ValueParser { - public function __construct(private ValueParser $innerParser) - { + public function __construct( + private bool $sorted = false, + private ?ValueParser $innerParser = null, + ) { } public function parse(mixed $value): mixed { + if ($value instanceof Contextual) { + return $this->parse($value->context()); + } + if (!is_iterable($value)) { - return $this->innerParser->parse($value); + return $this->innerParser ? $this->innerParser->parse($value) : null; } $parsed = []; @@ -32,6 +40,10 @@ public function parse(mixed $value): mixed } } + if ($this->sorted) { + ksort($parsed); + } + return $parsed; } } diff --git a/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php b/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php index a5a988e0..0b274d5d 100644 --- a/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php +++ b/src/Infrastructure/OutboundEventBus/Middleware/LogOutboundEvent.php @@ -13,21 +13,19 @@ namespace CloudCreativity\Modules\Infrastructure\OutboundEventBus\Middleware; use Closure; -use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; -use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Infrastructure\OutboundEventBus\OutboundEventMiddleware; +use CloudCreativity\Modules\Bus\SanitizedMessage; +use CloudCreativity\Modules\Contracts\Bus\Middleware\IntegrationEventMiddleware; use CloudCreativity\Modules\Contracts\Messaging\IntegrationEvent; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; -final readonly class LogOutboundEvent implements OutboundEventMiddleware +final readonly class LogOutboundEvent implements IntegrationEventMiddleware { public function __construct( private LoggerInterface $log, private string $publishLevel = LogLevel::DEBUG, private string $publishedLevel = LogLevel::INFO, - private ContextFactory $context = new SimpleContextFactory(), ) { } @@ -38,7 +36,7 @@ public function __invoke(IntegrationEvent $event, Closure $next): void $this->log->log( $this->publishLevel, "Publishing integration event {$name}.", - $context = ['event' => $this->context->make($event)], + $context = ['event' => (new SanitizedMessage($event))->context()], ); $next($event); diff --git a/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php b/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php index fd0a7c4a..2aa65aa8 100644 --- a/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php +++ b/src/Infrastructure/Queue/Middleware/LogPushedToQueue.php @@ -13,36 +13,36 @@ namespace CloudCreativity\Modules\Infrastructure\Queue\Middleware; use Closure; -use CloudCreativity\Modules\Bus\Loggable\SimpleContextFactory; -use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextFactory; -use CloudCreativity\Modules\Contracts\Infrastructure\Queue\QueueMiddleware; +use CloudCreativity\Modules\Bus\SanitizedMessage; +use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware; use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Toolkit\ModuleBasename; use Psr\Log\LoggerInterface; use Psr\Log\LogLevel; -final readonly class LogPushedToQueue implements QueueMiddleware +final readonly class LogPushedToQueue implements CommandMiddleware { public function __construct( private LoggerInterface $log, private string $queueLevel = LogLevel::DEBUG, private string $queuedLevel = LogLevel::INFO, - private ContextFactory $context = new SimpleContextFactory(), ) { } - public function __invoke(Command $command, Closure $next): void + public function __invoke(Command $command, Closure $next): null { $name = ModuleBasename::tryFrom($command)?->toString() ?? $command::class; $this->log->log( $this->queueLevel, "Queuing command {$name}.", - $context = ['command' => $this->context->make($command)], + $context = ['command' => (new SanitizedMessage($command))->context()], ); $next($command); $this->log->log($this->queuedLevel, "Queued command {$name}.", $context); + + return null; } } diff --git a/src/Bus/Logging/SanitizedResult.php b/src/Toolkit/Result/ContextualResult.php similarity index 52% rename from src/Bus/Logging/SanitizedResult.php rename to src/Toolkit/Result/ContextualResult.php index 1272f8b9..7f0707f6 100644 --- a/src/Bus/Logging/SanitizedResult.php +++ b/src/Toolkit/Result/ContextualResult.php @@ -10,13 +10,13 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Bus\Logging; +namespace CloudCreativity\Modules\Toolkit\Result; use CloudCreativity\Modules\Contracts\Toolkit\Contextual; use CloudCreativity\Modules\Contracts\Toolkit\Result\Error; use CloudCreativity\Modules\Contracts\Toolkit\Result\Result; -final readonly class SanitizedResult +readonly class ContextualResult implements Contextual { /** * @param Result $result @@ -30,19 +30,34 @@ public function success(): bool return $this->result->didSucceed(); } - public function value(): ?Contextual + public function value(): mixed { $value = $this->result->safe(); - return $value instanceof Contextual ? $value : null; + if ($value instanceof Contextual) { + return $value->context(); + } + + // do not return strings as we do not know if they are sensitive or not. + if (is_bool($value) || is_int($value) || is_float($value)) { + return $value; + } + + return null; } /** - * @return array + * @return array|null */ - public function meta(): array + public function meta(): ?array { - return $this->result->meta()->all(); + $meta = $this->result->meta(); + + if ($meta->isNotEmpty()) { + return $meta->all(); + } + + return null; } /** @@ -56,6 +71,22 @@ public function errors(): array ); } + /** + * @return array + */ + public function context(): array + { + $errors = $this->errors(); + + return array_filter([ + 'success' => $this->success(), + 'value' => $this->value(), + 'error' => count($errors) === 1 ? $errors[0] : null, + 'errors' => count($errors) > 1 ? $errors : null, + 'meta' => $this->meta(), + ], fn (mixed $value): bool => $value !== null); + } + /** * @return array */ diff --git a/src/Toolkit/Result/FailedResultException.php b/src/Toolkit/Result/FailedResultException.php index b78a8d7a..96851bb4 100644 --- a/src/Toolkit/Result/FailedResultException.php +++ b/src/Toolkit/Result/FailedResultException.php @@ -46,4 +46,14 @@ public function getResult(): Result { return $this->result; } + + /** + * @return array + */ + public function context(): array + { + $context = $this->result->context(); + + return is_array($context) ? $context : [$context]; + } } diff --git a/src/Toolkit/Result/Result.php b/src/Toolkit/Result/Result.php index c9263a42..e55db524 100644 --- a/src/Toolkit/Result/Result.php +++ b/src/Toolkit/Result/Result.php @@ -157,4 +157,12 @@ public function withMeta(array|Meta $meta): self meta: $this->meta->merge($meta), ); } + + /** + * @return array + */ + public function context(): array + { + return (new ContextualResult($this))->context(); + } } diff --git a/tests/Integration/Bus/MathEventBus.php b/tests/Integration/Bus/MathEventBus.php index 30f3a259..a3a67921 100644 --- a/tests/Integration/Bus/MathEventBus.php +++ b/tests/Integration/Bus/MathEventBus.php @@ -13,12 +13,12 @@ namespace CloudCreativity\Modules\Tests\Integration\Bus; use CloudCreativity\Modules\Bus\InboundEventDispatcher; -use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; use CloudCreativity\Modules\Bus\WithDefault; use CloudCreativity\Modules\Bus\WithEvent; use CloudCreativity\Modules\Toolkit\Pipeline\Through; -#[Through(LogInboundEvent::class)] +#[Through(LogMessageDispatch::class)] #[WithDefault(DefaultEventHandler::class)] #[WithEvent(NumbersAdded::class, NumbersAddedHandler::class)] #[WithEvent(NumbersSubtracted::class, NumbersSubtractedHandler::class)] diff --git a/tests/Integration/Bus/MathEventBusTest.php b/tests/Integration/Bus/MathEventBusTest.php index 4d2423e6..40e53f7c 100644 --- a/tests/Integration/Bus/MathEventBusTest.php +++ b/tests/Integration/Bus/MathEventBusTest.php @@ -14,7 +14,7 @@ use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork; use CloudCreativity\Modules\Application\UnitOfWork\UnitOfWorkManager; -use CloudCreativity\Modules\Bus\Middleware\LogInboundEvent; +use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; use CloudCreativity\Modules\Testing\FakeContainer; use PHPUnit\Framework\TestCase; @@ -30,7 +30,7 @@ public function test(): void $container->bind(NumbersAddedHandler::class, fn () => $a); $container->bind(NumbersSubtractedHandler::class, fn () => $b); $container->bind(DefaultEventHandler::class, fn () => $c); - $container->bind(LogInboundEvent::class, fn () => new LogInboundEvent($container->logger)); + $container->bind(LogMessageDispatch::class, fn () => new LogMessageDispatch($container->logger)); $container->bind(ExecuteInUnitOfWork::class, fn () => new ExecuteInUnitOfWork( new UnitOfWorkManager($container->unitOfWork), )); diff --git a/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php b/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php index 2e72939d..c71d87d6 100644 --- a/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php +++ b/tests/Unit/Application/Bus/Middleware/LogMessageDispatchTest.php @@ -12,9 +12,8 @@ namespace CloudCreativity\Modules\Tests\Unit\Application\Bus\Middleware; -use CloudCreativity\Modules\Bus\Logging\SanitizedMessage; -use CloudCreativity\Modules\Bus\Logging\SanitizedResult; use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch; +use CloudCreativity\Modules\Bus\SanitizedMessage; use CloudCreativity\Modules\Contracts\Messaging\Command; use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Messaging\Query; @@ -70,8 +69,8 @@ public function testWithDefaultLevels(): void $this->assertSame($expected, $actual); $this->assertEquals([ - [LogLevel::DEBUG, "Bus dispatching {$name}.", ['command' => new SanitizedMessage($this->message)]], - [LogLevel::INFO, "Bus dispatched {$name}.", ['result' => new SanitizedResult($expected)]], + [LogLevel::DEBUG, "Bus dispatching {$name}.", ['command' => (new SanitizedMessage($this->message))->context()]], + [LogLevel::INFO, "Bus dispatched {$name}.", ['result' => $expected->context()]], ], $this->logs); } @@ -88,8 +87,8 @@ public function testWithCustomLevels(): void $this->assertSame($expected, $actual); $this->assertEquals([ - [LogLevel::NOTICE, "Bus dispatching {$name}.", ['command' => new SanitizedMessage($this->message)]], - [LogLevel::WARNING, "Bus dispatched {$name}.", ['result' => new SanitizedResult($expected)]], + [LogLevel::NOTICE, "Bus dispatching {$name}.", ['command' => (new SanitizedMessage($this->message))->context()]], + [LogLevel::WARNING, "Bus dispatched {$name}.", ['result' => $expected->context()]], ], $this->logs); } @@ -108,7 +107,7 @@ public function testItLogsAfterTheNextClosureIsInvoked(): void } catch (LogicException $ex) { $this->assertSame($expected, $ex); $this->assertEquals([ - [LogLevel::DEBUG, "Bus dispatching {$name}.", ['query' => new SanitizedMessage($message)]], + [LogLevel::DEBUG, "Bus dispatching {$name}.", ['query' => (new SanitizedMessage($message))->context()]], ], $this->logs); } } diff --git a/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php b/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php deleted file mode 100644 index 8e493f19..00000000 --- a/tests/Unit/Application/InboundEventBus/Middleware/LogInboundEventTest.php +++ /dev/null @@ -1,117 +0,0 @@ -logger = $this->createMock(LoggerInterface::class); - $this->event = new TestOutboundEvent(); - } - - public function test(): void - { - $eventName = ModuleBasename::from($this->event); - - $this->logger - ->expects($this->exactly(2)) - ->method('log') - ->willReturnCallback(function ($level, $message, $context) use (&$logs): bool { - $logs[] = [$level, $message, $context]; - return true; - }); - - $middleware = new LogInboundEvent($this->logger); - $middleware($this->event, function (IntegrationEvent $received): void { - $this->assertSame($this->event, $received); - }); - - $context = (new ObjectDecorator($this->event))->context(); - - $this->assertSame([ - [LogLevel::DEBUG, "Receiving integration event {$eventName}.", ['event' => $context]], - [LogLevel::INFO, "Received integration event {$eventName}.", ['event' => $context]], - ], $logs); - } - - public function testWithCustomLevels(): void - { - $eventName = ModuleBasename::from($this->event); - $logs = []; - - $this->logger - ->expects($this->exactly(2)) - ->method('log') - ->willReturnCallback(function ($level, $message, $context) use (&$logs): bool { - $logs[] = [$level, $message, $context]; - return true; - }); - - $middleware = new LogInboundEvent($this->logger, LogLevel::NOTICE, LogLevel::WARNING); - $middleware($this->event, function (IntegrationEvent $received) { - $this->assertSame($this->event, $received); - }); - - $context = (new ObjectDecorator($this->event))->context(); - - $this->assertSame([ - [LogLevel::NOTICE, "Receiving integration event {$eventName}.", ['event' => $context]], - [LogLevel::WARNING, "Received integration event {$eventName}.", ['event' => $context]], - ], $logs); - } - - public function testItLogsAfterTheNextClosureIsInvoked(): void - { - $expected = new LogicException(); - $eventName = ModuleBasename::from($this->event); - - $context = (new ObjectDecorator($this->event))->context(); - - $this->logger - ->expects($this->once()) - ->method('log') - ->with(LogLevel::DEBUG, "Receiving integration event {$eventName}.", ['event' => $context]); - - $middleware = new LogInboundEvent($this->logger); - - try { - $middleware($this->event, static function () use ($expected) { - throw $expected; - }); - $this->fail('No exception thrown.'); - } catch (LogicException $ex) { - $this->assertSame($expected, $ex); - } - } -} diff --git a/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php b/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php deleted file mode 100644 index a534f1ca..00000000 --- a/tests/Unit/Bus/Loggable/ObjectDecoratorTest.php +++ /dev/null @@ -1,159 +0,0 @@ -factory = new SimpleContextFactory(); - } - - protected function tearDown(): void - { - parent::tearDown(); - unset($this->factory); - } - - public function testItUsesObjectProperties(): void - { - $uuid = Uuid::uuid4(); - $date1 = new \DateTimeImmutable(); - $date2 = new \DateTime('2025-01-01 12:34:56', new \DateTimeZone('Australia/Sydney')); - - $source = new class ($uuid, $date1, $date2, $date2->getTimezone()) implements Message { - public string $foo = 'bar'; - public string $baz = 'bat'; - public ?string $blah = null; - public UnitEnum $enum1 = TestBackedEnum::Foo; - public UnitEnum $enum2 = TestBackedIntEnum::FooBar; - public UnitEnum $enum3 = TestUnitEnum::Baz; - protected string $foobar = 'foobar'; - - public function __construct( - public UuidInterface $uuid, - public DateTimeInterface $date1, - public DateTimeInterface $date2, - public \DateTimeZone $timeZone, - ) { - } - }; - - $expected = [ - 'foo' => 'bar', - 'baz' => 'bat', - 'blah' => null, - 'enum1' => TestBackedEnum::Foo->value, - 'enum2' => TestBackedIntEnum::FooBar->name, - 'enum3' => TestUnitEnum::Baz->name, - 'uuid' => $uuid->toString(), - 'date1' => $date1->format('Y-m-d\TH:i:s.uP'), - 'date2' => $date2->format('Y-m-d\TH:i:s.uP'), - 'timeZone' => 'Australia/Sydney', - ]; - - $decorator = new ObjectDecorator($source); - - $this->assertInstanceOf(ContextProvider::class, $decorator); - $this->assertSame($expected, iterator_to_array($decorator)); - $this->assertSame($expected, $decorator->all()); - $this->assertSame($expected, $decorator->context()); - $this->assertSame($expected, $this->factory->make($source)); - $this->assertSame(array_keys($expected), $decorator->keys()); - } - - public function testItCanCustomiseDateFormat(): void - { - $date = new DateTimeImmutable('2025-01-01 12:34:56', new \DateTimeZone('Australia/Sydney')); - - $source = new class ($date) implements Message { - public function __construct(public DateTimeInterface $date) - { - } - }; - - $expected = [ - 'date' => $date->format('Y-m-d H:i:s'), - ]; - - $decorator = new ObjectDecorator($source, dateFormat: 'Y-m-d H:i:s'); - - $this->assertSame($expected, $decorator->context()); - } - - public function testItCanTurnOffDateFormatting(): void - { - $date = new DateTimeImmutable('2025-01-01 12:34:56', new \DateTimeZone('Australia/Sydney')); - - $source = new class ($date) implements Message { - public function __construct(public DateTimeInterface $date) - { - } - }; - - $expected = [ - 'date' => $date, - ]; - - $decorator = new ObjectDecorator($source, dateFormat: null); - - $this->assertSame($expected, $decorator->context()); - } - - public function testItExcludesSensitiveProperties(): void - { - $source = new class ('Hello', 'World') implements Message { - public string $foo = 'bar'; - #[Sensitive] - public string $baz = 'bat'; - public string $foobar = 'foobar'; - - public function __construct( - #[Sensitive] public string $blah1, - public string $blah2, - ) { - } - }; - - $expected = [ - 'foo' => 'bar', - 'foobar' => 'foobar', - 'blah2' => 'World', - ]; - - $decorator = new ObjectDecorator($source); - - $this->assertSame(array_keys($expected), $decorator->keys()); - $this->assertSame($expected, $decorator->all()); - $this->assertSame($expected, $decorator->context()); - $this->assertSame($expected, $this->factory->make($source)); - } -} diff --git a/tests/Unit/Bus/Loggable/ResultDecoratorTest.php b/tests/Unit/Bus/Loggable/ResultDecoratorTest.php deleted file mode 100644 index 3590b4b1..00000000 --- a/tests/Unit/Bus/Loggable/ResultDecoratorTest.php +++ /dev/null @@ -1,294 +0,0 @@ - - */ -interface ResultWithContext extends IResult, ContextProvider -{ -} - -interface ErrorWithContext extends IError, ContextProvider -{ -} - -class ResultDecoratorTest extends TestCase -{ - private SimpleContextFactory $factory; - - protected function setUp(): void - { - parent::setUp(); - $this->factory = new SimpleContextFactory(); - } - - protected function tearDown(): void - { - parent::tearDown(); - unset($this->factory); - } - - public function testSuccess(): void - { - $result = Result::ok(); - - $expected = [ - 'success' => true, - ]; - - $decorator = new ResultDecorator($result); - - $this->assertInstanceOf(ContextProvider::class, $decorator); - $this->assertSame($expected, $decorator->context()); - $this->assertSame($expected, $this->factory->make($result)); - } - - public function testSuccessWithContextProvider(): void - { - $expected = [ - 'success' => true, - 'value' => [ - 'foo' => 'bar', - 'blah!' => 'blah!!', - ], - ]; - - $value = $this->createMock(ContextProvider::class); - $value->method('context')->willReturn($expected['value']); - - $result = Result::ok($value); - - $this->assertSame($expected, (new ResultDecorator($result))->context()); - $this->assertSame($expected, $this->factory->make($result)); - } - - public function testSuccessWithIdentifier(): void - { - $expected = [ - 'success' => true, - 'value' => 99, - ]; - - $value = $this->createMock(Contextual::class); - $value->method('context')->willReturn($expected['value']); - - $result = Result::ok($value); - - $this->assertSame($expected, (new ResultDecorator($result))->context()); - $this->assertSame($expected, $this->factory->make($result)); - } - - /** - * @return array> - */ - public static function scalarProvider(): array - { - return [ - [true], - [false], - [1], - [1.1], - ['foo'], - ]; - } - - #[DataProvider('scalarProvider')] - public function testSuccessWithScalarOrNull(mixed $value): void - { - $expected = [ - 'success' => true, - 'value' => $value, - ]; - - $result = Result::ok($value); - - $this->assertSame($expected, (new ResultDecorator($result))->context()); - $this->assertSame($expected, $this->factory->make($result)); - } - - public function testSuccessContextWithMeta(): void - { - $result = Result::ok()->withMeta(['foo' => 'bar']); - - $expected = [ - 'success' => true, - 'meta' => [ - 'foo' => 'bar', - ], - ]; - - $this->assertSame($expected, (new ResultDecorator($result))->context()); - $this->assertSame($expected, $this->factory->make($result)); - } - - /** - * @return array> - */ - public static function onlyMessageProvider(): array - { - return [ - ['Something went wrong.'], - [new Error(message: 'Something went wrong.')], - ]; - } - - #[DataProvider('onlyMessageProvider')] - public function testFailureContextWithErrorThatOnlyHasMessage(Error|string $error): void - { - $result = Result::failed($error); - - $expected = [ - 'success' => false, - 'error' => is_string($error) ? $error : $error->message(), - ]; - - $this->assertSame($expected, (new ResultDecorator($result))->context()); - $this->assertSame($expected, $this->factory->make($result)); - } - - /** - * @return array> - */ - public static function onlyCodeProvider(): array - { - return [ - [TestUnitEnum::Baz], - [new Error(code: TestBackedEnum::Bar)], - ]; - } - - /** - * @param BackedEnum|Error $error - */ - #[DataProvider('onlyCodeProvider')] - public function testFailureContextWithErrorThatOnlyHasCode(Error|UnitEnum $error): void - { - $result = Result::failed($error); - $code = $error instanceof UnitEnum ? $error : $error->code(); - - $expected = [ - 'success' => false, - 'error' => enum_string($code ?? '!!'), - ]; - - $this->assertSame($expected, (new ResultDecorator($result))->context()); - $this->assertSame($expected, $this->factory->make($result)); - } - - /** - * @return array> - */ - public static function errorsProvider(): array - { - $error1 = new Error( - code: TestBackedEnum::Bar, - message: 'Something went wrong.', - key: 'foo', - ); - - $error2 = new Error( - code: TestBackedIntEnum::FooBar, - message: 'Something else went wrong.', - key: TestBackedIntEnum::BazBat, - ); - - $expected1 = [ - 'code' => TestBackedEnum::Bar->value, - 'key' => 'foo', - 'message' => 'Something went wrong.', - ]; - - $expected2 = [ - 'code' => TestBackedIntEnum::FooBar->name, - 'key' => TestBackedIntEnum::BazBat->name, - 'message' => 'Something else went wrong.', - ]; - - return [ - [[$error1], [$expected1]], - [[$error1, $error2], [$expected1, $expected2]], - ]; - } - - /** - * @param array $errors - * @param array> $expected - */ - #[DataProvider('errorsProvider')] - public function testFailureContextWithMeta(array $errors, array $expected): void - { - $result = Result::failed($errors)->withMeta(['baz' => 'bat']); - - $expected = [ - 'success' => false, - 'errors' => $expected, - 'meta' => [ - 'baz' => 'bat', - ], - ]; - - $this->assertSame($expected, (new ResultDecorator($result))->context()); - $this->assertSame($expected, $this->factory->make($result)); - } - - public function testItHasLogContext(): void - { - $mock = $this->createMock(ResultWithContext::class); - $mock->method('context')->willReturn($expected = ['foo' => 'bar', 'baz' => 'bat']); - - $this->assertSame($expected, (new ResultDecorator($mock))->context()); - $this->assertSame($expected, $this->factory->make($mock)); - } - - public function testItHasErrorWithLogContext(): void - { - $mock = $this->createMock(ErrorWithContext::class); - $mock->method('context')->willReturn($expected = ['foo' => 'bar', 'baz' => 'bat']); - - $error = new Error(null, 'Something went wrong.'); - - $result = Result::failed([$mock, $error]); - - $expected = [ - 'success' => false, - 'errors' => [ - $expected, - [ - 'message' => 'Something went wrong.', - ], - ], - ]; - - $this->assertSame($expected, (new ResultDecorator($result))->context()); - $this->assertSame($expected, $this->factory->make($result)); - } -} diff --git a/tests/Unit/Infrastructure/ExceptionReporter/PsrLogExceptionReporterTest.php b/tests/Unit/Infrastructure/ExceptionReporter/PsrLogExceptionReporterTest.php index 179b29e7..9fc79686 100644 --- a/tests/Unit/Infrastructure/ExceptionReporter/PsrLogExceptionReporterTest.php +++ b/tests/Unit/Infrastructure/ExceptionReporter/PsrLogExceptionReporterTest.php @@ -13,7 +13,6 @@ namespace CloudCreativity\Modules\Tests\Unit\Infrastructure\ExceptionReporter; use CloudCreativity\Modules\Contracts\Application\Ports\ExceptionReporter; -use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider; use CloudCreativity\Modules\Infrastructure\ExceptionReporter\PsrLogExceptionReporter; use LogicException; use PHPUnit\Framework\MockObject\MockObject; @@ -73,7 +72,10 @@ public function testItReportsDefaultMessageIfExceptionHasEmptyMessage(): void public function testItLogsContextForExceptionThatImplementsContextProvider(): void { - $exception = new class ('Boom!') extends LogicException implements ContextProvider { + $exception = new class ('Boom!') extends LogicException { + /** + * @return array + */ public function context(): array { return ['foo' => 'bar', 'exception' => null]; diff --git a/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php b/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php deleted file mode 100644 index d907cf77..00000000 --- a/tests/Unit/Infrastructure/OutboundEventBus/Middleware/LogOutboundEventTest.php +++ /dev/null @@ -1,117 +0,0 @@ -logger = $this->createMock(LoggerInterface::class); - $this->event = new TestOutboundEvent(); - } - - public function test(): void - { - $eventName = ModuleBasename::from($this->event); - - $this->logger - ->expects($this->exactly(2)) - ->method('log') - ->willReturnCallback(function ($level, $message, $context) use (&$logs): bool { - $logs[] = [$level, $message, $context]; - return true; - }); - - $middleware = new LogOutboundEvent($this->logger); - $middleware($this->event, function (IntegrationEvent $received): void { - $this->assertSame($this->event, $received); - }); - - $context = (new ObjectDecorator($this->event))->context(); - - $this->assertSame([ - [LogLevel::DEBUG, "Publishing integration event {$eventName}.", ['event' => $context]], - [LogLevel::INFO, "Published integration event {$eventName}.", ['event' => $context]], - ], $logs); - } - - public function testWithCustomLevels(): void - { - $eventName = ModuleBasename::from($this->event); - $logs = []; - - $this->logger - ->expects($this->exactly(2)) - ->method('log') - ->willReturnCallback(function ($level, $message, $context) use (&$logs): bool { - $logs[] = [$level, $message, $context]; - return true; - }); - - $middleware = new LogOutboundEvent($this->logger, LogLevel::NOTICE, LogLevel::WARNING); - $middleware($this->event, function (IntegrationEvent $received) { - $this->assertSame($this->event, $received); - }); - - $context = (new ObjectDecorator($this->event))->context(); - - $this->assertSame([ - [LogLevel::NOTICE, "Publishing integration event {$eventName}.", ['event' => $context]], - [LogLevel::WARNING, "Published integration event {$eventName}.", ['event' => $context]], - ], $logs); - } - - public function testItLogsAfterTheNextClosureIsInvoked(): void - { - $expected = new LogicException(); - $eventName = ModuleBasename::from($this->event); - - $context = (new ObjectDecorator($this->event))->context(); - - $this->logger - ->expects($this->once()) - ->method('log') - ->with(LogLevel::DEBUG, "Publishing integration event {$eventName}.", ['event' => $context]); - - $middleware = new LogOutboundEvent($this->logger); - - try { - $middleware($this->event, static function () use ($expected) { - throw $expected; - }); - $this->fail('No exception thrown.'); - } catch (LogicException $ex) { - $this->assertSame($expected, $ex); - } - } -} diff --git a/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php b/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php deleted file mode 100644 index 94a6968c..00000000 --- a/tests/Unit/Infrastructure/Queue/Middleware/LogPushedToQueueTest.php +++ /dev/null @@ -1,153 +0,0 @@ -logger = $this->createMock(LoggerInterface::class); - $this->context = $this->createMock(ContextFactory::class); - } - - protected function tearDown(): void - { - parent::tearDown(); - unset($this->logger, $this->context); - } - - public function testWithDefaultLevels(): void - { - $command = new class () implements Command { - public string $foo = 'bar'; - public string $baz = 'bat'; - }; - - $name = $command::class; - $logs = []; - $context = $this->withContext($command); - - $this->logger - ->expects($this->exactly(2)) - ->method('log') - ->willReturnCallback(function ($level, $message, $context) use (&$logs): bool { - $logs[] = [$level, $message, $context]; - return true; - }); - - $middleware = new LogPushedToQueue($this->logger, context: $this->context); - $middleware( - $command, - function (Command $received) use ($command): void { - $this->assertSame($command, $received); - }, - ); - - $this->assertSame([ - [LogLevel::DEBUG, "Queuing command {$name}.", ['command' => $context]], - [LogLevel::INFO, "Queued command {$name}.", ['command' => $context]], - ], $logs); - } - - public function testWithCustomLevels(): void - { - $command = new class () implements Command { - public string $foo = 'bar'; - public string $baz = 'bat'; - }; - - $name = $command::class; - $logs = []; - $context = $this->withContext($command); - - $this->logger - ->expects($this->exactly(2)) - ->method('log') - ->willReturnCallback(function ($level, $message, $context) use (&$logs): bool { - $logs[] = [$level, $message, $context]; - return true; - }); - - $middleware = new LogPushedToQueue($this->logger, LogLevel::NOTICE, LogLevel::WARNING, $this->context); - $middleware($command, function (Command $received) use ($command): void { - $this->assertSame($command, $received); - }); - - $this->assertSame([ - [LogLevel::NOTICE, "Queuing command {$name}.", ['command' => $context]], - [LogLevel::WARNING, "Queued command {$name}.", ['command' => $context]], - ], $logs); - } - - public function testItLogsAfterTheNextClosureIsInvoked(): void - { - $command = new class () implements Command { - public string $foo = 'bar'; - public string $baz = 'bat'; - }; - - $expected = new LogicException(); - $name = $command::class; - $context = $this->withContext($command); - - $this->logger - ->expects($this->once()) - ->method('log') - ->with(LogLevel::DEBUG, "Queuing command {$name}.", ['command' => $context]); - - $middleware = new LogPushedToQueue($this->logger, context: $this->context); - - try { - $middleware($command, static function () use ($expected): never { - throw $expected; - }); - $this->fail('No exception thrown.'); - } catch (LogicException $ex) { - $this->assertSame($expected, $ex); - } - } - - /** - * @return array - */ - private function withContext(object $expected): array - { - $this->context - ->expects($this->once()) - ->method('make') - ->with($this->identicalTo($expected)) - ->willReturn($context = ['foobar' => 'bazbat!']); - - return $context; - } -} From b2315c0db8dafc58e72d04d53b0cdc57b50bd6b3 Mon Sep 17 00:00:00 2001 From: Christopher Gammie Date: Tue, 6 Jan 2026 06:53:01 +0000 Subject: [PATCH 8/8] wip: move sensitive attribute to toolkit --- docs/guide/application/commands.md | 2 +- src/Bus/SanitizedMessage.php | 1 + src/{Bus => Toolkit}/Sensitive.php | 2 +- 3 files changed, 3 insertions(+), 2 deletions(-) rename src/{Bus => Toolkit}/Sensitive.php (88%) diff --git a/docs/guide/application/commands.md b/docs/guide/application/commands.md index cdc1f40d..6c135d8e 100644 --- a/docs/guide/application/commands.md +++ b/docs/guide/application/commands.md @@ -602,7 +602,7 @@ However, there may be scenarios where a property should not be logged, e.g. beca In this scenario, use the `Sensitive` attribute on the property, and it will not be logged: ```php -use CloudCreativity\Modules\Bus\Sensitive;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; +use CloudCreativity\Modules\Toolkit\Sensitive;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier; final readonly class CancelAttendeeTicketCommand implements Command { diff --git a/src/Bus/SanitizedMessage.php b/src/Bus/SanitizedMessage.php index 4e773a1a..14af304f 100644 --- a/src/Bus/SanitizedMessage.php +++ b/src/Bus/SanitizedMessage.php @@ -14,6 +14,7 @@ use CloudCreativity\Modules\Contracts\Messaging\Message; use CloudCreativity\Modules\Contracts\Toolkit\Contextual; +use CloudCreativity\Modules\Toolkit\Sensitive; use Generator; use IteratorAggregate; use ReflectionClass; diff --git a/src/Bus/Sensitive.php b/src/Toolkit/Sensitive.php similarity index 88% rename from src/Bus/Sensitive.php rename to src/Toolkit/Sensitive.php index ad86cc64..2e662e36 100644 --- a/src/Bus/Sensitive.php +++ b/src/Toolkit/Sensitive.php @@ -10,7 +10,7 @@ declare(strict_types=1); -namespace CloudCreativity\Modules\Bus; +namespace CloudCreativity\Modules\Toolkit; use Attribute;