Skip to content
Open
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"require": {
"php": "^8.0",
"era269/message-processor": "^0.4.0",
"era269/normalizable": "^0.5",
"era269/normalizable": "^0.6.0",
"psr/event-dispatcher": "^1.0"
},
"require-dev": {
Expand Down
33 changes: 11 additions & 22 deletions example/Application/Port/NotebooksPort.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,24 +11,23 @@
use Era269\Microobject\Example\Domain\Message\Notebook\Query\GetNotebookQuery;
use Era269\Microobject\Example\Domain\Notebook\NotebookCollectionFactory;
use Era269\Microobject\Exception\MicroobjectExceptionInterface;
use Era269\Normalizable\NormalizerInterface;

final class NotebooksPort
{
private NotebookCollectionFactory $notebookCollectionFactory;

public function __construct(NotebookCollectionFactory $notebookCollectionFactory)
public function __construct(
private NotebookCollectionFactory $notebookCollectionFactory,
private NormalizerInterface $normalizer
)
{
$this->notebookCollectionFactory = $notebookCollectionFactory;
}

/**
* POST /notebooks
*
* @param array<string, mixed> $request
*
* @return array<string, mixed>
*
* @throws MicroobjectExceptionInterface
* @return array<int|string, mixed>
*/
public function addNotebook(array $request): array
{
Expand All @@ -45,9 +44,7 @@ public function addNotebook(array $request): array
*
* @param array<string, mixed> $request
*
* @return array<string, mixed>
*
* @throws MicroobjectExceptionInterface
* @return array<int|string, mixed>
*/
public function addPage(array $request): array
{
Expand All @@ -64,9 +61,7 @@ public function addPage(array $request): array
*
* @param array<string, mixed> $request
*
* @return array<string, mixed>
*
* @throws MicroobjectExceptionInterface
* @return array<int|string, mixed>
*/
public function addLine(array $request): array
{
Expand All @@ -83,9 +78,7 @@ public function addLine(array $request): array
*
* @param array<string, mixed> $request
*
* @return array<string, mixed>
*
* @throws MicroobjectExceptionInterface
* @return array<int|string, mixed>
*/
public function getText(array $request): array
{
Expand All @@ -102,9 +95,7 @@ public function getText(array $request): array
*
* @param array<string, mixed> $request
*
* @return array<string, mixed>
*
* @throws MicroobjectExceptionInterface
* @return array<int|string, mixed>
*/
public function getPage(array $request): array
{
Expand All @@ -121,9 +112,7 @@ public function getPage(array $request): array
*
* @param array<string, mixed> $request
*
* @return array<string, mixed>
*
* @throws MicroobjectExceptionInterface
* @return array<int|string, mixed>
*/
public function getNotebook(array $request): array
{
Expand Down
12 changes: 2 additions & 10 deletions example/Domain/Message/AbstractMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,15 @@

use Era269\Microobject\MessageInterface;
use Era269\Microobject\Traits\MessageTrait;
use ReflectionClass;
use Era269\Normalizable\Traits\NormalizableTrait;

abstract class AbstractMessage implements MessageInterface
{
use MessageTrait;
use NormalizableTrait;

public function __construct()
{
$this->setId(MessageId::generate());
}

/**
* @inheritDoc
*/
public function getType(): string
{
return (new ReflectionClass(static::class))
->getShortName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,16 @@
use Era269\Microobject\Example\Domain\Notebook\NotebookIdAwareInterface;
use Era269\Microobject\Example\Domain\Notebook\Traits\NotebookIdAwareTrait;
use Era269\Normalizable\DenormalizableInterface;
use Era269\Normalizable\Traits\NormalizableTrait;

final class CreateNotebookCommand extends AbstractNotebookCollectionMessage implements NotebookIdAwareInterface, DenormalizableInterface
{
use NotebookIdAwareTrait;
use NormalizableTrait;

public function __construct(
NotebookId $notebookId,
protected string $notebookName
private string $notebookName
)
{
parent::__construct();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

use Era269\Microobject\Example\Domain\Message\Notebook\AbstractNotebookMessage;
use Era269\Microobject\Example\Domain\Message\Notebook\Command\CreateNotebookCommand;
use Era269\Normalizable\Traits\NormalizableTrait;
use Era269\Microobject\Example\Domain\Message\Traits\OccurredAtAwareTrait;
use Era269\Microobject\IdentifierInterface;
use Era269\Microobject\Message\EventInterface;

final class NotebookCreatedEvent extends AbstractNotebookMessage implements EventInterface
{
use OccurredAtAwareTrait;
use NormalizableTrait;

protected string $notebookName;
private string $notebookName;

public function __construct(CreateNotebookCommand $command)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Era269\Microobject\Example\Domain\Message\AbstractMessage;
use Era269\Microobject\Example\Domain\Notebook\NotebookId;
use Era269\Microobject\Example\Domain\Notebook\Traits\NotebookIdAwareTrait;
use Era269\Normalizable\Traits\NormalizableTrait;

abstract class AbstractPageCollectionMessage extends AbstractMessage implements PageCollectionMessageInterface
{
use NotebookIdAwareTrait;
use NormalizableTrait;

public function __construct(NotebookId $notebookId)
{
Expand Down
2 changes: 2 additions & 0 deletions example/Domain/Message/Notebook/Page/AbstractPageMessage.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Era269\Microobject\Example\Domain\Notebook\NotebookId;
use Era269\Microobject\Example\Domain\Notebook\Page\PageId;
use Era269\Microobject\Example\Domain\Notebook\Page\Traits\PageIdAwareTrait;
use Era269\Normalizable\Traits\NormalizableTrait;

abstract class AbstractPageMessage extends AbstractPageCollectionMessage implements PageMessageInterface
{
use PageIdAwareTrait;
use NormalizableTrait;

public function __construct(NotebookId $notebookId, PageId $pageId)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,16 @@
use Era269\Microobject\Example\Domain\Notebook\NotebookId;
use Era269\Microobject\Example\Domain\Notebook\Page\PageId;
use Era269\Normalizable\DenormalizableInterface;
use Era269\Normalizable\Traits\NormalizableTrait;

final class AddLineCommand extends AbstractPageMessage implements CommandInterface, DenormalizableInterface
{
use NormalizableTrait;

public function __construct(
NotebookId $notebookId,
PageId $pageId,
protected string $line,
private string $line,
)
{
parent::__construct($notebookId, $pageId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@
use Era269\Microobject\Example\Domain\Notebook\Page\Text;
use Era269\Microobject\Example\Domain\Notebook\Page\Traits\PageIdAwareTrait;
use Era269\Normalizable\DenormalizableInterface;
use Era269\Normalizable\Traits\NormalizableTrait;

final class CreatePageCommand extends AbstractPageCollectionMessage implements DenormalizableInterface
{
use PageIdAwareTrait;
use NormalizableTrait;

public function __construct(
NotebookId $notebookId,
PageId $pageId,
protected Text $text,
private Text $text,
)
{
parent::__construct($notebookId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,17 @@

use Era269\Microobject\Example\Domain\Message\Notebook\Page\AbstractPageMessage;
use Era269\Microobject\Example\Domain\Message\Notebook\Page\Command\AddLineCommand;
use Era269\Normalizable\Traits\NormalizableTrait;
use Era269\Microobject\Example\Domain\Message\Traits\OccurredAtAwareTrait;
use Era269\Microobject\IdentifierInterface;
use Era269\Microobject\Message\EventInterface;

final class LineAddedEvent extends AbstractPageMessage implements EventInterface
{
use OccurredAtAwareTrait;
use NormalizableTrait;

protected string $line;
private string $line;

public function __construct(AddLineCommand $command)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ final class PageCreatedEvent extends AbstractPageMessage implements EventInterfa
{
use OccurredAtAwareTrait;

protected Text $text;
private Text $text;

public function __construct(
CreatePageCommand $command
Expand Down
2 changes: 2 additions & 0 deletions example/Domain/Message/Notebook/Page/Query/GetPageQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Era269\Microobject\Example\Domain\Message\Notebook\Page\Query;

use Era269\Microobject\Example\Domain\Message\Notebook\Page\AbstractPageCollectionMessage;
use Era269\Normalizable\Traits\NormalizableTrait;
use Era269\Microobject\Example\Domain\Notebook\NotebookId;
use Era269\Microobject\Example\Domain\Notebook\Page\PageId;
use Era269\Microobject\Example\Domain\Notebook\Page\PageIdAwareInterface;
Expand All @@ -13,6 +14,7 @@
final class GetPageQuery extends AbstractPageCollectionMessage implements PageIdAwareInterface, DenormalizableInterface
{
use PageIdAwareTrait;
use NormalizableTrait;

public function __construct(NotebookId $notebookId, PageId $pageId)
{
Expand Down
2 changes: 2 additions & 0 deletions example/Domain/Message/Notebook/Query/GetNotebookQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
namespace Era269\Microobject\Example\Domain\Message\Notebook\Query;

use Era269\Microobject\Example\Domain\Message\Notebook\AbstractNotebookCollectionMessage;
use Era269\Normalizable\Traits\NormalizableTrait;
use Era269\Microobject\Example\Domain\Notebook\NotebookId;
use Era269\Microobject\Example\Domain\Notebook\NotebookIdAwareInterface;
use Era269\Microobject\Example\Domain\Notebook\Traits\NotebookIdAwareTrait;
Expand All @@ -12,6 +13,7 @@
final class GetNotebookQuery extends AbstractNotebookCollectionMessage implements NotebookIdAwareInterface, DenormalizableInterface
{
use NotebookIdAwareTrait;
use NormalizableTrait;

public function __construct(NotebookId $notebookId)
{
Expand Down
11 changes: 11 additions & 0 deletions example/Domain/NormalizableInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

declare(strict_types=1);

namespace Era269\Microobject\Example\Domain;

use Era269\Normalizable\NormalizationFacadeAwareInterface;

interface NormalizableInterface extends \Era269\Normalizable\NormalizableInterface, NormalizationFacadeAwareInterface
{
}
14 changes: 3 additions & 11 deletions example/Domain/Notebook.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
use Era269\Microobject\Example\Domain\Notebook\PageCollectionInterface;
use Era269\Microobject\Message\Event\EventStreamInterface;
use Era269\Microobject\MessageInterface;
use Era269\Normalizable\Traits\NormalizableTrait;
use Psr\EventDispatcher\EventDispatcherInterface;

final class Notebook extends AbstractMicroobject implements NotebookInterface
{
use NormalizableTrait;

private string $name;
private PageCollectionInterface $pages;
private NotebookId $id;
Expand Down Expand Up @@ -63,17 +66,6 @@ public function processPageCollectionMessages(PageCollectionMessageInterface $me
->process($message);
}

/**
* @inheritDoc
*/
protected function getNormalized(): array
{
return [
'id' => $this->getId()->normalize(),
'name' => $this->name,
];
}

/**
* @inheritDoc
*/
Expand Down
14 changes: 3 additions & 11 deletions example/Domain/Notebook/Page.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,13 @@
use Era269\Microobject\Example\Domain\Notebook\Page\Text;
use Era269\Microobject\Message\Event\EventStreamInterface;
use Era269\Microobject\Message\EventInterface;
use Era269\Normalizable\Traits\NormalizableTrait;
use Psr\EventDispatcher\EventDispatcherInterface;

final class Page extends AbstractMicroobject implements PageInterface
{
use NormalizableTrait;

private PageId $id;
private Text $text;

Expand Down Expand Up @@ -91,17 +94,6 @@ protected function applyPageCreatedEvent(PageCreatedEvent $event): void
$this->text = $event->getText();
}

/**
* @inheritDoc
*/
protected function getNormalized(): array
{
return [
'id' => $this->getId()->normalize(),
'text' => $this->text->normalize(),
];
}

public function getId(): PageId
{
return $this->id;
Expand Down
16 changes: 6 additions & 10 deletions example/Domain/Notebook/Page/Text.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@

namespace Era269\Microobject\Example\Domain\Notebook\Page;

use Era269\Normalizable\Abstraction\AbstractNormalizable;
use Era269\Microobject\Example\Domain\NormalizableInterface;
use Era269\Normalizable\Traits\NormalizableTrait;
use Stringable;

final class Text extends AbstractNormalizable implements Stringable
final class Text implements Stringable, NormalizableInterface
{
use NormalizableTrait;

/**
* @var string[]
*/
Expand All @@ -32,15 +35,8 @@ public function withLine(string $line): self
/**
* @inheritDoc
*/
public function __toString()
public function __toString(): string
{
return implode("\n", $this->lines);
}

protected function getNormalized(): array
{
return [
'lines' => $this->lines,
];
}
}
2 changes: 1 addition & 1 deletion example/Domain/Notebook/Page/Traits/PageIdAwareTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

trait PageIdAwareTrait
{
protected PageId $pageId;
private PageId $pageId;

public function getPageId(): PageId
{
Expand Down
Loading