Skip to content

Commit

Permalink
Merge branch 'release/0.6.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
lindyhopchris committed Feb 7, 2024
2 parents 499cd61 + ca659a0 commit 68f1e92
Show file tree
Hide file tree
Showing 219 changed files with 4,425 additions and 527 deletions.
29 changes: 29 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,35 @@
All notable changes to this project will be documented in this file. This project adheres to
[Semantic Versioning](http://semver.org/) and [this changelog format](http://keepachangelog.com/).

## Unreleased

## [0.6.0] - 2024-02-07

### Added

- New `DeferredDispatcher` class for dispatching domain events when not using a unit of work.
- New UUID factory interface and class, that wraps the `ramsey/uuid` factory to return UUID identifiers.
- GUIDs that wrap UUIDs can now be created via the static `Guid::fromUuid()` method.
- New `SetupBeforeDispatch` and `TearDownAfterDispatch` bus middleware, that can be used either to setup (and optionally
tear down) application state around the dispatching of a message, or to just do tear down work.
- The `EventBus` namespace now has a working implementation for publishing integration events.
- Can now provide a closure to the `ListOfErrorsInterface::first()` method to find the first matching error.
- Added the following methods to the `ListOfErrorsInterface`:
- `contains()` - determines whether the list contains a matching error.
- `codes()` - returns an array containing the unique error codes in the list.
- Added an `ErrorInterface::is()` method to determine whether an error matches a given code.

### Changed

- **BREAKING** - renamed the domain event `Dispatcher` class to `UnitOfWorkAwareDispatcher`.
- **BREAKING** - removed the `IntegrationEvents` namespace and moved to the `Infrastructure\EventBus` namespace.
- **BREAKING** - the `IntegrationEventInterface` now expects the UUID to be an identifier UUID, not a Ramsey UUID.
- The UUID factory from the `ramsey/uuid` package is now used when creating new UUID identifiers.

### Fixed

- The unit of work manager now correctly handles re-attempts so that deferred events are not dispatched multiple times.

## [0.5.0] - 2023-12-02

### Added
Expand Down
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,23 @@
# Domain Driven Design Modules

**Write highly encapsulated and loosely coupled modules, for domain-centric architecture.**

## Documentation

This package provides a common PHP toolset for writing these modules.

**It can be tempting to dive straight into the code - you'll need to resist that temptation!**

The key to achieving highly encapsulated and loosely coupled modules is _how you use the tools in this package_. That is
described in the [documentation](https://github.com/cloudcreativity/ddd-modules/wiki) - so ensure you read the docs
before using these tools.

## Installation

```bash
composer require cloudcreativity/ddd-modules
```

## License

DDD Modules is open-sourced software licensed under the [Apache 2.0 License](./LICENSE).
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"require": {
"php": "^8.1",
"ext-json": "*",
"psr/log": "^3.0",
"psr/log": "^1.0.1 || ^2.0 || ^3.0",
"ramsey/uuid": "^4.7"
},
"require-dev": {
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/CommandDispatcher.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/CommandDispatcherInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/CommandHandler.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/CommandHandlerContainer.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/CommandHandlerContainerInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/CommandHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/CommandInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions src/Bus/DispatchThroughMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,7 +24,7 @@ interface DispatchThroughMiddleware
/**
* Get the middleware for the command or query.
*
* @return array<int,callable|string>
* @return array<callable|string>
*/
public function middleware(): array;
}
2 changes: 1 addition & 1 deletion src/Bus/MessageInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions src/Bus/Middleware/CommandMiddlewareInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ interface CommandMiddlewareInterface
* Handle the command.
*
* @param CommandInterface $command
* @param Closure $next
* @param Closure(CommandInterface): ResultInterface<mixed> $next
* @return ResultInterface<mixed>
*/
public function __invoke(CommandInterface $command, Closure $next): ResultInterface;
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/Middleware/ExecuteInUnitOfWork.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
59 changes: 59 additions & 0 deletions src/Bus/Middleware/FlushDeferredEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
/*
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace CloudCreativity\Modules\Bus\Middleware;

use Closure;
use CloudCreativity\Modules\Bus\MessageInterface;
use CloudCreativity\Modules\Infrastructure\DomainEventDispatching\DeferredDispatcherInterface;
use CloudCreativity\Modules\Toolkit\Result\ResultInterface;
use Throwable;

final class FlushDeferredEvents implements MessageMiddlewareInterface
{
/**
* FlushDeferredEvents constructor.
*
* @param DeferredDispatcherInterface $dispatcher
*/
public function __construct(private readonly DeferredDispatcherInterface $dispatcher)
{
}

/**
* @inheritDoc
*/
public function __invoke(MessageInterface $message, Closure $next): ResultInterface
{
try {
$result = $next($message);
} catch (Throwable $ex) {
$this->dispatcher->forget();
throw $ex;
}

if ($result->didSucceed()) {
$this->dispatcher->flush();
} else {
$this->dispatcher->forget();
}

return $result;
}
}
2 changes: 1 addition & 1 deletion src/Bus/Middleware/LogMessageDispatch.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
4 changes: 2 additions & 2 deletions src/Bus/Middleware/MessageMiddlewareInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ interface MessageMiddlewareInterface
* Handle the message.
*
* @param MessageInterface $message
* @param Closure $next
* @param Closure(MessageInterface): ResultInterface<mixed> $next
* @return ResultInterface<mixed>
*/
public function __invoke(MessageInterface $message, Closure $next): ResultInterface;
Expand Down
4 changes: 2 additions & 2 deletions src/Bus/Middleware/QueryMiddlewareInterface.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -29,7 +29,7 @@ interface QueryMiddlewareInterface
* Handle the query.
*
* @param QueryInterface $query
* @param Closure $next
* @param Closure(QueryInterface): ResultInterface<mixed> $next
* @return ResultInterface<mixed>
*/
public function __invoke(QueryInterface $query, Closure $next): ResultInterface;
Expand Down
57 changes: 57 additions & 0 deletions src/Bus/Middleware/SetupBeforeDispatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<?php
/*
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace CloudCreativity\Modules\Bus\Middleware;

use Closure;
use CloudCreativity\Modules\Bus\MessageInterface;
use CloudCreativity\Modules\Toolkit\Result\ResultInterface;

final class SetupBeforeDispatch implements MessageMiddlewareInterface
{
/**
* SetupBeforeDispatch constructor.
*
* @param Closure(): ?Closure(): void $callback
*/
public function __construct(private readonly Closure $callback)
{
}

/**
* @inheritDoc
*/
public function __invoke(MessageInterface $message, Closure $next): ResultInterface
{
$tearDown = ($this->callback)();

assert(
$tearDown === null || $tearDown instanceof Closure,
'Expecting setup function to return null or a teardown closure.',
);

try {
return $next($message);
} finally {
if ($tearDown) {
$tearDown();
}
}
}
}
48 changes: 48 additions & 0 deletions src/Bus/Middleware/TearDownAfterDispatch.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?php
/*
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

declare(strict_types=1);

namespace CloudCreativity\Modules\Bus\Middleware;

use Closure;
use CloudCreativity\Modules\Bus\MessageInterface;
use CloudCreativity\Modules\Toolkit\Result\ResultInterface;

final class TearDownAfterDispatch implements MessageMiddlewareInterface
{
/**
* TearDownAfterDispatch constructor.
*
* @param Closure(): void $callback
*/
public function __construct(private readonly Closure $callback)
{
}

/**
* @inheritDoc
*/
public function __invoke(MessageInterface $message, Closure $next): ResultInterface
{
try {
return $next($message);
} finally {
($this->callback)();
}
}
}
2 changes: 1 addition & 1 deletion src/Bus/Middleware/ValidateCommand.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
2 changes: 1 addition & 1 deletion src/Bus/Middleware/ValidateQuery.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/*
* Copyright 2023 Cloud Creativity Limited
* Copyright 2024 Cloud Creativity Limited
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading

0 comments on commit 68f1e92

Please sign in to comment.