Skip to content

Commit 33d12ae

Browse files
refactor: move bus and messages into their own namespace (#32)
1 parent d083916 commit 33d12ae

File tree

214 files changed

+1375
-2723
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

214 files changed

+1375
-2723
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
"require-dev": {
3333
"deptrac/deptrac": "^4.4",
3434
"laravel/pint": "^1.26",
35+
"monolog/monolog": "^3.9",
3536
"phpstan/phpstan": "^2.1",
3637
"phpunit/phpunit": "^11.5"
3738
},

deptrac.yaml

Lines changed: 39 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -2,32 +2,38 @@ deptrac:
22
paths:
33
- ./src
44
layers:
5-
- name: Toolkit
5+
- name: Application
66
collectors:
77
- type: classLike
8-
value: CloudCreativity\\Modules\\Contracts\\Toolkit\\*
8+
value: CloudCreativity\\Modules\\Contracts\\Application\\*
99
- type: classLike
10-
value: CloudCreativity\\Modules\\Toolkit\\*
10+
value: CloudCreativity\\Modules\\Application\\*
11+
- name: Bus
12+
collectors:
1113
- type: classLike
12-
value: Ramsey\\Uuid\\*
14+
value: CloudCreativity\\Modules\\Contracts\\Bus\\*
15+
- type: classLike
16+
value: CloudCreativity\\Modules\\Bus\\*
1317
- name: Domain
1418
collectors:
1519
- type: classLike
1620
value: CloudCreativity\\Modules\\Contracts\\Domain\\*
1721
- type: classLike
1822
value: CloudCreativity\\Modules\\Domain\\*
19-
- name: Application
20-
collectors:
21-
- type: classLike
22-
value: CloudCreativity\\Modules\\Contracts\\Application\\*
23-
- type: classLike
24-
value: CloudCreativity\\Modules\\Application\\*
2523
- name: Infrastructure
2624
collectors:
2725
- type: classLike
2826
value: CloudCreativity\\Modules\\Contracts\\Infrastructure\\*
2927
- type: classLike
3028
value: CloudCreativity\\Modules\\Infrastructure\\*
29+
- type: classLike
30+
value: Monolog\\*
31+
- name: Messaging
32+
collectors:
33+
- type: classLike
34+
value: CloudCreativity\\Modules\\Contracts\\Messaging\\*
35+
- type: classLike
36+
value: CloudCreativity\\Modules\\Messaging\\*
3137
- name: PSR Container
3238
collectors:
3339
- type: classLike
@@ -36,27 +42,38 @@ deptrac:
3642
collectors:
3743
- type: classLike
3844
value: Psr\\Log\\*
39-
- name: Attributes
45+
- name: Toolkit
4046
collectors:
47+
- type: classLike
48+
value: CloudCreativity\\Modules\\Contracts\\Toolkit\\*
49+
- type: classLike
50+
value: CloudCreativity\\Modules\\Toolkit\\*
51+
- type: classLike
52+
value: Ramsey\\Uuid\\*
4153
- type: classLike
4254
value: ^Deprecated$
4355
ruleset:
44-
Toolkit:
45-
- Attributes
46-
- PSR Container
47-
Domain:
48-
- Toolkit
49-
- Attributes
5056
Application:
51-
- Toolkit
57+
- Bus
5258
- Domain
59+
- Messaging
5360
- PSR Container
5461
- PSR Log
55-
- Attributes
56-
Infrastructure:
5762
- Toolkit
58-
- Domain
63+
Bus:
64+
- Messaging
65+
- PSR Container
66+
- PSR Log
67+
- Toolkit
68+
Domain:
69+
- Toolkit
70+
Infrastructure:
5971
- Application
72+
- Bus
73+
- Messaging
6074
- PSR Container
6175
- PSR Log
62-
- Attributes
76+
- Toolkit
77+
Messaging:
78+
- Toolkit
79+
Toolkit:

docs/guide/application/asynchronous-processing.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,7 @@ And then our port adapter is as follows:
197197
```php
198198
namespace App\Modules\EventManagement\Application\Bus;
199199

200-
use App\Modules\EventManagement\Application\Ports\Driven\Queue\InternalCommandBus;
201-
use CloudCreativity\Modules\Application\Bus\CommandDispatcher;
200+
use App\Modules\EventManagement\Application\Ports\Driven\Queue\InternalCommandBus;use CloudCreativity\Modules\Bus\CommandDispatcher;
202201

203202
final class InternalCommandBusAdapter extends CommandDispatcher implements
204203
InternalCommandBus
@@ -221,7 +220,7 @@ public commands. I.e.:
221220
```php
222221
namespace App\Modules\EventManagement\Application\Ports\Driven\Queue;
223222

224-
use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue as Port;
223+
use CloudCreativity\Modules\Contracts\Application\Ports\Queue as Port;
225224

226225
// injected into the command queuer for queuing public commands
227226
interface Queue extends Port
@@ -239,4 +238,4 @@ internal bus - to dispatch the command to when it is pulled from the queue.
239238

240239
If you prefer, it is acceptable to define a single queue driven port. This simplifies the implementation by having a
241240
single queue that deals with both. However, you might find it gets complicated knowing whether to dispatch queued
242-
commands to either the public or internal command bus.
241+
commands to either the public or internal command bus.

docs/guide/application/commands.md

Lines changed: 14 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,7 @@ For example:
1818
```php
1919
namespace App\Modules\EventManagement\Application\UseCases\Commands\CancelAttendeeTicket;
2020

21-
use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;
22-
use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command;
23-
use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum;
21+
use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;use VendorName\EventManagement\Shared\Enums\CancellationReasonEnum;
2422

2523
final readonly class CancelAttendeeTicketCommand implements Command
2624
{
@@ -52,10 +50,7 @@ For example:
5250
```php
5351
namespace App\Modules\EventManagement\Application\UseCases\Commands\CancelAttendeeTicket;
5452

55-
use App\Modules\EventManagement\Application\Ports\Driven\Persistence\AttendeeRepository;
56-
use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork;
57-
use CloudCreativity\Modules\Contracts\Application\Messages\DispatchThroughMiddleware;
58-
use CloudCreativity\Modules\Toolkit\Results\Result;
53+
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;
5954

6055
final readonly class CancelAttendeeTicketHandler implements
6156
DispatchThroughMiddleware
@@ -142,8 +137,7 @@ And then our implementation is as follows:
142137
```php
143138
namespace App\Modules\EventManagement\Application\Bus;
144139

145-
use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as Port;
146-
use CloudCreativity\Modules\Application\Bus\CommandDispatcher;
140+
use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as Port;use CloudCreativity\Modules\Bus\CommandDispatcher;
147141

148142
final class CommandBus extends CommandDispatcher implements Port
149143
{
@@ -167,16 +161,7 @@ For example:
167161
```php
168162
namespace App\Modules\EventManagement\Application\Bus;
169163

170-
use App\Modules\EventManagement\Application\UsesCases\Commands\{
171-
CancelAttendeeTicket\CancelAttendeeTicketCommand,
172-
CancelAttendeeTicket\CancelAttendeeTicketHandler,
173-
};
174-
use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as CommandBusPort;
175-
use App\Modules\EventManagement\Application\Ports\Driven\DependencyInjection\ExternalDependencies;
176-
use CloudCreativity\Modules\Application\Bus\CommandHandlerContainer;
177-
use CloudCreativity\Modules\Application\Bus\Middleware\ExecuteInUnitOfWork;
178-
use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch;
179-
use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;
164+
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;
180165

181166
final class CommandBusProvider
182167
{
@@ -343,9 +328,7 @@ And then our implementation is as follows:
343328
```php
344329
namespace App\Modules\EventManagement\Application\Bus;
345330

346-
use App\Modules\EventManagement\Application\Ports\Driving\CommandQueuer as Port;
347-
use App\Modules\EventManagement\Application\Ports\Driven\Queue;
348-
use CloudCreativity\Modules\Application\Bus\CommandQueuer as Queuer;
331+
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;
349332

350333
final class CommandQueuer extends Queuer implements Port
351334
{
@@ -466,8 +449,7 @@ singleton instances of dependencies.
466449
For example:
467450

468451
```php
469-
use App\Modules\EventManagement\Domain\Services;
470-
use CloudCreativity\Modules\Application\Bus\Middleware\SetupBeforeDispatch;
452+
use App\Modules\EventManagement\Domain\Services;use CloudCreativity\Modules\Bus\Middleware\SetupBeforeDispatch;
471453

472454
$middleware->bind(
473455
SetupBeforeDispatch::class,
@@ -497,7 +479,7 @@ If you only need to do teardown work, use the `TeardownAfterDispatch` middleware
497479
closure as its only constructor argument:
498480

499481
```php
500-
use CloudCreativity\Modules\Application\Bus\Middleware\TeardownAfterDispatch;
482+
use CloudCreativity\Modules\Bus\Middleware\TeardownAfterDispatch;
501483

502484
$middleware->bind(
503485
TeardownAfterDispatch::class,
@@ -578,7 +560,7 @@ Use our `LogMessageDispatch` middleware to log the dispatch of a command, and th
578560
[PSR Logger](https://php-fig.org/psr/psr-3/).
579561

580562
```php
581-
use CloudCreativity\Modules\Application\Bus\Middleware\LogMessageDispatch;
563+
use CloudCreativity\Modules\Bus\Middleware\LogMessageDispatch;
582564

583565
$middleware->bind(
584566
LogMessageDispatch::class,
@@ -620,9 +602,7 @@ However, there may be scenarios where a property should not be logged, e.g. beca
620602
In this scenario, use the `Sensitive` attribute on the property, and it will not be logged:
621603

622604
```php
623-
use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;
624-
use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command;
625-
use CloudCreativity\Modules\Toolkit\Loggable\Sensitive;
605+
use CloudCreativity\Modules\Toolkit\Sensitive;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;
626606

627607
final readonly class CancelAttendeeTicketCommand implements Command
628608
{
@@ -638,9 +618,7 @@ final readonly class CancelAttendeeTicketCommand implements Command
638618
If you need full control over the log context, implement the `ContextProvider` interface on your command message:
639619

640620
```php
641-
use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;
642-
use CloudCreativity\Modules\Contracts\Toolkit\Loggable\ContextProvider;
643-
use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command;
621+
use CloudCreativity\Modules\Contracts\Bus\Loggable\ContextProvider;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Identifiers\Identifier;
644622

645623
final readonly class CancelAttendeeTicketCommand implements
646624
Command,
@@ -670,10 +648,7 @@ following signature:
670648
```php
671649
namespace App\Modules\EventManagement\Application\Bus\Middleware;
672650

673-
use Closure;
674-
use CloudCreativity\Modules\Contracts\Application\Bus\CommandMiddleware;
675-
use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command;
676-
use CloudCreativity\Modules\Contracts\Toolkit\Result\Result;
651+
use Closure;use CloudCreativity\Modules\Contracts\Bus\Middleware\CommandMiddleware;use CloudCreativity\Modules\Contracts\Messaging\Command;use CloudCreativity\Modules\Contracts\Toolkit\Result\Result;
677652

678653
final class MyMiddleware implements CommandMiddleware
679654
{
@@ -685,7 +660,7 @@ final class MyMiddleware implements CommandMiddleware
685660
* @return Result<mixed>
686661
*/
687662
public function __invoke(
688-
Command $command,
663+
Command $command,
689664
Closure $next,
690665
): Result
691666
{
@@ -712,11 +687,7 @@ instead:
712687
```php
713688
namespace App\Modules\EventManagement\Application\Bus\Middleware;
714689

715-
use Closure;
716-
use CloudCreativity\Modules\Contracts\Application\Bus\BusMiddleware;
717-
use CloudCreativity\Modules\Contracts\Toolkit\Messages\Command;
718-
use CloudCreativity\Modules\Contracts\Toolkit\Messages\Query;
719-
use CloudCreativity\Modules\Contracts\Toolkit\Result\Result;
690+
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;
720691

721692
class MyBusMiddleware implements BusMiddleware
722693
{
@@ -728,7 +699,7 @@ class MyBusMiddleware implements BusMiddleware
728699
* @return Result<mixed>
729700
*/
730701
public function __invoke(
731-
Command|Query $message,
702+
Command|Query $message,
732703
Closure $next,
733704
): Result
734705
{

0 commit comments

Comments
 (0)