Skip to content

Commit

Permalink
Merge branch 'release/2.0.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Dec 7, 2024
2 parents f97c75c + 29a33e4 commit e82567a
Show file tree
Hide file tree
Showing 245 changed files with 535 additions and 223 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,17 @@ All notable changes to this project will be documented in this file. This projec

## Unreleased

## [2.0.0] - 2024-12-07

### Changed

- **BREAKING** Removed the sub-namespaces for ports provided by this package, i.e.:
- `Contracts\Application\Ports\Driven` all interfaces are no longer in sub-namespaces; and
- `Contracts\Application\Ports\Driven` also has the same change.
- **BREAKING** Renamed the `InboundEventBus\EventDispatcher` port to `InboundEventDispatcher`.
- **BREAKING** Renamed the `OutboundEventBus\EventPublisher` port to `OutboundEventPublisher`.
- Upgraded to PHPStan v2.

## [2.0.0-rc.3] - 2024-10-13

### Added
Expand All @@ -16,6 +27,10 @@ All notable changes to this project will be documented in this file. This projec
is already implemented.
- New `AggregateRoot` interface so that an aggregate root can be distinguished from a regular aggregate or entity.

### Changed

- Remove deprecation message in PHP 8.4.

## [2.0.0-rc.2] - 2024-07-27

### Added
Expand Down Expand Up @@ -312,3 +327,5 @@ All notable changes to this project will be documented in this file. This projec
## [0.1.0] - 2023-11-18

Initial release.

[2.0.0]: https://github.com/cloudcreativity/docs.dancecloud.com/compare/v2.0.0-rc.3...v2.0.0
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
},
"require-dev": {
"laravel/pint": "^1.15",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^2.0",
"phpunit/phpunit": "^10.4"
},
"autoload": {
Expand Down
20 changes: 10 additions & 10 deletions docs/guide/application/asynchronous-processing.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ For example, an endpoint that triggers a recalculation of our sales report:
namespace App\Http\Controllers\Api\AttendanceReport;

use App\Modules\EventManagement\Application\{
Ports\Driving\Commands\CommandBus,
Ports\Driving\CommandBus,
UsesCases\Commands\RecalculateSalesAtEvent\RecalculateSalesAtEventCommand,
};
use CloudCreativity\Modules\Toolkit\Identifiers\IntegerId;
Expand Down Expand Up @@ -95,7 +95,7 @@ processing. Some examples of where your application layer might need to push int
Or anything else that fits with the specific use case of your bounded context!

Our approach is to define this work as _internal_ command messages. These are queued and dispatched by a specific
_internal_ command bus - separating them from the command bus that is an adapter of the driving port in the application
_internal_ command bus - separating them from the command bus that implements the driving port in the application
layer.

This means internal commands are not exposed as use cases of our module - making them an internal implementation detail
Expand Down Expand Up @@ -177,12 +177,12 @@ command is queued by an infrastructure adapter, it has left the application laye
queue for processing, it needs to re-enter the application layer via a driving port.

However, by defining this as a separate port to our public command bus, we can ensure that internal commands are only
dispatched by the internal command bus adapter.
dispatched by the internal command bus.

Define the port as follows:
Define the internal command bus as follows:

```php
namespace App\Modules\EventManagement\Application\Ports\Driving\CommandBus;
namespace App\Modules\EventManagement\Application\Ports\Driving;

use CloudCreativity\Modules\Application\Ports\Driving\CommandBus\CommandDispatcher;

Expand All @@ -191,15 +191,15 @@ interface InternalCommandBus extends CommandDispatcher
}
```

And then our adapter (the concrete implementation of the port) is as follows:
And then our port implementation is as follows:

```php
namespace App\Modules\EventManagement\Application\Adapters\CommandBus;
namespace App\Modules\EventManagement\Application\Bus;

use App\Modules\EventManagement\Application\Ports\Driving\CommandBus\InternalCommandBus;
use App\Modules\EventManagement\Application\Ports\Driving\InternalCommandBus;
use CloudCreativity\Modules\Application\Bus\CommandDispatcher;

final class InternalCommandBusAdapter extends CommandDispatcher implements
final class InternalCommandBusService extends CommandDispatcher implements
InternalCommandBus
{
}
Expand All @@ -221,7 +221,7 @@ public commands. I.e.:
```php
namespace App\Modules\EventManagement\Application\Ports\Driven\Queue;

use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue\Queue as Port;
use CloudCreativity\Modules\Contracts\Application\Ports\Driven\Queue as Port;

// queues public commands
interface Queue extends Port
Expand Down
48 changes: 23 additions & 25 deletions docs/guide/application/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -126,32 +126,31 @@ Although there is a _generic_ command bus interface, our bounded context needs t
We do this by defining an interface in our application's driving ports.

```php
namespace App\Modules\EventManagement\Application\Ports\Driving\CommandBus;
namespace App\Modules\EventManagement\Application\Ports\Driving;

use CloudCreativity\Modules\Application\Ports\Driving\CommandBus\CommandDispatcher;
use CloudCreativity\Modules\Application\Ports\Driving\CommandDispatcher;

interface CommandBus extends CommandDispatcher
{
}
```

And then our adapter (the concrete implementation of the port) is as follows:
And then our implementation is as follows:

```php
namespace App\Modules\EventManagement\Application\Adapters\CommandBus;
namespace App\Modules\EventManagement\Application\Bus;

use App\Modules\EventManagement\Application\Ports\Driving\CommandBus\CommandBus;
use App\Modules\EventManagement\Application\Ports\Driving\CommandBus as Port;
use CloudCreativity\Modules\Application\Bus\CommandDispatcher;

final class CommandBusAdapter extends CommandDispatcher implements
CommandBus
final class CommandBus extends CommandDispatcher implements Port
{
}
```

### Creating a Command Bus

The command dispatcher class that your adapter extended (in the above example) allows you to build a command bus
The command dispatcher class that your implementation extends (in the above example) allows you to build a command bus
specific to your domain. You do this by:

1. Binding command handler factories into the command dispatcher; and
Expand All @@ -164,29 +163,29 @@ handler or middleware are actually being used.
For example:

```php
namespace App\Modules\EventManagement\Application\Adapters\CommandBus;
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\CommandBus;
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;

final class CommandBusAdapterProvider
final class CommandBusProvider
{
public function __construct(
private readonly ExternalDependencies $dependencies,
) {
}

public function getCommandBus(): CommandBus
public function getCommandBus(): CommandBusPort
{
$bus = new CommandBusAdapter(
$bus = new CommandBus(
handlers: $handlers = new CommandHandlerContainer(),
middleware: $middleware = new PipeContainer(),
);
Expand Down Expand Up @@ -222,15 +221,15 @@ final class CommandBusAdapterProvider
}
```

As the presentation and delivery layer is the user of the driving ports, we can now bind the port and its adapter into a
service container. For example, in Laravel:
Adapters in the presentation and delivery layer will use the driving ports. Typically this means we need to bind the
port into a service container. For example, in Laravel:

```php
namespace App\Providers;

use App\Modules\EventManagement\Application\{
Adapters\CommandBus\CommandBusAdapterProvider,
Ports\Driving\CommandBus\CommandBus,
Bus\CommandBusProvider,
Ports\Driving\CommandBus,
};
use Illuminate\Contracts\Container\Container;
use Illuminate\Support\ServiceProvider;
Expand All @@ -242,13 +241,12 @@ final class EventManagementServiceProvider extends ServiceProvider
$this->app->bind(
CommandBus::class,
static function (Container $app) {
$provider = $app->make(CommandBusAdapterProvider::class);
$provider = $app->make(CommandBusProvider::class);
return $provider->getCommandBus();
},
);
}
}

```

### Dispatching Commands
Expand All @@ -260,8 +258,8 @@ a single action controller to handle a HTTP request in a Laravel application, we
namespace App\Http\Controllers\Api\Attendees;

use App\Modules\EventManagement\Application\{
Ports\Driving\CommandBus\CommandBus,
UsesCases\Commands\CancelAttendeeTicket\CancelAttendeeTicketCommand,
Ports\Driving\CommandBus,
UseCases\Commands\CancelAttendeeTicket\CancelAttendeeTicketCommand,
};
use CloudCreativity\Modules\Toolkit\Identifiers\IntegerId;
use Illuminate\Validation\Rule;
Expand Down Expand Up @@ -322,8 +320,8 @@ updated to return a `202 Accepted` response to indicate the command has been que
namespace App\Http\Controllers\Api\Attendees;

use App\Modules\EventManagement\Application\{
Ports\Driving\CommandBus\CommandBus,
UsesCases\Commands\CancelAttendeeTicket\CancelAttendeeTicketCommand,
Ports\Driving\CommandBus,
UseCases\Commands\CancelAttendeeTicket\CancelAttendeeTicketCommand,
};
use CloudCreativity\Modules\Toolkit\Identifiers\IntegerId;
use Illuminate\Validation\Rule;
Expand Down Expand Up @@ -573,7 +571,7 @@ You can write your own middleware to suit your specific needs. Middleware is a s
following signature:

```php
namespace App\Modules\EventManagement\Application\Adapters\Middleware;
namespace App\Modules\EventManagement\Application\Bus\Middleware;

use Closure;
use CloudCreativity\Modules\Contracts\Application\Bus\CommandMiddleware;
Expand Down Expand Up @@ -615,7 +613,7 @@ If you want to write middleware that can be used with both commands and queries,
instead:

```php
namespace App\Modules\EventManagement\Application\Adapters\Middleware;
namespace App\Modules\EventManagement\Application\Bus\Middleware;

use Closure;
use CloudCreativity\Modules\Contracts\Application\Bus\BusMiddleware;
Expand Down
18 changes: 9 additions & 9 deletions docs/guide/application/domain-events.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,9 +169,9 @@ Although this sounds like a lot of work, we provide the tools to make this easy.
above:

```php
namespace App\Modules\EventManagement\Application\Adapters\CommandBus;
namespace App\Modules\EventManagement\Application\Bus;

use App\Modules\EventManagement\Application\Ports\Driving\CommandBus\CommandBus;
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;
Expand All @@ -182,7 +182,7 @@ use CloudCreativity\Modules\Application\Bus\Middleware\SetupBeforeDispatch;
use CloudCreativity\Modules\Application\UnitOfWork\UnitOfWorkManager;
use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;

final class CommandBusAdapterProvider
final class CommandBusProvider
{
/**
* @var UnitOfWorkManager|null
Expand All @@ -202,7 +202,7 @@ final class CommandBusAdapterProvider

public function getCommandBus(): CommandBus
{
$bus = new CommandBusAdapter(
$bus = new CommandBus(
handlers: $handlers = new CommandHandlerContainer(),
middleware: $middleware = new PipeContainer(),
);
Expand Down Expand Up @@ -407,9 +407,9 @@ into the middleware that flushes deferred events.
Here's an example:

```php
namespace App\Modules\EventManagement\Application\Adapters\CommandBus;
namespace App\Modules\EventManagement\Application\Bus;

use App\Modules\EventManagement\Application\Ports\Driving\CommandBus\CommandBus;
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;
Expand All @@ -419,7 +419,7 @@ use CloudCreativity\Modules\Application\Bus\Middleware\FlushDeferredEvents;
use CloudCreativity\Modules\Application\Bus\Middleware\SetupBeforeDispatch;
use CloudCreativity\Modules\Toolkit\Pipeline\PipeContainer;

final class CommandBusAdapterProvider
final class CommandBusProvider
{
/**
* @var DomainEventDispatcher|null
Expand All @@ -432,9 +432,9 @@ final class CommandBusAdapterProvider
) {
}

public function getCommandBus(): CommandBus
public function getCommandBus(): CommandBusPort
{
$bus = new CommandBusAdapter(
$bus = new CommandBus(
handlers: $handlers = new CommandHandlerContainer(),
middleware: $middleware = new PipeContainer(),
);
Expand Down
Loading

0 comments on commit e82567a

Please sign in to comment.