Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions .github/workflows/documentation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: Documentation

on:
pull_request:
types: [ closed ]

jobs:
publish:
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest

steps:
- name: Checkout source code
uses: actions/checkout@v2

- name: Pusblish Wiki
uses: SwiftDocOrg/github-wiki-publish-action@v1
with:
path: "wiki/"
env:
GH_PERSONAL_ACCESS_TOKEN: ${{ secrets.GH_PERSONAL_ACCESS_TOKEN }}
21 changes: 21 additions & 0 deletions wiki/DomainModeling.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
## Domain Modeling: Aggregates, Entities and Value Objects

Complex Heart allows you to model your domain Aggregates, Entities, and Value Objects using a set of traits. Great, but
why traits and not classes? Well, sometimes you have some kind of inheritance in your classes. Being forced to use a
certain base class is too invasive and personally, I don't like it. By using a set of traits and interfaces you have all
the functionality you need without compromising the essence of your own domain.

The available traits are:

- `HasAttributes` Provide some functionality to manage attributes.
- `HasEquality` Provide functionality to handle equality between objects.
- `HasInvariants` Allow invariant checking on instantiation (Guard Clause).
- `HasIdentity` Define the Entity/Aggregate identity.
- `HasDomainEvents` Provide domain event management.

On top of those base traits **Complex Heart** provide ready to use compositions:

- `IsModel` composed by `HasAttributes` and `HasInvariants`
- `IsValueObject` composed by `IsModel` and `HasEquality`
- `IsEntity` composed by `IsModel`, `HasIdentity`, `HasEquality`
- `IsAggregate` composed by `IsEntity`, `HasDomainEvents`
37 changes: 37 additions & 0 deletions wiki/DomainModeling_ValueObjects.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# Value Objects

```php
use OtherCode\ComplexHeart\Domain\Contracts\ValueObject;
use OtherCode\ComplexHeart\Domain\Traits\IsValueObject;

/**
* Class Color
* @method string value()
*/
final class Color implements ValueObject
{
use IsValueObject;

private string $value;

public function __construct(string $value)
{
$this->initialize(['value' => $value]);
}

protected function invariantValueMustBeHexadecimal(): bool
{
return preg_match('/^#(?:[0-9a-fA-F]{3}){1,2}$/', $this->value) === 1;
}

public function __toString(): string
{
return $this->value();
}
}

$red = new Color('#ff0000');
$red->equals(new Color('#00ff00')); // false
$red->value(); // #ff0000
$magenta = new Color('ff00ff'); // Exception InvariantViolation: Value must be hexadecimal.
```
2 changes: 2 additions & 0 deletions wiki/Home.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Home

17 changes: 17 additions & 0 deletions wiki/ServiceBus.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
## Service Bus: Commands, Queries and Events

The Service Bus integration contains some basic interfaces (`ServiceBus`, `CommandBus`, `QueryBus`, and `EventBus`) and
classes to build on top of them.

- `Message` Base DTO to transfer objects between layers.
- `Request`
- `Command` Command DTO.
- `Event` Event DTO.
- `Query` Query DTO.
- `Response`

Check this small example of the query bus usage:

```php
$response = $queryBus->ask(new GetUserQuery('some-uuid-value'));
```
7 changes: 7 additions & 0 deletions wiki/_Sidebar.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
- [Home](Home)
- [Domain Modeling](DomainModeling)
- Aggregates
- Entities
- [Value Objects](DomainModeling_ValueObjects)
- [Service Bus](Service Bus)
- Criteria Pattern