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
36 changes: 18 additions & 18 deletions docs/cookbook/user-bundle/creating-a-user.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,31 @@
# Creating a User

Users can be created by dispatching the `CreateUserCommand` message with a data array that contains values for the `User`
Users can be created by dispatching the `CreateUser` message with a data array that contains values for the `User`
constructor arguments.

```php
<?php

use MsgPhp\User\Command\CreateUserCommand;
use MsgPhp\User\Command\CreateUser;
use Symfony\Component\Messenger\MessageBusInterface;

/** @var MessageBusInterface $bus */
$bus->dispatch(new CreateUserCommand([]));
$bus->dispatch(new CreateUser([]));
```

The handler will automatically add an `id` element to the data array holding an instance of `MsgPhp\User\UserIdInterface`.
The handler will automatically add an `id` element to the data array holding an instance of `MsgPhp\User\UserId`.
Alternatively it can be passed upfront:

```php
<?php

use MsgPhp\User\UserId;
use MsgPhp\User\Command\CreateUserCommand;
use MsgPhp\User\ScalarUserId;
use MsgPhp\User\Command\CreateUser;
use Symfony\Component\Messenger\MessageBusInterface;

/** @var MessageBusInterface $bus */
$bus->dispatch(new CreateUserCommand([
'id' => new UserId(),
$bus->dispatch(new CreateUser([
'id' => new ScalarUserId(),
]));
```

Expand All @@ -34,15 +34,15 @@ To programmatically factorize an [identifier](../../ddd/identifiers.md), use the
```php
<?php

use MsgPhp\Domain\Factory\DomainObjectFactoryInterface;
use MsgPhp\User\UserIdInterface;
use MsgPhp\User\Command\CreateUserCommand;
use MsgPhp\Domain\Factory\DomainObjectFactory;
use MsgPhp\User\UserId;
use MsgPhp\User\Command\CreateUser;
use Symfony\Component\Messenger\MessageBusInterface;

/** @var DomainObjectFactoryInterface $factory */
/** @var DomainObjectFactory $factory */
/** @var MessageBusInterface $bus */
$bus->dispatch(new CreateUserCommand([
'id' => $factory->create(UserIdInterface::class),
$bus->dispatch(new CreateUser([
'id' => $factory->create(UserId::class),
]));
```

Expand All @@ -64,7 +64,7 @@ class User extends BaseUser
private $requiredField;
private $optionalField;

public function __construct(UserIdInterface $id, $requiredField, $optionalField = null)
public function __construct(UserId $id, $requiredField, $optionalField = null)
{
$this->id = $id;
$this->requiredField = $requiredField;
Expand All @@ -80,17 +80,17 @@ Specify the fields during dispatch:
```php
<?php

use MsgPhp\User\Command\CreateUserCommand;
use MsgPhp\User\Command\CreateUser;
use Symfony\Component\Messenger\MessageBusInterface;

/** @var MessageBusInterface $bus */
$bus->dispatch(new CreateUserCommand([
$bus->dispatch(new CreateUser([
'requiredField' => 'value',
]));

// alternatively:

$bus->dispatch(new CreateUserCommand([
$bus->dispatch(new CreateUser([
'requiredField' => 'value',
'optionalField' => 'value',
]));
Expand Down
20 changes: 10 additions & 10 deletions docs/cookbook/user-bundle/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace App\Entity\User;

use Doctrine\ORM\Mapping as ORM;
use MsgPhp\User\User as BaseUser;
use MsgPhp\User\UserIdInterface;
use MsgPhp\User\UserId;

/**
* @ORM\Entity()
Expand All @@ -31,12 +31,12 @@ class User extends BaseUser
/** @ORM\Id() @ORM\GeneratedValue() @ORM\Column(type="msgphp_user_id", length=191) */
private $id;

public function __construct(UserIdInterface $id)
public function __construct(UserId $id)
{
$this->id = $id;
}

public function getId(): UserIdInterface
public function getId(): UserId
{
return $this->id;
}
Expand Down Expand Up @@ -67,7 +67,7 @@ not have to be queried for it after. To disable it, use:

public function __construct()
{
$this->id = new MsgPhp\User\UserId(); // represents an "empty" ID (i.e. "new")
$this->id = new \MsgPhp\User\ScalarUserId(); // represents an "empty" ID (i.e. "new")
}
```

Expand All @@ -86,9 +86,9 @@ private $id;

// ...

public function getId(): UserIdInterface
public function getId(): UserId
{
return MsgPhp\User\UserId::fromValue($this->id);
return \MsgPhp\User\ScalarUserId::fromValue($this->id);
}
```

Expand All @@ -109,7 +109,7 @@ If for some reason the default mapping needs to be customized, create the file `

## Configure the User Identity

The user is identified by a built-in [domain identifier](../../ddd/identifiers.md) of type `MsgPhp\User\UserIdInterface`.
The user is identified by a built-in [domain identifier](../../ddd/identifiers.md) of type `MsgPhp\User\UserId`.

The default data type is considered `integer` using a default implementation of type: `MsgPhp\User\UserId`.

Expand All @@ -120,9 +120,9 @@ Optionally change the data type and implementation used by MsgPHP:

msgphp_user:
id_type_mapping:
MsgPhp\User\UserIdInterface: bigint
MsgPhp\User\UserId: bigint
class_mapping:
MsgPhp\User\UserIdInterface: App\Entity\User\UserId
MsgPhp\User\UserId: App\Entity\User\UserId
```

### Using a UUID identifier
Expand All @@ -132,7 +132,7 @@ msgphp_user:

msgphp_user:
id_type_mapping:
MsgPhp\User\UserIdInterface: uuid # uuid_binary, uuid_binary_ordered_time
MsgPhp\User\UserId: uuid # uuid_binary, uuid_binary_ordered_time
```

This changes the default implementation used by MsgPHP to `MsgPhp\User\Infrastructure\Uuid\UserId`, a sub class of the default [UUID domain identifier](../../infrastructure/uuid.md#domain-identifier).
Expand Down
18 changes: 9 additions & 9 deletions docs/ddd/collections.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Collections

A domain collection is a [traversable] and bound to `MsgPhp\Domain\DomainCollectionInterface`. Its purpose is to utilize
a primitive iterable value. It may hold any type of element values.
A domain collection is a [traversable] and bound to `MsgPhp\Domain\DomainCollection`. Its purpose is to utilize a
primitive iterable value. It may hold any type of element values.

## API

Expand All @@ -12,7 +12,7 @@ a primitive iterable value. It may hold any type of element values.

---

### `static fromValue(?iterable $value): DomainCollectionInterface`
### `static fromValue(?iterable $value): DomainCollection`

Returns a factorized collection from any primitive iterable. Using `null` implies an empty collection.

Expand Down Expand Up @@ -54,31 +54,31 @@ Returns the element at the given key from a collection.

---

### `filter(callable $filter): DomainCollectionInterface`
### `filter(callable $filter): DomainCollection`

Returns a **new** collection containing only elements for which `$filter` returns `true`. Keys are preserved.

---

### `slice(int $offset, int $limit = 0): DomainCollectionInterface`
### `slice(int $offset, int $limit = 0): DomainCollection`

Returns a **new** collection containing a slice of elements. By default the slice has no limit, implied by integer `0`.
Keys are preserved.

---

### `map(callable $mapper): DomainCollectionInterface`
### `map(callable $mapper): DomainCollection`

Returns a **new** collection containing each collection element as returned by `$mapper`. Keys are preserved.

## Pagination API

A collection that is part of a paginated result set is bound to `MsgPhp\Domain\PaginatedDomainCollectionInterface`. Its
purpose is to expose the current pagination.
A collection that is part of a paginated result set is bound to `MsgPhp\Domain\PaginatedDomainCollection`. Its purpose
is to expose the current pagination.

### Extends

- [`DomainCollectionInterface`](#collections)
- [`DomainCollection`](#collections)

---

Expand Down
12 changes: 6 additions & 6 deletions docs/ddd/identifiers.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Identifiers

A domain identifier is a value object and bound to `MsgPhp\Domain\DomainIdInterface`. Its purpose is to utilize a
primitive identifier value, usually used to identity an entity with.
A domain identifier is a value object and bound to `MsgPhp\Domain\DomainId`. Its purpose is to utilize a primitive
identifier value, usually used to identity an entity with.

## API

### `static fromValue($value): DomainIdInterface`
### `static fromValue($value): DomainId`

Returns a factorized identifier from any primitive value. Using `null` might imply an empty identifier.

Expand All @@ -17,7 +17,7 @@ Tells if an identifier value is considered empty, thus has no known primitive va

---

### `equals(DomainIdInterface $id): bool`
### `equals(DomainId $id): bool`

Tells if an identifier strictly equals another identifier.

Expand All @@ -39,12 +39,12 @@ A first class citizen domain identifier trait.
```php
<?php

use MsgPhp\Domain\DomainIdInterface;
use MsgPhp\Domain\DomainId;
use MsgPhp\Domain\DomainIdTrait;

// --- SETUP ---

class MyDomainId implements DomainIdInterface
class MyDomainId implements DomainId
{
use DomainIdTrait;
}
Expand Down
19 changes: 9 additions & 10 deletions docs/ddd/object-factory.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Object Factory

A domain object factory is bound to `MsgPhp\Domain\Factory\DomainObjectFactoryInterface`. Its purpose is to initialize
any domain object based on a given class name and context.
A domain object factory is bound to `MsgPhp\Domain\Factory\DomainObjectFactory`. Its purpose is to initialize any domain
object based on a given class name and context.

## API

Expand Down Expand Up @@ -30,8 +30,7 @@ Returns the actual class name the factory uses for a given class name.
### `MsgPhp\Domain\Factory\GenericDomainObjectFactory`

A generic object factory. It initializes a class by reading its [constructor] arguments. If the class is a sub class
of `MsgPhp\Domain\DomainIdInterface` or `MsgPhp\Domain\DomainCollectionInterface` its static `fromValue` constructor
will be used instead.
of `MsgPhp\Domain\DomainId` or `MsgPhp\Domain\DomainCollection` its static `fromValue` constructor will be used instead.

Context elements mapped by argument name will be used as argument value. In case of a type-hinted object argument a
nested context may be provided to initialize the object with.
Expand All @@ -47,11 +46,11 @@ use MsgPhp\Domain\Factory\GenericDomainObjectFactory;

// --- SETUP ---

interface KnownInterface
interface Known
{
}

class Some implements KnownInterface
class Some implements Known
{
public function __construct(int $a, ?int $b, ?int $c)
{
Expand All @@ -60,13 +59,13 @@ class Some implements KnownInterface

class Subject
{
public function __construct(string $argument, KnownInterface $some, Subject $otherSubject = null)
public function __construct(string $argument, Known $some, Subject $otherSubject = null)
{
}
}

$factory = new GenericDomainObjectFactory([
KnownInterface::class => Some::class,
Known::class => Some::class,
]);

// Optionally set the factory to use for nested objects, or use the current factory by default.
Expand All @@ -75,8 +74,8 @@ $factory = new GenericDomainObjectFactory([
// --- USAGE ---

/** @var Some $object */
$object = $factory->create(KnownInterface::class, ['a' => 1]);
$factory->getClass(KnownInterface::class); // "Some"
$object = $factory->create(Known::class, ['a' => 1]);
$factory->getClass(Known::class); // "Some"

/** @var Subject $object */
$object = $factory->create(Subject::class, [
Expand Down
4 changes: 2 additions & 2 deletions docs/ddd/repositories.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ This page describes the API provided by default [implementations](#implementatio

## API

### `doFindAll(int $offset = 0, int $limit = 0): DomainCollectionInterface`
### `doFindAll(int $offset = 0, int $limit = 0): DomainCollection`

Finds all entities available. An unlimited collection is implied by `$limit` set to zero.

---

### `doFindAllByFields(array $fields, int $offset = 0, int $limit = 0): DomainCollectionInterface`
### `doFindAllByFields(array $fields, int $offset = 0, int $limit = 0): DomainCollection`

Finds all entities matching the specified fields. Supported field values should be `null`, `scalar`, `scalar[]` (i.e.
one of) and `object` (i.e. another entity or its [identifier](identifiers.md)). An unlimited collection is implied by
Expand Down
14 changes: 7 additions & 7 deletions docs/event-sourcing/event-handlers.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Event Handlers

A domain event handler is bound to `MsgPhp\Domain\Event\DomainEventHandlerInterface`. Its purpose is to implement the
handling of [domain events](events.md) within a certain context.
A domain event handler is bound to `MsgPhp\Domain\Event\DomainEventHandler`. Its purpose is to implement the handling of
[domain events](events.md) within a certain context.

Usually an entity implements it in order to mutate its own state (i.e. self-handling). It enforces the entity state to
be valid by design as it encapsulates all write operations.
Expand All @@ -12,7 +12,7 @@ requires its history to be accessible.

## API

### `handleEvent(DomainEventInterface $event): bool`
### `handleEvent(DomainEvent $event): bool`

Handles the given domain event for a known subject. A boolean return value tells if the domain event is actually handled
yes or no.
Expand All @@ -29,13 +29,13 @@ A utility trait implementing the event handler API. By convention it maps events
```php
<?php

use MsgPhp\Domain\Event\DomainEventHandlerInterface;
use MsgPhp\Domain\Event\DomainEvent;
use MsgPhp\Domain\Event\DomainEventHandler;
use MsgPhp\Domain\Event\DomainEventHandlerTrait;
use MsgPhp\Domain\Event\DomainEventInterface;

// --- SETUP ---

class MyDomainEvent implements DomainEventInterface
class MyDomainEvent implements DomainEvent
{
public $newValue;

Expand All @@ -45,7 +45,7 @@ class MyDomainEvent implements DomainEventInterface
}
}

class MyEntity implements DomainEventHandlerInterface
class MyEntity implements DomainEventHandler
{
use DomainEventHandlerTrait;

Expand Down
Loading